Ive got a problem with my xml SOAP message - using java 1.8, Websphere 8.5.5.17, for generating class from wsdl Ive used jaxws-maven-plugin.
When I received SOAP message via WAS to my Java application, something duplicate my ns3 prefix (sometimes another), and unmarshaling to type Object is not work :(
<ns3:document xmlns:ns4="http://service.gggg.com/common/CommonMessage/v01" xmlns:ns3="http://service.gggg.com/RDS/datamodel/LAA/common/v01">
<ns3:outputChannels>
<ns3:archiveType>None</ns3:archiveType>
<ns3:publishingType>Signature</ns3:publishingType>
<ns3:printType>None</ns3:printType></ns3:document>
ns3 prefix is correctly defined upper and element "document" is anyType. The problem is in the inner atribute of document element -> the second definiton of xmlns:ns3, when I overide it manualy together with ns of childs it works.
<ns3:document xmlns:ns4="http://service.gggg.com/common/CommonMessage/v01" xmlns:ns9="http://service.gggg.com/RDS/datamodel/LAA/common/v01">
<ns9:outputChannels>
<ns9:archiveType>None</ns9:archiveType>
<ns9:publishingType>Signature</ns9:publishingType>
<ns9:printType>None</ns9:printType></ns3:document>
Ive just tried jaxb NamespacePrefixMapper, namespaces set in jaxb bindings, manualy overiding in Interceptor SOAPElement, add prefix namespace in package-info.java and a lot lot lot of more but without happy end :(
maven
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<genJWS>false</genJWS>
<extension>true</extension>
<wsdlFiles>
<wsdlFile>
${project.basedir}/src/main/resources/wsdl/ServiceWSDL.wsdl
</wsdlFile>
</wsdlFiles>
<target>2.0</target>
<xadditionalHeaders>true</xadditionalHeaders>
<bindingFiles>
<bindingFile>${project.basedir}/src/main/resources/jaxb/bindings.xml</bindingFile>
<bindingFile>${project.basedir}/src/jaxws/binding.xml</bindingFile>
</bindingFiles>
</configuration>
</execution>
</executions>
</plugin>
binding.xml
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle></jaxws:bindings>
bindings.xml
<jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<jaxb:bindings>
<jaxb:globalBindings generateElementProperty="false" fixedAttributeAsConstantProperty="true"
choiceContentProperty="true"/>
</jaxb:bindings></jaxb:bindings>
Can someone help me ?
THX!
Related
I'm currently developing client app using official API of Polish Ministry of Finance to check NIP numbers. (https://sprawdz-status-vat.mf.gov.pl/?wsdl)
Unfortunately I have a problem with wsdl published by them. Namely there is a message with 2 parts.
<wsdl:message name="SprawdzNIPNaDzienZapytanie">
<wsdl:part name="NIP" element="tns:NIP"/>
<wsdl:part name="Data" element="tns:Data"/>
</wsdl:message>
I was trying to parse it by wsimport maven plugin but client side code didn't even generate, because of error
[ERROR] operation "SprawdzNIPNaDzien": more than one part bound to body[ERROR] operation "SprawdzNIPNaDzien": more than one part bound to body
I thought ok, I will try different tool for generating code. As I have already used cxf earlier I chose to use it. Code generated just fine but when I was trying to call the service I did get similar error as before.
SEI WeryfikacjaVAT has method sprawdzNIPNaDzien annotated as BARE but it has more than one parameter bound to body. This is invalid. Please annotate the method with annotation: #SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
Now I'm wondering. Is there a way to make it work without changing wsdl file? As it is official API which doesn't belong to me, I have no way to correct it. I guess there must by a way to operate with such wsdl as SoapUI handle it just fine and doesn't throw any errors.
#Update
I have tried to add cxf parameter mentioned by Khalid so my pom.xml looks as follows:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<defaultOptions>
</defaultOptions>
<sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>other.xml</wsdl>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/my.wsdl</wsdl>
<bindingFiles>
<bindingFile>
${basedir}/src/main/resources/wsdl/bindings.xml
</bindingFile>
</bindingFiles>
<noAddressBinding>true</noAddressBinding>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
And bindings.xml file:
<jaxws:bindings
wsdlLocation="my.wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<enableWrapperStyle>true</enableWrapperStyle>
</jaxws:bindings>
Unfortunately port is still generated with
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) instead of WRAPPED annotation.
When parameterStyle is Bare, web methods should only have 1 parameter.
With document style web services, the BP mandates that each message
have zero or one part.
Here is an example :
<message name = "SubmitPurchaseOrderMessage">
<part name="Order" element "sd:purchaseOrder"/>
</message>
So, that means the parameters are all inside element in the SOAP request.
When the parameter style is wrapped, that makes sense to have all
parameters wrapped inside element.
When the
parameter style is bare, all parameters are not wrapped inside any
element.
Therefore, that makes sense to have this under doc/lit/bare:
<message name="add">
<part name="parameter1" element="tns:a"/>
</message>
The schema will show something like this:
<add>
<element name="parameter1" type:int/>
</add>
But that won't make sense to have this message under doc/lit/bare:
<message name="add>
<part name = "parameter1" element="tns:a"/>
<part name = "parameter2" element="tns:b"/>
</message>
This is not valid as BP mandates that with document style web service, the message must have at most 1 element.
That's the reason your web method won't deploy. you have more than one part in message.
Reference :
https://coderanch.com/t/624936/certification/parameterStyle-Bare-web-methods-parameter
if you want to make it wrapped style without changing wsdl file then you use binding file with cxf to generate code.
Here is the bindings.xml
<jaxws:bindings
wsdlLocation="Your wsdl file path"
xmlns="http://java.sun.com/xml/ns/jaxws"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<enableWrapperStyle>true</enableWrapperStyle>
</jaxws:bindings>
enableWrapperStyle = false to generate unwrapped style code.
and Here is the configuration you'll in pom.xml
<configuration>
<!-- Binding file for Wrapped style services -->
<defaultOptions>
<bindingFiles>
<bindingFile>
${basedir}/src/main/resources/bindings.xml
</bindingFile>
</bindingFiles>
<noAddressBinding>true</noAddressBinding>
</defaultOptions>
</configuration>
all
I tried to generate Java client from Jira wadl descriptor, but it does not work:
java.lang.IllegalStateException: Single WADL resources element is expected
WADL file used: https://docs.atlassian.com/jira/REST/7.0.4/jira-rest-plugin.wadl
Build used:
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-wadl2java-plugin</artifactId>
<version>3.1.9</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
<wadlOptions>
<wadlOption>
<wadl>${basedir}/src/main/resources/jira-rest-plugin.wadl</wadl>
<impl>true</impl>
<packagename>com.mycompany.jira</packagename>
<schemaPackagenames>
<schemaPackagename>http://mycompany=com.mycompany.jira.schema</schemaPackagename>
</schemaPackagenames>
</wadlOption>
</wadlOptions>
</configuration>
<goals>
<goal>wadl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I had a hope that they fixed their WADL in 7.x ...
Anybody who made it work?
It does not look like valid WADL file, it explains individual services, with input, input format. For a wadl2java plugin to work you need to have WADL file with syntax similar to shown below.
<application xmlns="http://research.sun.com/wadl/2006/10">
<doc xmlns:jersey="http://jersey.dev.java.net/"
jersey:generatedBy="Jersey: 1.0-ea-SNAPSHOT 10/02/2008 12:17 PM"/>
<resources base="http://localhost:9998/storage/">
<resource path="/containers">
<method name="GET" id="getContainers">
<response>
<representation mediaType="application/xml"/>
</response>
</method>
<!-- Next methods ->
</resource>
</resources>
</application>
I guess only way for you is to contact atlassian to provide at valid WADL file if the support, else you might need to use top down approach and implement the syntax as shown in the link you shared
Here is some additional info,
1) go to your specific server version api docs url.
eg:- https://docs.atlassian.com/software/jira/docs/api/REST/7.12.3/
2) Append "jira-rest-plugin.wadl" to the end and press enter
This downloads the wadl for the specific version you want
3) Signup for free in Apimatic.io and login
4) Use the transformer to upload the wadl and specify the output format (Swagger openapi v2.0 or 3.0, or postman, etc.)
5) THis will generate and download the swagger.json
I am currently developing SOAP webservices client using Apache CXF's cxf-codegen-plugin. Since I have multiple WSDL, I need to bind it to different packages in my java project.
My question is, is it possible to define 1 single binding file for multiple WSDL file?
Below is my plugin configuration
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<defaultOptions>
<bindingFiles>
<bindingFile>src/main/resources/wsdl/bindings.xjb</bindingFile>
</bindingFiles>
</defaultOptions>
<sourceRoot>${basedir}/src/main/java</sourceRoot>
<wsdlRoot>src/main/resources/wsdl</wsdlRoot>
<includes>
<include>*.wsdl</include>
</includes>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
I am trying to achieve something like this but to no avail
<jaxws:bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns="http://java.sun.com/xml/ns/jaxws">
<jaxws:bindings wsdlLocation="serviceA.wsdl" >
<jaxws:package name="org.ws.serviceA"/>
</jaxws:bindings>
<jaxws:bindings wsdlLocation="serviceB.wsdl" >
<jaxws:package name="org.ws.serviceB"/>
</jaxws:bindings>
</jaxws:bindings>
Turns out, it is indeed impossible and clearly stated in this site
https://jax-ws.java.net/nonav/2.1.2/docs/customizations.html
1.1.1 Root Binding Element
The jaxws:bindings declaration appears as the root of all other
binding declarations. This top-level jaxws:bindings element must
specify the location of the WSDL file as a URI in the value of
wsdlLocation attribute.
However it did not specify anything about the wsdlLocation at child element. This site does http://itdoc.hitachi.co.jp/manuals/3020/30203Y2310e/EY230286.HTM#ID00669
Non-root jaxws:bindings > wsdlLocation > The attribute cannot be
specified. Even if the attribute is specified, it is ignored.
Hopefully this can be improved in the future as JAXB can already bind multiple schemaLocation in one file like this
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="schema1.xsd" node="//xsd:schema">
<jxb:schemaBindings>
<jxb:package name="org.package1" />
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="schema2.xsd" node="//xsd:schema">
<jxb:schemaBindings>
<jxb:package name="org.package2" />
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
I am facing a problem with jdeb plugin.I have to modify the jdeb plugin (integrated with maven)such that the name of the debian file created shall have a different name then the current name and the control file generated should have the modified name.Now i am able to modify the current name but i am still getting the old package name in my control file.
Please find my plugin written below.
<plugin>
<artifactId>jdeb</artifactId>
<groupId>org.vafer</groupId>
<version>0.11-nklasens-1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jdeb</goal>
</goals>
<configuration>
<deb>${project.build.directory}/ABC_${version}.deb</deb>
<timestamped>true</timestamped>
<controlInfo>
<priority>${debian.priority}</priority>
<section>${debian.section}</section>
<architecture>${debian.architecture}</architecture>
<description>${debian.description}</description>
<maintainer>${debian.maintainer}</maintainer>
</controlInfo>
<dataSet>
<data>
<src>${project.build.directory}/ABC.war</src>
<type>file</type>
<destName>ABC.war</destName>
<mapper>
<type>perm</type>
<prefix>/srv/tomcat/webapps</prefix>
<user>tomcat</user>
<group>tomcat</group>
<filemode>644</filemode>
</mapper>
</data>
</dataSet>
</configuration>
</execution>
</executions>
</plugin>
got the answer after doing some experiment
The answer is add below tags under tag
<packageName>ABC</packageName>
<version>${version}</version>
I am completely new to web service stuff.
I have to write rest web service client for a web service. The web service runs fine on SoapUI. WSDL file for the URL is provided to me. But when I add the wsdl file in my Eclipse project, it gives compilation error
src-resolve.4.2: Error resolving component 'xs:schema'. It was detected that 'xs:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:///E:/Ashish%20Workspace/HATStoLSAMS%20Webservice/HATS2LSAMSWS/WebContent/WEB-INF/wsdl/CorpsiteService.svc.wsdl'. If this is the incorrect namespace, perhaps the prefix of 'xs:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:///E:/Ashish%20Workspace/HATStoLSAMS%20Webservice/HATS2LSAMSWS/WebContent/WEB-INF/wsdl/CorpsiteService.svc.wsdl'.
I googled a lot to get rid of these error but nothing worked.
If I ignore the errors and try creating stubs using wsimport as well as wsdl2java commands
it gives error
[ERROR] undefined element declaration 'xs:schema'
line 1 of http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl
I am using below command to generate stubs
wsimport -d e:\test -s E:\wssrc http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl -wsdllocation "../../../../../WEB-INF/wsdl/CorpsiteService.svc.wsdl"
I am stuck at this point and have been struggling on to this the whole day.
Any help regarding this would be really helpful
The solution to this appears to be supply alternate bindings for xs:schema as described in https://metro.java.net/2.1/guide/Dealing_with_schemas_that_are_not_referenced.html
Specifically, for the http://www.w3.org/2001/XMLSchema which is often imported into the namespace xs, there is some additional work that needs to be done.
The command would be: wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b customization.xjb something.wsdl
customization.xjb linked from the above is at https://www.java.net//blog/kohsuke/archive/20070228/xsd.xjb or copied from below
This customization exists to handle some naming conflicts that might arise from using the schema Schema (which is imported as the same name space in multiple schemas).
customization.xjb
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.0">
<globalBindings>
<xjc:simple />
</globalBindings>
<bindings scd="~xsd:complexType">
<class name="ComplexTypeType"/>
</bindings>
<bindings scd="~xsd:simpleType">
<class name="SimpleTypeType"/>
</bindings>
<bindings scd="~xsd:group">
<class name="GroupType"/>
</bindings>
<bindings scd="~xsd:attributeGroup">
<class name="AttributeGroupType"/>
</bindings>
<bindings scd="~xsd:element">
<class name="ElementType"/>
</bindings>
<bindings scd="~xsd:attribute">
<class name="attributeType"/>
</bindings>
</bindings>
I have tried this with these files and the associated -b parameters to wsimport and have gotten (apparently) past this error (and on to other ones). That said, I'm not 100% certain that my new errors are not in part caused by this (and thus this wouldn't be a complete answer). Without the actual wsdl causing the problem, one can only take a reasonable guess as to solving the problem (and on to the next one).
If you are using maven-jaxb2-plugin instead -b provide needed URL as additional schema in schemas:
<schema>
<url>https://example.com/WebService.asmx?WSDL</url>
</schema>
<schema>
<url>http://www.w3.org/2001/XMLSchema.xsd</url>
</schema>
You can even save it in resources so it is picked up automatically
I was facing same issue, resolved by just adding one line into maven plugin
<args>
<arg>-b</arg>
<arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
</args>
My maven plugin is given below
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>periodictableaccessws</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<args>
<arg>-b</arg>
<arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
</args>
<wsdlFiles>
<wsdlFile>doosdaas.wsdl</wsdlFile>
</wsdlFiles>
<packageName>com.dss.doosdaas</packageName>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
<!-- <bindingDirectory>${basedir}/src/main/resources/jaxb</bindingDirectory>
<bindingFiles>
<bindingFile>jaxb_binding.xjb</bindingFile>
</bindingFiles>-->
</configuration>
</execution>
</executions>
</plugin>
I face this kind of error when I had to consume some of UE Taxations Customs web services. In previous projects I had used the solution proposed by user289086
But for recents projects I had used another solution also based in bindings but shorter, where I use the Wrapper-style rules described here Using JAXB Data Binding.
1- Create a binding file with the following content and add it to META-INF folder:
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
2- Create Web service reference from wsdl using wsimport(in my case I use the Netbeans IDE WS Client Assistant that use wsimport in the background) for the following service for example:
UE CheckTinService
Note: First maybe the process of wsimport could be raise and error or not, but the difference of adding or not the previous binding is easy to check.
3- Add the binding reference to the corresponding jaxws-maven-plugin execution in the .pom file. For the example it stays like this:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlFiles>
<wsdlFile>ec.europa.eu/taxation_customs/tin/checkTinService.wsdl</wsdlFile>
</wsdlFiles>
<packageName></packageName>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
<wsdlLocation>https://ec.europa.eu/taxation_customs/tin/checkTinService.wsdl</wsdlLocation>
<staleFile>${project.build.directory}/jaxws/stale/checkTinService.stale</staleFile>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml</bindingFile>
</bindingFiles>
</configuration>
<id>wsimport-generate-checkTinService</id>
<phase>generate-sources</phase>
</execution>
</executions>
...
You can see the exactly configuration for using the binding file created before:
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml</bindingFile>
</bindingFiles>
4- Finally turn to refresh de WS Reference and the changes will be applied to the process of wsimport.