Adding one part into another part in WSDL4J - java

I am generating WSDL dynamically using WSDL4J and I am able to create a WSDL file, but I want a nested structure (I mean, I want to declare a complex element and add it into the message).
So I want to add the TestService element into the wsdl:message TestServiceRequest dynamically using Java code and WSDL4J...
<element name="TestService">
<complexType>
<sequence>
<element name="servicetag" type="xsd:string"/>
<element name="header" type="xsd:string"/>
<element name="requestparam" type="xsd:string"/>
<element name="body" type="xsd:string"/>
</sequence>
</complexType>
</element>
<wsdl:message name="TestServiceRequest">
<wsdl:part name="parameters" element="tns:TestService">
</wsdl:part>
</wsdl:message>
How can I achieve that?

Related

WSDL Array Complex Type not typed in Java output

When using the Axis2 WSDL2Java tool, the array seems to be not typed and therefore have to cast an object to add it.
<element name="FunnyObject" nillable="true">
<complexType>
<sequence>
<element name="id" type="string" />
<element name="joke" type="string" />
</sequence>
</complexType>
</element>
<element name="FunnyObjects" nillable="true">
<complexType>
<complexContent mixed="false">
<restriction base="SOAP-ENC:Array">
<attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="FunnyObject[]" />
</restriction>
</complexContent>
</complexType>
</element>
Any ideas what edits I need to do? New to WSDL as just learning it for a course (unfortunately in 2019).

How 'minOccurs' and 'maxOccurs' attribute value will generated inside the `element` tag of the WSDL file?

We have custom java code that deployed in the JBoss. We are firing the webservice call and the WSDL file is generating by using the Apache Axis framework.
My question is for some of the tag, minOccurs and maxOccurs attribute is present, but for some other tag, those attributes are not present.
If I want minOccurs and maxOccurs attribute inside the element tag, then where I have to configure? How this Apache Axis framework will generate these attribute.
Sample WSDL :
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="urn:sif.siperian.com" xmlns:intf="urn:sif.siperian.com"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:sif.siperian.com">
<!--
WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="urn:sif.siperian.com">
<complexType name="Account">
<sequence>
<element name="accountNumber" nillable="true" type="xsd:string"/>
<element name="accountType" nillable="true" type="xsd:string"/>
<element name="cardholderName" nillable="true" type="xsd:string"/>
<element name="city" nillable="true" type="xsd:string"/>
<element name="expirationMonth" nillable="true" type="xsd:string"/>
<element name="expirationYear" nillable="true" type="xsd:string"/>
<element name="hubStateInd" nillable="true" type="xsd:string"/>
<element name="issuingCompany" nillable="true" type="xsd:string"/>
<element name="pkeySrcObject" nillable="true" type="xsd:string"/>
<element name="postalCode" nillable="true" type="xsd:string"/>
<element name="rowidObject" nillable="true" type="xsd:string"/>
<element name="securityCode" nillable="true" type="xsd:string"/>
<element name="source" nillable="true" type="xsd:string"/>
<element name="stateProvince" nillable="true" type="xsd:string"/>
<element name="streetName" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="ArrayOfAccount">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item"
type="impl:Account"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
</wsdl:definitions>
In the above WSDL, the <complexType name="Account"> is not having property minOccurs and maxOccurs.
Where as, the <complexType name="ArrayOfAccount"> is having both the properties.
The following is a Java Code sample on how to build the following element:
<element maxOccurs="1" minOccurs="0" name="Test" nillable="true" type="xsd:string"/>
Java Code:
elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("test");
elemField.setXmlName(new javax.xml.namespace.QName("http://www.test.com", "Test"));
elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
elemField.setMinOccurs(0);
elemField.setNillable(true);
Hope this helps.

Cannot resolve the name ... to a(n) 'type definition' component

