Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Mapping Java to WSDL and XML • JAX-RPC provides standards for how the definitions in WSDL are mapped to Java interfaces as well as how XML data types map to data types in Java. • The JAX-RPC runtime environment hides these complexities by automatically transforming the XML representation of a procedure call and associated parameters (the SOAP message) into a Java method call with Java data type parameters (this process is called deserialization). • JAX-RPC also hides the complexities of transforming a Java method call with Java data type parameters (or a single return value Java object) to its XML representation such that it can be transmitted as a SOAP message (this process is called serialization). • JAX-RPC handles this serialization/deserialization process at both the client and the service endpoint. Mapping Java to WSDL • The WSDL portType (along with associated message, part, and types) defines the JAX-RPC service endpoint interface. The name attributes of the portType, operation, and part elements are, by default, used as the names of the Java interface, methods, and parameters, respectively. JAX-RPC handles this mapping for one-way and request/response message exchange patterns, but does not handle solicit/response or notification. • The package names for Java types cannot be directly derived from the WSDL so they are handled by a JAX-RPC mapping file, which is a file that explicitly maps the definitions in WSDL to their Java representations. The mapping file associates Java package names with XML namespaces defined in the WSDL. They are typically generated by JAX-RPC compilation tools provided by your vendor. Mapping Java to WSDL, cont. • WSDL portType that specifies One-Way messaging: <message name=”Request”> <part name=”param1” type=”xsd:boolean”/> </message> <portType name=”MySEI”> <operation name=”setOperation”> <input message=”tns:Request”/> </operation> </portType> • JAX-RPC Service Endpoint Interface generated from the WSDL: public interface MySEI extends java.rmi.Remote { public void setOperation(boolean param1) throws java.rmi.RemoteException; } Mapping Java to XML • JAX-RPC compiler and runtime environment will automatically translate from XML data types in the WSDL or SOAP message to Java data types as well as translate from Java data types in a method call to their appropriate XML representation. • xsd:string maps to java.lang.String, xsd:int maps to int, xsd:boolean maps to boolean, xsd:anyURI maps to java.net.URI, xsd:dateTime maps to java.util.Calendar, etc. • All simple SOAP Encoding types are mapped to the Java wrapper associated with the Java primitive because they are all defined as nillable (in terms of Java this means that the type can be assigned null). Ex: soapenc:int is mapped to java.lang.Integer instead of int. • Also supports mapping XML Schema complexType to JavaBeans Mapping Java to XML, cont. • XML complexType definition: <xsd:element name=”MonitorPriceRequest”> <xsd:complexType> <xsd:sequence> <xsd:element name=”productId” type=”xsd:string”/> <xsd:element name=”currency” type=”xsd:string”/> </xsd:sequence> </xsd:complexType> </xsd:element> • JAX-RPC generated JavaBean from complexType: public class MonitorPriceRequest { private String productId; private String currency; public MonitorPriceRequest(){} public String getProductId(){return productId;} public void setProductId(String productId){this.productId = productId;} public String getCurrency(){return currency;} public void setCurrency(String currency){this.currency = currency;} } Deploying JAX-RPC Service Endpoints • Deploying service endpoints on a J2EE server requires the same deployment descriptors for typical servlets and EJBs, plus more • To deploy service endpoints your vendor implementation will likely require you to use their deployment tools and/or create additional vendor-specific deployment descriptors. • Servlet endpoints require web.xml and EJB endpoints require the ejb-jar.xml. Both endpoints require webservices.xml (called the Web services deployment descriptor). Plus you must include the WSDL file and the JAX-RPC mapping file that gets generated by the JAXRPC compiler. • JAX-RPC allows you to take a WSDL document and generate Java code and JAX-RPC mapping file, or start with Java code and generate a WSDL document and JAXRPC mapping file. Starting with Java is more comfortable for most Java developers. Starting from WSDL generates code that is more interoperable. Deploying JAX-RPC Service Endpoints • webservices.xml is placed in the WEB-INF directory of the WAR file for a servlet endpoint and the META-INF directory of the EJB JAR file for an EJB endpoint. A single webservices.xml file can be used for every servlet endpoint in a single WAR file that shares the same WSDL file, and a separate single webservices.xml file can be used for every EJB endpoint in a single EJB JAR file that shares the same WSDL file. • webservices.xml identifies: 1) Name of the Web service; 2) Location of the WSDL and JAX-RPC mapping files; 3) EJBs or “servlets” identified in the ejb-jar.xml or web.xml, respectively, that are endpoints; 4) WSDL port associated with each endpoint; 5) The JAX-RPC SEI and implementation classes. webservices.xml for Servlet Endpoint <?xml version=”1.0” encoding=”UTF-8”?> <webservices version=”1.1” xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:tns=”http://my-fake-company.com” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd”> <webservice-description> <webservice-description-name>MyService</webservice-description-name> <wsdl-file>WEB-INF/wsdl/MyService.wsdl</wsdl-file> <jaxrpc-mapping-file>WEB-INF/wsdl/MyService_mapping.xml </jaxrpc-mapping-file> <port-component> <port-component-name>MyServletEndpoint</port-component-name> <wsdl-port>tns:MyPort</wsdl-port> <service-endpoint-interface>javawebbook.MySEI </service-endpoint-interface> <service-impl-bean> <servlet-link>MyServletEndpoint</servlet-link> </service-impl-bean> </port-component> </webservice-description> </webservices> webservices.xml for EJB Endpoint <?xml version=”1.0” encoding=”UTF-8”?> <webservices version=”1.1” xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:tns=”http://my-fake-company.com” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd”> <webservice-description> <webservice-description-name>MyService</webservice-description-name> <wsdl-file>META-INF/wsdl/MyService.wsdl</wsdl-file> <jaxrpc-mapping-file>META-INF/wsdl/MyService_mapping.xml </jaxrpc-mapping-file> <port-component> <port-component-name>MyEJBEndpoint</port-component-name> <wsdl-port>tns:MyPort</wsdl-port> <service-endpoint-interface>javawebbook.MySEI </service-endpoint-interface> <service-impl-bean> <ejb-link>MyBean</ejb-link> </service-impl-bean> </port-component> </webservice-description> </webservices> Endpoint Names in web.xml and ejb-jar.xml • Snippet from web.xml: <servlet> <servlet-name>MyServletEndpoint</servlet-name> <servlet-class>javawebbook.MyServletEndpoint</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServletEndpoint</servlet-name> <url-pattern>/MyService/MyServletEndpoint</url-pattern> </servlet-mapping> • Snippet from ejb-jar.xml: <session> <ejb-name>MyBean</ejb-name> <service-endpoint>javawebbook.MySEI</service-endpoint> <ejb-class>javawebbook.MyBean</ejb-class> <session-type>Stateless</session-type> … </session>