Exposing EJBs As Web Services

  • 13,263 views
Uploaded on

EJBs can be exposed as web services on a fly with EJB3. This is an introductory presentation about the same.

EJBs can be exposed as web services on a fly with EJB3. This is an introductory presentation about the same.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
13,263
On Slideshare
0
From Embeds
0
Number of Embeds
11

Actions

Shares
Downloads
224
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • WSDL stands for Web Services Description Language WSDL is written in XML WSDL is an XML document WSDL is used to describe Web services WSDL is also used to locate Web services WSDL is a W3C recommendation WSDL Describes Web Services
  • UDDI stands for Universal Description, Discovery and Integration UDDI is a directory for storing information about web services UDDI is a directory of web service interfaces described by WSDL The basic process is that a service can publish information about itself to a known UDDI registry, including the WSDL required for a client to communicate with the service. A client can search the registry looking for a particular type of service, vendor name, and similar information. Once a service catches the eye of the client, the client requests the WSDL for the service. The client will then consume the WSDL, bind to the service, and invoke the service using the published service description. Microsoft, IBM and SAP have shut down their public UDDI registries. Use jUDDI for learning and experimentation. [http://ws.apache.org/juddi/]
  • The Simple Object Access Protocol (SOAP) is a distributed protocol similar to CORBA and Java RMI. It lets applications talk to each other by exchanging messages over a network protocol, most commonly HTTP. SOAP is heavily dependent on XML, and every SOAP message is an XML document that contains several elements (such as Envelope, Header, and Body). The SOAP header contains application-specific infrastructure data, such as security information. The SOAP body contains the message being exchanged between applications. While the SOAP header is optional for a SOAP message, the SOAP envelope and body are mandatory. SOAP stands for Simple Object Access Protocol SOAP is a communication protocol SOAP is a format for sending messages SOAP is designed to communicate via Internet SOAP is platform independent SOAP is language independent SOAP is based on XML SOAP is simple and extensible SOAP allows you to get around firewalls SOAP is a W3C standard
  • Extra benefits from using EJB 3 web services. First, you automatically get the benefits of declarative transaction and security available only to EJB 3 components. You can use interceptors and the timer service if your applications need them, without depending on extra layering. Second, a web service that uses EJB 3 can easily expose your business applications using additional protocols, such as RMI, by adding a remote interface. As you saw in the previous section, exposing an EJB 3 stateless session bean is easy and can be done by simply adding the @WebService annotation.
  • @Target({TYPE}) public @interface WebService { String name() default ""; String targetNamespace() default ""; String serviceName() default ""; String wsdlLocation() default ""; String endpointInterface() default ""; String portName() default ""; }; Marks a Java class as implementing a Web Service, or a Java interface as defining a Web Service interface.
  • @SOAPBinding [http://www.javabeat.net/articles/80-ejb-30-and-webservices-7.html] @Retention(value = RetentionPolicy.RUNTIME) @Target({TYPE}) public @interface SOAPBinding { public enum Style { DOCUMENT, RPC }; Style style() default Style.DOCUMENT; public enum Use { LITERAL, ENCODED }; Use use() default Use.LITERAL; public enum ParameterStyle { BARE, WRAPPED }; ParameterStyle parameterStyle() default ParameterStyle.WRAPPED; } Specifies the mapping of the Web Service onto the SOAP message protocol.
  • @Target({METHOD}) public @interface WebMethod { String operationName() default ""; String action() default "" ; boolean exclude() default false; }; Customizes a method that is exposed as a Web Service operation. The associated method must be public and its parameters return value, and exceptions must follow the rules defined in JAX-RPC 1.1, section 5. The method is not required to throw java.rmi.RemoteException.
  • @Target({PARAMETER}) public @interface WebParam { public enum Mode { IN, OUT, INOUT }; String name() default ""; String targetNamespace() default ""; Mode mode() default Mode.IN; boolean header() default false; String partName() default ""; }; Customizes the mapping of an individual parameter to a Web Service message part and XML element.
  • public @interface WebResult { String name() default "return"; String targetNamespace() default ""; boolean header() default false; String partName() default ""; }; Customizes the mapping of the return value to a WSDL part and XML element.
  • Determine whether you really need your application to be exposed as a web service and that your application requires interoperability. If not, then consider using alternative technologies and protocols because you will most likely find better performance in using alternative protocols such as RMI. Regardless of the technology used, at this point in the SOAP web service paradigm, messing around with all that XML can put a real strain on your network. Options for sending binary web service messages are just now emerging, but they are still a few years away from being widely available. Analyze whether you need RPC-oriented or document-oriented web services. You can use the @SOAPBinding annotation to control the style for your EJB web service. RPC-style web services may perform better than document style web services. However, document style web services provide more flexibility because you can use XML schemas to define the messages. Similarly, avoid using message encoding because it makes your services less interoperable, as well as less portable between SOAP implementations. Document/literal is the recommended combination for an interoperable web service. Design your EJB web service so that it creates very minimal network traffic. Avoid sending large objects over the wire. It’s better to send an Id or reference to an object instead of sending the entire object. All objects sent via SOAP are serialized into XML. The XML representation of data can be quite large, making SOAP messages much more expensive than retrieving the object in the target location. In addition, if your EJB involves a long-running transaction, avoid exposing it as a web service, or mark it as not returning a value so that it can be invoked in a more asynchronous manner. Use JAX-WS data types as the method parameters for your web service to give it interoperability with heterogeneous web services. Suppose you have an object graph involving Collections, HashMaps, and Lists as web service parameters. Using these data types in the WSDL makes your application less interoperable. Test your applications to make sure they comply with the WS-I Basic Profile if interoperability is important for your application.

Transcript

  • 1. Exposing EJBs as web services [email_address]
  • 2. What’s Inside
    • What is a web service?
    • Types
    • WSDL, UDDI and SOAP
    • Development Approaches
    • EJB Vs POJO for a web service
    • Clients
    • Debugging and Testing
    • Best practices
    • Resources
  • 3. What Are Web Services ?
    • Software Components that can be published, located and run over the internet
    [W3C (working group) definition] "A Web service is a software application identified by a URI, whose interfaces and bindings are capable of being defined, described and discovered as XML artifacts. A Web service supports direct interactions with other software agents using XML based messages exchanged via internet-based protocols."
  • 4. Web Services Vision
  • 5. Type of Web services SOAP REST and more… ..
  • 6. SOAP Web Services
    • The key players: WSDL, UDDI and SOAP
  • 7. Describing a web service: WSDL
    • <types>
    • The types element defines the data types exchanged when the web service is invoked.The parameters passed to and returned from a method are considered data types.
    • <message>
    • The messages used by the web service. A message may contain more than a message part. Each message part is actually part of the SOAP message being sent, and is either a parameter or result being passed.
    • <portType>
    • A portType is the most important part of a WSDL. it defines operations that can be performed and the messages involved.
    • <binding>
    • The communication protocols used by the web service
    The Web Services Description Language (WSDL) describes all details about how the web service works, where it can be found, and what the client should expect in return etc..
  • 8. Discovering a service: UDDI
    • UDDI is a platform-independent framework for describing services, discovering businesses, and integrating business services by using the Internet .
    http://www.xmethods.com/ve2/index.po
  • 9. Defining a message: SOAP <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Header> ... </soap:Header> <soap:Body> ... <soap:Fault> ... </soap:Fault> </soap:Body> </soap:Envelope> SOAP is an XML-based protocol to let applications exchange information over HTTP.
  • 10. Approaches to developing web services
    • Bottom up strategy
      • The bottom-up strategy is the most popular approach to developing a web service. It allows you to reuse your investments by exposing your existing applications. If the implementation class already exists. All that is needed is to create a WSDL and expose the implementation class as a web service.
    • Top down strategy
      • Top down is often termed the “pure approach” to building a web service. Also known as contract first web services, this approach starts with the WSDL (the contract) by defining operations, messages, and so forth. Then you build the endpoint interface, and finally the implementation class.
  • 11. Why choose EJB over a POJO for a web service?
  • 12. Developing EJB web services with JAX-WS 2.0
    • @WebService
    • @SOAPBinding
    • @WebMethod
    • @WebParam
    • @WebResult
    • Lets write some code.
  • 13. @WebService Marks a Java class as implementing a Web Service, or a Java interface as defining a Web Service interface.
  • 14. @SOAPBinding Specifies the mapping of the Web Service onto the SOAP message protocol.
  • 15. @WebMethod Customizes a method that is exposed as a Web Service operation.
  • 16. @WebParam Customizes the mapping of an individual parameter to a Web Service message part and XML element.
  • 17. @WebResult Customizes the mapping of the return value to a WSDL part and XML element..
  • 18. Writing clients in java
    • Java application client
    • EJB as a web service client
  • 19. Debugging and Testing EJB web Service
    • JUnit
    • Eclipse Web Service Explorer
    • SoapUI
    • Web Service Call Composer
    • WebInject
    • JMeter
    • SOAPSonar Personal Edition
    • SOA Cleaner
    • Vordel SOAPbox
    • Storm
  • 20. Best practices for web service development
    • Determine whether you really need your application to be exposed as a web service and that your application requires interoperability.
    • Analyze whether you need RPC-oriented or document-oriented web services.
    • Design your EJB web service so that it creates very minimal network traffic.
    • Use JAX-WS data types as the method parameters for your web service to give it interoperability with heterogeneous web services.
    • Best practices for Web services versioning
    • http://www.ibm.com/developerworks/webservices/library/ws-version/
  • 21. Resources
    • http://www.w3schools.com/webservices/default.asp
    • http://www.w3schools.com/soap/default.asp
    • http://www.w3schools.com/wsdl/default.asp
    • Manning EJB 3 in Action
  • 22. Thank You