I want to import code from a WSDL file with wsimport, but i receiving this error below.
[WARNING] src-resolve: Cannot resolve the name 'impl:ArrayOf_tns1_IndicadorVO' to a(n) 'type definition' component.
Here's the WSDL file...
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://ws.cnmpind.cnmp.gov.br" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://ws.cnmpind.cnmp.gov.br" xmlns:intf="http://ws.cnmpind.cnmp.gov.br" xmlns:tns1="http://vo.ws.cnmpind.cnmp.gov.br" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://ws.cnmpind.cnmp.gov.br" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://vo.ws.cnmpind.cnmp.gov.br"/>
<element name="getQuestionariosDisponiveis">
<complexType>
<sequence>
<element name="email" type="xsd:string"/>
<element name="senha" type="xsd:string"/>
<element name="dataInicio" type="xsd:string"/>
<element name="dataFinal" type="xsd:string"/>
<element name="areaAtuacao" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="getQuestionariosDisponiveisResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="getQuestionariosDisponiveisReturn" type="tns1:QuestionarioVO"/>
</sequence>
</complexType>
</element>
<complexType name="ArrayOf_tns1_IndicadorVO">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="tns1:IndicadorVO"/>
</sequence>
</complexType>
<element name="salvaRespostasQuestionarios">
<complexType>
<sequence>
<element name="email" type="xsd:string"/>
<element name="senha" type="xsd:string"/>
<element name="dataInicio" type="xsd:string"/>
<element name="dataFinal" type="xsd:string"/>
<element name="areaAtuacao" type="xsd:string"/>
<element maxOccurs="unbounded" name="questionarios" type="tns1:QuestionarioVO"/>
</sequence>
</complexType>
</element>
<element name="salvaRespostasQuestionariosResponse">
<complexType/>
</element>
</schema>
<schema elementFormDefault="qualified" targetNamespace="http://vo.ws.cnmpind.cnmp.gov.br" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://ws.cnmpind.cnmp.gov.br"/>
<complexType name="IndicadorVO">
<sequence>
<element name="descricaoDescritor" nillable="true" type="xsd:string"/>
<element name="id" type="xsd:long"/>
<element name="idDescritor" type="xsd:int"/>
<element name="idIndicadorPai" type="xsd:long"/>
<element name="idQuestionario" type="xsd:long"/>
<element name="nomeDescritor" nillable="true" type="xsd:string"/>
<element name="ordem" type="xsd:int"/>
<element name="tamanhoDescritor" nillable="true" type="xsd:decimal"/>
<element name="tipoDescritor" nillable="true" type="xsd:string"/>
<element name="valor" nillable="true" type="xsd:decimal"/>
</sequence>
</complexType>
<complexType name="QuestionarioVO">
<sequence>
<element name="aberto" type="xsd:boolean"/>
<element name="dataAtualizacao" nillable="true" type="xsd:string"/>
<element name="dataInicio" nillable="true" type="xsd:string"/>
<element name="dataTermino" nillable="true" type="xsd:string"/>
<element name="descricaoArea" nillable="true" type="xsd:string"/>
<element name="id" type="xsd:long"/>
<element name="idArea" type="xsd:int"/>
<element name="idUnidade" type="xsd:int"/>
<element name="indicadores" nillable="true" type="impl:ArrayOf_tns1_IndicadorVO"/>
<element name="nomeArea" nillable="true" type="xsd:string"/>
<element name="nomeUnidade" nillable="true" type="xsd:string"/>
<element name="nomeUsuarioAtualizacao" nillable="true" type="xsd:string"/>
<element name="siglaUnidade" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="salvaRespostasQuestionariosResponse">
<wsdl:part element="impl:salvaRespostasQuestionariosResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getQuestionariosDisponiveisResponse">
<wsdl:part element="impl:getQuestionariosDisponiveisResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getQuestionariosDisponiveisRequest">
<wsdl:part element="impl:getQuestionariosDisponiveis" name="parameters"/>
</wsdl:message>
<wsdl:message name="salvaRespostasQuestionariosRequest">
<wsdl:part element="impl:salvaRespostasQuestionarios" name="parameters"/>
</wsdl:message>
<wsdl:portType name="QuestionarioWS">
<wsdl:operation name="getQuestionariosDisponiveis">
<wsdl:input message="impl:getQuestionariosDisponiveisRequest" name="getQuestionariosDisponiveisRequest"/>
<wsdl:output message="impl:getQuestionariosDisponiveisResponse" name="getQuestionariosDisponiveisResponse"/>
</wsdl:operation>
<wsdl:operation name="salvaRespostasQuestionarios">
<wsdl:input message="impl:salvaRespostasQuestionariosRequest" name="salvaRespostasQuestionariosRequest"/>
<wsdl:output message="impl:salvaRespostasQuestionariosResponse" name="salvaRespostasQuestionariosResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="QuestionarioWSSoapBinding" type="impl:QuestionarioWS">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getQuestionariosDisponiveis">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getQuestionariosDisponiveisRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getQuestionariosDisponiveisResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="salvaRespostasQuestionarios">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="salvaRespostasQuestionariosRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="salvaRespostasQuestionariosResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="QuestionarioWSService">
<wsdl:port binding="impl:QuestionarioWSSoapBinding" name="QuestionarioWS">
<wsdlsoap:address location="http://aplicativos.cnmp.gov.br/cnmpind/services/QuestionarioWS"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Someone can give me some light? Thanks!
EDIT 1:
This is just a warning. The true error is
package-info.java:1: error: error while writing package-info: could
not create parent directories
#javax.xml.bind.annotation.XmlSchema(namespace =
"http://ws.cnmpind.cnmp.gov.br", elementFormDefault =
javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
So, the code was generated, but the error happens when compiling.
Its seems to be a WSIMPORT bug, i don't know.
To solve the problem, I used the param "-Xnocompile" to force WSIMPORT only generate the code whithout compiling.
After that, i compiled the code by command line with javac and put the classes into a .jar
I added the .jar to the project and everything are running fine.

