JAXWS SOAP Response Schema - java

I am in the process of moving an older web service that had dependency on Weblogic 8 (servicegen) to a JAX WS implementation using annotations. I used the existing WSDL and JAXB to generate the data objects (marshalling/unmarshalling). However, I notice a difference in the SOAP response that is now being generated with JAXWS. I need to generate the same response, as there are over 900 clients, and can’t ask them to modify their code to use the new response schema.
The existing response looks like this:
<env:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header/>
<env:Body>
<m:findAllCertInfoByOwnerResponse xmlns:m="http://uum.webservices.com">
<n1:result xsi:type="n2:ArrayOfWSCertInfo" xmlns:n1="http://uum.webservices.com" xmlns:n2="java:com.service.data">
<n2:WSCertInfo>
<n2:CPCreateDate> </n2:CPCreateDate>
<n2:CPExpireDate> </n2:CPExpireDate>
<n2:CPStatus> </n2:CPStatus>
<n2:PrevUniqueId>123456</n2:PrevUniqueId>
<n2:UniqueId></n2:UniqueId>
<n2:certID xsi:nil="true"/>
<n2:certStatus/>
<n2:endDate xsi:nil="true"/>
<n2:issuerDN> </n2:issuerDN>
<n2:owner></n2:owner>
<n2:profileName> </n2:profileName>
<n2:renewalStatus xsi:nil="true"/>
<n2:revokeReason/>
<n2:serialNo xsi:nil="true"/>
<n2:startDate xsi:nil="true"/>
<n2:subjectDN xsi:nil="true"/>
<n2:validCertificate>false</n2:validCertificate>
<n2:validEnrollment>true</n2:validEnrollment>
</n2:WSCertInfo>
</n1:result>
</m:findAllCertInfoByOwnerResponse>
</env:Body>
</env:Envelope>
The new JAX WS SOAP response has the following format:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findLatestCertInfoByOwnerResponse xmlns:ns3="java:com.service.data" xmlns:ns2="http://uum.webservices.com">
<result>
<ns2:result>
<ns3:WSCertInfo>
<ns3:CPCreateDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:CPExpireDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:CPStatus xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:PrevUniqueId>123456</ns3:PrevUniqueId>
<ns3:UniqueId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:certID xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:certStatus xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:endDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:issuerDN xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:owner xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:profileName xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:renewalStatus xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:revokeReason xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:serialNo xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:startDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:subjectDN xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:validCertificate>false</ns3:validCertificate>
<ns3:validEnrollment>false</ns3:validEnrollment>
</ns3:WSCertInfo>
</ns2:result>
</result>
</ns2:findLatestCertInfoByOwnerResponse>
</S:Body>
</S:Envelope>
The JAXWS SOAP response is pretty close except for the following:
JAXWS response is missing the xsi:type and xmlns info. Plus it is nested in the attribute.
How can I add the xsi:type and xmlns to the attribute?
I am including the example class to show the defined web annotations.
Thanks in advance for your assistance!!!!!
The Web Service class looks like the following:
#WebService(
name = "UUMCertLocatorService",
serviceName = "UUMCertLocatorService",
portName = "UUMCertLocatorServicePort",
targetNamespace = "http://uum.webservices.com",
wsdlLocation = "UUMCertLocatorService.wsdl")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED,
style = SOAPBinding.Style.DOCUMENT,
use = SOAPBinding.Use.LITERAL)
public class UUMCertLocatorServiceEndPoint {
#WebMethod(action="",operationName="findLatestCertInfoByOwner")
#WebResult(name="findLatestCertInfoByOwnerResponse",header=true,targetNamespace="java:com.service.data",partName="http://uum.webservices.com")
public FindAllCertInfoByOwnerResponse findAllCertInfoByOwner(
#WebParam(targetNamespace="http://uum.webservices.com",
partName="http://uum.webservices.com",
name="string")String uniqueID,
#WebParam(targetNamespace="http://uum.webservices.com",
partName="http://uum.webservices.com",
name="string0")String adminSessionSpec,
#WebParam(targetNamespace="http://uum.webservices.com",
partName="http://uum.webservices.com",
name="string1")String webKey) throws WSUUMException
{
LogHelper.debug(UUMCertLocatorServiceEndPoint.class, "Params: {} {} {} ", uniqueID,adminSessionSpec,webKey);
final ObjectFactory objectFactory = new ObjectFactory();
FindAllCertInfoByOwnerResponse response = objectFactory.createFindAllCertInfoByOwnerResponse();
WSCertInfo certinfo = objectFactory.createWSCertInfo();
certinfo.setBofaPrevUniqueId("123456");
ArrayOfWSCertInfo arraycert = objectFactory.createArrayOfWSCertInfo();
arraycert.getWSCertInfo().add(certinfo);
response.setResult(arraycert);
return response;
}
}

