How to generate #HandlerChain using wsimport - java

I'm generating Java from WSDL using wsimport (JAX-WS 2.1.3) and need to make it generate a #HandlerChain annotation. So I create a JAX-WS binding file:
<jaxws:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
wsdlLocation="../etc/MessageStudio.wsdl">
<jaxws:bindings node="wsdl:definitions">
<javaee:handler-chain>
<javaee:handler-chain-name>StrongmailHandlers</javaee:handler-chain-name>
<javaee:handler>
<javaee:handler-name>OrganizationTokenHandler</javaee:handler-name>
<javaee:handler-class>com.bossmedia.strongmailadapter.deliveryadapter.OrganizationTokenHandler</javaee:handler-class>
</javaee:handler>
</javaee:handler-chain>
</jaxws:bindings>
and run the wsimport Ant task:
<wsimport
wsdl="../etc/MessageStudio.wsdl"
sourcedestdir="../src/gen"
destdir="../classes"
verbose="false"
binding="../etc/jaxws.bindings.xml">
</wsimport>
but I get no annotation and no handler chain XML file. Googling only finds me solutions for changing packages, methods and arguments and the JAX-WS RI page from where I copied the XML.
Could you help me find the flaw in my configuration or another way, short of modifying the generated code, to get my handler into the chain?

The answer is that the RI example is incorrect. There needs to be a handler-chains wrapper tag:
<jaxws:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
wsdlLocation="../etc/MessageStudio.wsdl">
<jaxws:bindings node="wsdl:definitions">
<javaee:handler-chains>
<javaee:handler-chain>
<javaee:handler-chain-name>StrongmailHandlers</javaee:handler-chain-name>
<javaee:handler>
<javaee:handler-name>OrganizationTokenHandler</javaee:handler-name>
<javaee:handler-class>com.bossmedia.strongmailadapter.deliveryadapter.OrganizationTokenHandler</javaee:handler-class>
</javaee:handler>
</javaee:handler-chain>
</javaee:handler-chains>
</jaxws:bindings>

It turns out that the generated handler chain file is put in the output directory (target/package) where the compiled class files are. If you want to change that, you can use the "destDir" option to do that. Also, set "xnocompile" to false else the generated class files will end up in the same directory as the handler file. Wish they didn't do such a half a**ed job at documentation.

There is still an error in the example. The tag <javaee:handler-chain-name> does not exist according to the XML scheme (http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/javaee_web_services_metadata_handler_2_0.xsd).
The correction is:
<jaxws:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
wsdlLocation="../etc/MessageStudio.wsdl">
<jaxws:bindings node="wsdl:definitions">
<javaee:handler-chains>
<javaee:handler-chain>
<javaee:handler>
<javaee:handler-name>OrganizationTokenHandler</javaee:handler-name>
<javaee:handler-class>com.bossmedia.strongmailadapter.deliveryadapter.OrganizationTokenHandler</javaee:handler-class>
</javaee:handler>
</javaee:handler-chain>
</javaee:handler-chains>

Related

Jaxb: How to specify a default class for an XSD element

When generating Java classes from a XSD, how can I specify that for some specific node, a specific and already existent Java class should be used instead of trying to generate one?
Thank you very much.
You can use episode file to reference the existing classes. .episode files are just jaxb bindings file and has mappings between elements and java classes.
a) if those existing classes are also generated from (another) xsd. use below option to first create .episode file.
xjc -episode a.episode a.xsd
then use this a.episode that contains the mappings as input to the next xjc generation.
xjc b.xsd -extension -b a.episode
b) If you want to refer some random classes, then you may have to write your own episode file providing mapping between element and class reference like below.
sample.episode
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" if-exists="true" version="2.1">
<jaxb:bindings scd="x-schema::">
<jaxb:bindings scd="employee">
<jaxb:class ref="www1.example.Employee"/>
<jaxb:package name="www1.example" />
</jaxb:bindings>
</jaxb:bindings>
and use xjc b.xsd -extension -b sample.episode
You should use following binding customization
<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:annox="http://annox.dev.java.net" xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix">
<bindings schemaLocation="../schema/yourSchema.xsd">
<bindings node="//xs:complexType[#name='Foo']">
<class ref="com.FooImpl"/>
</bindings>
</bindings>
</bindings>

Creating custom binding for generating wsdl client proxy using wsimport

I have a requirement to generate client proxy java files in Eclipse IDE.
I tried to generate this via wsimport command. Below is the command I used.
wsimport -keep -b bindings.xml -p com.aasc.carrier.shipexec.proxy -implServiceName wcfSoxContract -implPortName wcfShip http://shipexec.com/demo/wcf/soap?wsdl -B-XautoNameResolution
After executing this I am getting below issue.
[ERROR] Invalid operation "InstantiateWCF", can't generate java method parameter. Local name of the wrapper child "package" in the global element "{......}InstantiateWCF" is a java keyword. Use customization to change the parametername.
line 1 of http://shipexec.com/demo/wcf/soap?wsdl=wsdl0
I tried to resolve this issue using the custom binding xml file as below.
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
wsdlLocation="http://shipexec.com/demo/wcf/soap?wsdl">
<enableWrapperStyle>false</enableWrapperStyle>
<jaxws:bindings node="wsdl:definitions/wsdl:import/wsdl:portType[#name='IwcfShip']/wsdl:operation[#name='InstantiateWCF']">
<jaxws:parameter part="wsdl:definitions/wsdl:message[#name='IwcfShip_InstantiateWCF_InputMessage']/wsdl:part[#name='parameters']" childElementName="package" name="paramPackage" />
</jaxws:bindings>
</jaxws:bindings>
But the node I am trying to get is not recognizing.
Can anyone please help on finding the exact node path for changing the name of the parameter for 'InstantiateWCF' operation.
Thanks,
Y Pradeep
I have resolved this issue by changing binding.xml file to as below.
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
wsdlLocation="http://shipexec.com/demo/wcf/soap?wsdl=wsdl0">
<jaxws:bindings node="wsdl:definitions" >
<jaxws:bindings node="//wsdl:portType[#name='IwcfShip']/wsdl:operation[#name='InstantiateWCF']">
<jaxws:parameter part="wsdl:definitions/wsdl:message[#name='IwcfShip_InstantiateWCF_InputMessage']/wsdl:part[#name='parameters']" childElementName="tns:package" name="paramPackage" />
</jaxws:bindings>
</jaxws:bindings>
</jaxws:bindings>
And also modified wsimport command as below.
wsimport -keep -p com.aasc.carrier.shipexec.proxy -implServiceName wcfSoxContract -implPortName wcfShip http://shipexec.com/demo/wcf/soap?wsdl -B-XautoNameResolution -b bindings.xml
Thanks,
Y Pradeep