How to pass null value to Document Literal SOAP Request

Hi,
I am passing the null value for the resourcekey in the SOAP Request as below.
<urn:createNetwork>
<net:resourceIdentityInfo>
<api:resourceKey ></api:resourceKey>
<api:resourceName>TEST2</api:resourceName>
<api:resourceType>NETWORK</api:resourceType>
</net:resourceIdentityInfo>
</urn:createNetwork>
The sample WSDL file for this request is as below:
<wsdl:operation name="createNetwork">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="createNetworkRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="createNetworkResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<element name="createNetwork">
<complexType>
<sequence>
<element name="in0" type="tns5:NetworkInfo"/>
</sequence>
</complexType>
</element>
<element name="createNetworkResponse">
<complexType>
<sequence>
<element name="createNetworkReturn" type="tns2:ResourceIdentityInfo"/>
</sequence>
</complexType>
</element>
<wsdl:message name="createNetworkRequest">
<wsdl:part element="intf:createNetwork" name="parameters">
</wsdl:part>
</wsdl:message>
<complexType name="NetworkInfo">
<sequence>
<element name="comments" nillable="true" type="impl:ArrayOf_xsd_anyType"/>
<element name="description" nillable="true" type="xsd:string"/>
<element name="dnsDomainName" nillable="true" type="xsd:string"/>
<element name="documentUrls" nillable="true" type="impl:ArrayOf_xsd_anyType"/>
<element name="resourceIdentityInfo" nillable="true" type="tns2:ResourceIdentityInfo"/>
</sequence>
</complexType>
<complexType name="ResourceIdentityInfo">
<sequence>
<element name="resourceKey" nillable="true" type="xsd:string"/>
<element name="resourceName" nillable="true" type="xsd:string"/>
<element name="resourceType" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
I have declared as nillable=true in all the places.
If i pass the resourcekey as empty, in SOAP UI I am getting null pointer exception.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>java.lang.NullPointerException</faultstring>
<detail>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">linbgg244.lss.emc.com</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
I have tried with
<api:resourceKey xsi:nil="true" ></api:resourceKey>
The same null pointer exception is getting.
Could you please guide to resolve the issue?
Thanks in advance.
I don't think you have to pass null here. AFAIK, the webservice code is throwing the NullPointerException during processing of the SOAP request. Try to identify why is that ? and do a null check or make changes in the logic to prevent it.