Related

How do i remove the <soapenv:Envelope> <soapenv:Header/> <soapenv:Body> tags from getting generated from my wsdl?

I need to generate a soap request like the below one :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document xmlns:ns2="http://www.xyz" xmlns="thsss.738.syhd.738">
<Customer>
<Group>
<Message>Something</Message>
</Group>
</Customer>
</Document>
But the request getting generated is as below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://eygyjdg.dbajshb/" xmlns:thss="thsss.738.syhd.738" xmlns:xyz="http://www.xyz">
<soapenv:Header/>
<soapenv:Body>
<Document>
<Customer>
<Group>
<Message>Something</Message>
</Group>
</Customer>
</Document>
</soapenv:Body>
</soapenv:Envelope>
Hence i get a namespace on the "Document" element, is not a valid SOAP version
Can you please tell me how to go about this.

XMLBeam parsing

I am unable to properly read a XML file with XMLBeam:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:storeTokenResponse xmlns:ns1="http://recurring.services.adyen.com">
<ns1:result>
<additionalData xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<alias xmlns="http://recurring.services.adyen.com">ALIAS</alias>
<aliasType xmlns="http://recurring.services.adyen.com">Default</aliasType>
<params xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<pspEchoData xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<pspReference xmlns="http://recurring.services.adyen.com">PSPREFERENCE</pspReference>
<recurringDetailReference xmlns="http://recurring.services.adyen.com">RECURRINGDETAILREFERENCE</recurringDetailReference>
<redirectType xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<redirectUrl xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<result xmlns="http://recurring.services.adyen.com">RESULT</result>
</ns1:result>
</ns1:storeTokenResponse>
</soap:Body>
with given Java class:
public interface PaymentResponse {
#XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:alias")
String getAlias();
#XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:recurringDetailReference")
String getRecurringDetailReference();
#XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:pspReference")
String getPspReference();
#XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:result")
String getResult();
}
I was doing it like this :
final PaymentResponse paymentResponse = new XBProjector.onXMLString(xml).read(PaymentResponse.class);
Assert.assertTrue("ALIAS",paymentResponse.getAlias());
And yes, proper XPath is ns1:alias, as I've tested.
But looks like XMLBeam is not properly recognizing the values.
Can anyone help, please ?

Override namespace with empty namespace CXF (JBoss EAP 6.2.4.GA)

I have the following issue with CXF version 2.7.7-redhat-1, that seems like a bug in the library.
With the following request:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<authorizePayment xmlns="http://ejb.example.org">
<request xmlns="">
<role xmlns:q1="http://to.homepay.example.org" xsi:type="q1:CustomerTO">
<user>7C742</user>
</role>
<error>
<errorCode>1</errorCode>
<errorMessage>1</errorMessage>
</error>
<status>
<code>1</code>
</status>
<ordAccount>1</ordAccount>
<logId>374216011815223570893830967949</logId>
<signMethod>1</signMethod>
<lang>1</lang>
<terminalId>1</terminalId>
<terminalLocation>Earth</terminalLocation>
</request>
</authorizePayment>
</soap:Body>
</soap:Envelope>
I get the following error:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: unexpected element (uri:"http://ejb.example.org", local:"request"). Expected elements are <{}request></faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
From the request you can clearly see that the namespace of the request is "" overridden from its parent.
If I change the request to:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<aa:authorizePayment xmlns:aa="http://ejb.example.org">
<request xmlns="">
<role xmlns:q1="http://to.homepay.example.org" xsi:type="q1:CustomerTO">
<user>7C742</user>
</role>
<error>
<errorCode>1</errorCode>
<errorMessage>1</errorMessage>
</error>
<status>
<code>1</code>
</status>
<ordAccount>1</ordAccount>
<logId>374216011815223570893830967949</logId>
<signMethod>1</signMethod>
<lang>1</lang>
<terminalId>1</terminalId>
<terminalLocation>Earth</terminalLocation>
</request>
</aa:authorizePayment>
</soap:Body>
</soap:Envelope>
The call works. I need a way to fix this issue server side, the client can't be modified to change the request.
Versions:
JBoss AS release: 7.3.4.Final-redhat-1 "Janus"
JBoss AS product: EAP 6.2.4.GA
java.version: 1.7.0_91
Set the elementFormDefault=qualified in the wsdl, generate the artifacts and redeploy the application.
Qualified means that local element declarations (xs:element within xs:complexType) refers to elements in the target namespace of the schema. Without it, they refer to elements in no namespace.