Property is already defined error in wsdl2java

I am trying to generate proxy classes from wsdl2java using cxf, but whenever I try I keep on getting below error:
WSDLToJava Error: http://webservices.sabre.com/wsdl/sabreXML1.0.00/shopping/Grou
pedItineraryResponse_v1-0-2.xsd [0,0]: Property "ValidatingCarrier" is already d
efined. Use <jaxb:property> to resolve this conflict.
http://webservices.sabre.com/wsdl/sabreXML1.0.00/shopping/GroupedItineraryRespon
se_v1-0-2.xsd [0,0]: The following location is relevant to the above error
I tried to add binding file to wsdl2java.bat as I got info from one of the url like this:
<jaxws:bindings wsdlLocation="http://webservices.sabre.com/wsdl/sabreXML1.0.00/shopping/BargainFinderMaxRQ_v1-8-2.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:extensionBindingPrefixes="xjc"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema">
<jaxb:globalBindings
jaxb:version="2.0">
<xjc:simple />
</jaxb:globalBindings>
</jaxws:bindings>
I am using third party wsdl url, so I don't have any control to change on the server side, I need to make changes only on command to successfuly generate proxy classes. Can someone kindly help me in this issue?
The problem is that FareType has both child element named ValidatingCarrier and attribute with the same name.
To work around this you should add field binding as suggested by error message. Example binding:
<jaxb:bindings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:version="2.1"
schemaLocation="http://webservices.sabre.com/wsdl/sabreXML1.0.00/shopping/GroupedItineraryResponse_v1-0-2.xsd">
<jaxb:bindings node="//xs:complexType[#name='FareType']/xs:sequence/xs:element[#name='ValidatingCarrier']">
<jaxb:property name="validatingCarrierInfo"></jaxb:property>
</jaxb:bindings>
</jaxb:bindings>
With this binding I renamed ValidatingCarrier to ValidatingCarrierInfo.

XJC [ERROR] XPath evaluation of "//*[local-name()='schema']" results in empty target node

I am new to XJC. I'm attempting to consume a WSDL and generate binding classes with the XJC command and I got the following error:
C:\jaxb>xjc -verbose -b c:\jaxb\bindings-wsdl.xjb -wsdl c:\jaxb\BioMetScrnSvc.wsdl
parsing a schema...
[ERROR] XPath evaluation of "//*[local-name()='schema']" results in empty target node
line 8 of file:/C:/jaxb/bindings-wsdl.xjb
Failed to parse a schema.
My binding file is as follows:
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:impl="http://www.openuri.org/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:intf="http://www.openuri.org/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings node="//*[local-name()='schema']">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
The WSDL provided to me is something as follows:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.openuri.org/"
xmlns:impl="http://www.openuri.org/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:intf="http://www.openuri.org/">
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://www.openuri.org/"
xmlns="http://www.w3.org/2001/XMLSchema">
...
From all the suggestions I have read from this site, I have included the necessary namespaces into the binding file to no avail. I have tested the Xpath and it is correct.
If I don't have a binding file, a JAXBElement is generated instead of a String. Understood it is because of minOccurs and nillable occurring together.
Regards,
Wes
I could not make bindings work with node. This might be a bug in XJC, I'll check/report to Oracle.
But SCD bindings do work! So here's a solution for you. Make a file namely "wsdl.xjb" and put following code in it. And place it on the same folder (for simplicity OR you can place anywhere then you will need to mention its path) where you have your example.wsdl file.
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0">
<jaxb:bindings scd="x-schema::tns" xmlns:tns="http://www.openuri.org/">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
You'll need to include a -extension command switch and your final command will look like this:
xjc -extension -verbose -wsdl example.wsdl -b wsdl.xjb

wsdl:import issue with custom binding in CXF

I am not able to get a custom binding work for an XSD imported in a WSDL using wsdl:import tag.
I guess wsdl:type and xsd:import is the best way to import schema from an XSD but I am in need of a solution where I do not have to change the WSDL.
I am using CXF for generating the artifacts from the WSDL and it works fine when I do not use any custom binding but since my requirement is to change the name of the classes defined in the schema I intend to use a custom binding.
WSDL contains:
<definitions name="MMMWS" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xmmmd="http://xyz.com/abcdata"
xmlns:xmmms="http://xyz.com/abcservice"
targetNamespace="http://xyz.com/abcservice">
<import namespace="http://xyz.com/abcdata" location="abcdata.xsd"/>
.....
Binding file (.xjb) contains:
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
schemaLocation="abcdata.xsd">
.....
The error I get is:
[ERROR] "file:abcdata.xsd" is not a part of this compilation. Is this a mistake for "file:abcdata.xjb"?
[ERROR] at line 7 column 51 of schema file:abcdata.xjb

Categories

Resources