Specify order of elements in a SOAP response using java

I have a web service that returns a dataset object that contains the current weather forecast along with 0 or more weather alerts for a county/state. The dataset object just contains a Weather object and an array of Alerts objects. One of the clients of this would like to have it so the response gives the weather first instead of the alerts. Is there a way to specify the order of the response elements? I thought I could just change the WSDL to map out the weather first then the alerts, but that didn't do anything.
Here's the generic WSDL sheet:
(well, it showed formatted in the preview but not after posting... how can I post formatted XML on here? I tried using back-ticks as well as pre and code).
<wsdl:definitions ...>
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://ws.sample.com" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://objects.sample.com"/>
<element name="getAll">
<complexType>
<sequence>
<element name="county" type="xsd:string"/>
<element name="state" type="xsd:string"/>
<element name="latitude" type="xsd:double"/>
<element name="longitude" type="xsd:double"/>
</sequence>
</complexType>
</element>
<element name="getAllResponse">
<complexType>
<sequence>
<element name="getAllReturn" type="tns1:DataSet"/>
</sequence>
</complexType>
</element>
<complexType name="ArrayOf_tns1_Alert">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="tns1:Alert"/>
</sequence>
</complexType>
</schema>
<schema elementFormDefault="qualified" targetNamespace="http://objects.sample.com" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://ws.sample.com"/>
<complexType name="Alert">
<sequence>
<element name="county" nillable="true" type="xsd:string"/>
<element name="endDate" nillable="true" type="xsd:dateTime"/>
<element name="locationCode" nillable="true" type="xsd:string"/>
<element name="startDate" nillable="true" type="xsd:dateTime"/>
<element name="state" nillable="true" type="xsd:string"/>
<element name="title" nillable="true" type="xsd:string"/>
<element name="warning" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="Weather">
<sequence>
<element name="chancePrecipitation" type="xsd:int"/>
<element name="period" nillable="true" type="xsd:string"/>
<element name="skyConditions" nillable="true" type="xsd:string"/>
<element name="temperature" type="xsd:int"/>
<element name="temperatureType" nillable="true" type="xsd:string"/>
<element name="temperatureUnit" nillable="true" type="xsd:string"/>
<element name="windDirection" nillable="true" type="xsd:string"/>
<element name="windSpeed" type="xsd:int"/>
<element name="windUnit" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="DataSet">
<sequence>
<element name="weather" nillable="true" type="tns1:Weather"/>
<element name="alert" nillable="true" type="impl:ArrayOf_tns1_Alert"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="getAllResponse">
<wsdl:part element="impl:getAllResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getAllRequest">
<wsdl:part element="impl:getAll" name="parameters"/>
</wsdl:message>
<wsdl:portType name="TSTWeather">
<wsdl:operation name="getAll">
<wsdl:input message="impl:getAllRequest" name="getAllRequest"/>
<wsdl:output message="impl:getAllResponse" name="getAllResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TSTWeatherSoapBinding" type="impl:TSTWeather">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getAll">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getAllRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getAllResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TSTWeatherService">
<wsdl:port binding="impl:TSTWeatherSoapBinding" name="TSTWeather">
<wsdlsoap:address location="http://localhost:8282/Services/service/TSTWeather"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I don't see how I could specify the order of my service response.
In many cases, just changing the WSDL does not change the service, and it's the service that determines the order of the elements in the XML.
We can change the order by adding JAXB annotations in the particular java file.
For example: #XmlType(propOrder = {"x", "y", "z"})

Categories