Creating custom binding for generating wsdl client proxy using wsimport - java

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

Related

How to prevent unnecessary boxing while creating a jar from a WSDL using wsimport?

The output is like this and related methods use this wrapper class as a return type but instead of an unnecessary boxing I expect to see List<ItemVariantSpecType> as a return type.
I found something that might be related with this issue but it didn't work:
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
whole wsimport command:
wsimport wsCreateShipment.wsdl -keep -clientjar UPSCreateShipment.jar -d "UPSCargoService" -XadditionalHeaders -B-XautoNameResolution -b custom-binding.xml -J-Djavax.xml.accessExternalSchema=all -J-Djavax.xml.accessExternalDTD=all`
custom-binding.xml which i use in the wsimport command:
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
<jaxb:bindings>
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
So is there a way to prevent this situation?

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>

Gradle - Generating serializable classes with jaxb

I'm using gradle as build tool and configuring jaxb plugin jacobono. Have the below entry in build.gradle file:
jaxb {
bindingsDir = "src/main/resources/xjb"
xjc {
xsdDir = "src/main/resources/xsd"
generatePackage = "some.package"
}
}
under xjb directory, have binding.xml with the below content:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
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"
version="2.1">
<globalBindings>
<serializable uid="1" />
</globalBindings>
</bindings>
Although the files are getting generated, none of them implements serializable interface as i have defined in binding xml. I doubt on the binding dir configurations.
Any advice will be much helpful.
Moved the binding information to xsds, and it worked.
Not sure whether the plugin works properly with binging dir paramter as it didnt work even with absolute path.

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

How to generate #HandlerChain using wsimport

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>

Categories

Resources