Adding xml string to soap message

Using this xml file for creating soap message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
<soapenv:Header/>
<soapenv:Body>
<ord:UpdateOrder>
<ord:OrderId>26</ord:OrderId>
<ord:View>BroadbandDSLOrderCreation</ord:View>
<ord:UpdatedOrder>
</ord:UpdatedOrder>
</ord:UpdateOrder>
</soapenv:Body>
</soapenv:Envelope>
XML String that need to insert in between UpdatedOrder tags.
<_root>
<DslOrder index="1422888817752">
<SubscriberInfo index="1422888817756">
<Address index="1422888817758">
<City index="1422888817761">OTT</City>
<PostalCode index="1422888817760">101</PostalCode>
<Street index="1422888817759">333</Street>
</Address>
<PhoneNumber index="1422888817762">438</PhoneNumber>
<Name index="1422888817757">xyz</Name>
</SubscriberInfo>
</DslOrder>
</_root>
Output of soap message must be like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
<soapenv:Header/>
<soapenv:Body>
<ord:UpdateOrder>
<ord:OrderId>26</ord:OrderId>
<ord:View>BroadbandDSLOrderCreation</ord:View>
<ord:UpdatedOrder>
<_root>
<DslOrder index="1422888817752">
<SubscriberInfo index="1422888817756">
<Address index="1422888817758">
<City index="1422888817761">OTT</City>
<PostalCode index="1422888817760">101</PostalCode>
<Street index="1422888817759">333</Street>
</Address>
<PhoneNumber index="1422888817762">438</PhoneNumber>
<Name index="1422888817757">xyz</Name>
</SubscriberInfo>
</DslOrder>
</_root>
</ord:UpdatedOrder>
</ord:UpdateOrder>
</soapenv:Body>
</soapenv:Envelope>
Need to add the XML String to soap envelope.
How can I add that XML string to soap envelope as shown in output?
I am converting xml file to soap message.Now i need to add xml string to soap message (in between same tags). Please help me
You may want to look into using <![CDATA[]]> tags so that the message doesn't try to parse your payload (which happens to be XML).
For example:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
<soapenv:Header/>
<soapenv:Body>
<ord:UpdateOrder>
<ord:OrderId>26</ord:OrderId>
<ord:View>BroadbandDSLOrderCreation</ord:View>
<ord:UpdatedOrder>
<![CDATA[
<_root>
<DslOrder index="1422888817752">
<SubscriberInfo index="1422888817756">
<Address index="1422888817758">
<City index="1422888817761">OTT</City>
<PostalCode index="1422888817760">101</PostalCode>
<Street index="1422888817759">333</Street>
</Address>
<PhoneNumber index="1422888817762">438</PhoneNumber>
<Name index="1422888817757">xyz</Name>
</SubscriberInfo>
</DslOrder>
</_root>
]]>
</ord:UpdatedOrder>
</ord:UpdateOrder>
</soapenv:Body>
If you are making the SOAP calls with a Java library, such as jax-ws, the library will take care of this for you (you only have to send the XML payload as is).

SOAP sessionkey in header

I tried sending a SOAP message using saaj, but I can't add multiple headers element, how do I send a SOAP message like the following?
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"xmlns:ns1="urn://xparcws/ticket" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn://xparcws/session" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
<env:Header>
<ns2:Session><scalar>asd</scalar>
<sessionkey>67e61b5b36e3c989d91eba0d8621</sessionkey>
</ns2:Session>
</env:Header>
<env:Body>
<ns1:TicketService.requestTicket env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<ticketid xsi:type="xsd:long">1261534</ticketid>
</ns1:TicketService.requestTicket></env:Body>
</env:Envelope>

Categories