Java different parameter type needed for identical SOAP Web Service? -
i have web service client 2 identical soap web services called company1service , company2service. both these web services have exact same purchaseorder class.
however, when want call m1processpurchaseorder() method , m2processpurchaseorder() method each web service, require different parameter types po object. yet, purchaseorder class identical both services.
i using netbeans , generated sources (jax-ws).
public boolean m1processpurchaseorder(ab.service.company1.purchaseorder po) { ab.service.company1.company1service port = service1.getcomapny1serviceport(); return port.processpurchaseorder(po); } public boolean m2processpurchaseorder(ab.service.company2.purchaseorder po) { ab.service.company2.company2service port = service2.getcomapny2serviceport(); return port.processpurchaseorder(po); }
what have ab.service.company1.purchaseorder
parameter type both company1service , company2service.
here error if try change m2processpurchaseorder()
parameter type ab.service.company1.purchaseorder
:
method processpurchaseorder in interface company2service cannot applied given types;
required: ab.service.company2.purchaseorder
found: ab.service.company1.purchaseorder
reason: actual argument ab.service.company1.purchaseorder cannot converted ab.service.company2.purchaseorder method invocation conversion
depending on jax-ws implementation using -- there severals: cxf, ri/metro, axis2, jbossws, spring-ws, etc. -- might needing invoke different tools generate artifacts (xsd schemas or wsdl's), i.e. ri's wsimport, or specific jax-ws implementation tools *axis*2's or cxf's wsdl2java, or jbossws' wsprovide.
also, depending on build script/tool have setup project, there might task, goal, or target can utilize automate invocation of these tools. nevertheless, when comes xml-to-java binding, can utilize jaxb binding document(s) manipulate generated java classes including manipulation of (package) generated into. done via jaxb:bindings (jaxb namespace prefix). wsdl artifacts, i.e. service, can place mapping instructions in jaxws:bindings (same here jaxws xml namespace). note these 2 two separate binding (xml) documents can fed 1 of aforementioned tools, i.e. cxf's wsdl2java or wsimport.
for jaxb binding, can create binding document (company1binding.xml
):
<?xml version="1.0" encoding="utf-8" ?> <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"> <jaxb:bindings schemalocation="purchaseorder.xsd"> <jaxb:schemabindings> <jaxb:package name="ab.service.common" /> </jaxb:schemabindings> </jaxb:bindings> <!-- more binding related company1service --> </jaxb:bindings>
and jaxb binding company2binding.xml
:
<?xml version="1.0" encoding="utf-8" ?> <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"> <jaxb:bindings schemalocation="purchaseorder.xsd"> <jaxb:schemabindings> <jaxb:package name="ab.service.common" /> </jaxb:schemabindings> </jaxb:bindings> <!-- more binding related company2service --> </jaxb:bindings>
this place generated purchaseorder.java
class in ab.service.common
package, can reference instances of class in ab.service.company1.*
, ab.service.company2.*
single class (ab.service.common.purchaseorder.java
).
note place such binding in both company1's , company2's in case make changes purchaseorder.xsd @ point, , generate binding 1 of services, i.e. company1's. in case, purchaseorder.java regenerated both, since there 1 generated class (ab.service.common.purchaseorder.java
).
you can same wsdl artifacts, example comapny1service.wsdl
, can create new binding document (company1servicebinding.xml
):
<?xml version="1.0" encoding="utf-8"?> <jaxws:bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" version="2.1" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" wsdllocation="company1service.wsdl"> <jaxws:bindings node="wsdl:definitions"> <jaxws:package name="ab.service.company1" /> </jaxws:bindings> <jaxws:bindings node="wsdl:definitions/wsdl:porttype/wsdl:operation/wsdl:fault[@name='fault']"> <jaxws:class name="ab.service.common.serviceexception" /> </jaxws:bindings> </jaxws:bindings>
which place service classes (like interface, client proxy, along side, say, soap fault type specified in wsdl operations) in ab.service.company1
package. notice difference between namespaces in each binding document (jaxb:bindings
vs. jaxws:bindings
). finally, can pass these binding information actual tool, i.e. cxf's wsdl2java (in case, snippet of code ant build file):
<java classname="org.apache.cxf.tools.wsdlto.wsdltojava" fork="true"> <arg value="-d"/> <arg value="${path.to.generated.code}"/> <arg value="-b"/> <arg value="${path.to.artifacts}/company1binding.xml"/> <arg value="-b"/> <arg value="${path.to.artifacts}/company1servicebinding.xml"/> <arg value="${path.to.artifacts}/company1service.wsdl"/> <classpath> <path refid="${jaxws.impl.library.path}"/> </classpath> </java>
(note: should have similar target company2service)
as can see, particular tool accepts binding documents (jaxb , jax-ws) via -b
flag. matter of fact, binding compiler (xjc) these tools, wsdl2java, call, accept binding documents via -b
option (note link takes reference implementation/metor's version of xjc, cxf's , others' should close). matter of fact, have call wsdl2java directly:
/path/to/wsdltojava -d /path/to/where/you/want/to/generate -b /path/to/wsdl/artifacts/companybinding.xml -b /path/to/wsdl/artifacts/company1servicebinding.xml /path/to/wsdl/artifacts/company1service.wsdl
mapping using jaxb requires getting familiarized bit of details, can read more here jax-ws ri/metro's. cxf's, can refer here, , examples maven's plugin cxf's wsdl2java. again, every jax-ws implementation has own set of tools, concepts identical when comes underlying mapping/binding tied jaxb.
Comments
Post a Comment