Wsdl client works in windows but not in linux environment - java

I'm a project than I generate a wsdl client with apache cfx.
When I run my project in mi local machine with Windows it works perfectlly, but when I was to try in machine with SO Linux (Red hat) it didn't work.
My xml since Windows is:
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header>
<wsse:Security xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
<wsse:UsernameToken wsu:Id='UsernameToken-3e963a94-b8fc-4876-ace8-b675f270d3a0'>
<wsse:Username>myusername</wsse:Username>
<wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>mypass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<ns4:HeaderReq xmlns:ns4='http://www.something.com/ws/nss/general/Headers' xmlns:ns3='http://www.something.com/ws/nss/common/ExcepcionGeneral' xmlns:ns2='http://www.something.com/ws/iss/nameWebConsume' locale='es_MX' codIdioma='UTF-8'>
<Deploy>
***
</Deploy>
<Access>
***
</Access>
<Consumer>
***
</Consumer>
<RequestData>
***
</RequestData>
</ns4:HeaderReq>
</env:Header>
<env:Body>
<CheckSomething xmlns='http://www.something.com/ws/nss/nameWebConsume' xmlns:ns4='http://www.something.com/ws/nss/general/Headers' xmlns:ns3='http://www.something.com/ws/nss/common/ExcepcionGeneral' xmlns:ns2='http://www.something.com/ws/iss/nameWebConsume'>
<Folio>123456789</Folio>
</CheckSomething>
</env:Body>
</env:Envelope>
My xml since linux is:
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Header>
<wsse:Security xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
<wsse:UsernameToken wsu:Id='UsernameToken-9d835b01-63d0-4d88-9d15-6c06b73531a2'>
<wsse:Username>myusername</wsse:Username>
<wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>mypass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<ns2:HeaderReq xmlns:ns2='http://www.something.com/ws/nss/general/Headers' xmlns:ns3='http://www.something.com/ws/nss/common/ExcepcionGeneral' xmlns:ns4='http://www.something.com/ws/iss/nameWebConsume' codIdioma='UTF-8' locale='es_MX'>
<Deploy>
***
</Deploy>
<Access>
***
</Access>
<Consumer>
***
</Consumer>
<RequestData>
***
</RequestData>
</ns2:HeaderReq>
</soap:Header>
<soap:Body>
<ns4:CheckSomething xmlns:ns2='http://www.something.com/ws/nss/general/Headers' xmlns:ns3='http://www.something.com/ws/nss/common/ExcepcionGeneral' xmlns:ns4='http://www.something.com/ws/iss/nameWebConsume'>
<Folio>123456789</Folio>
</ns4:CheckSomething>
</soap:Body>
</soap:Envelope>
As you can see there are different tags from both SO, my question is: How I can create the same xml request to consume wsdl service?
My code configuration in classes, every header looks like I post
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "HeaderRequestType", propOrder = {
"deploy",
"access",
"consumer",
"requestData"
})
public class HeaderRequestType {...}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "CheckSomething", namespace = "http://www.something.com/ws/iss/nameWebConsume", propOrder = {
"folio"
})
public class CheckSomething {...}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "Deploy", propOrder = {
...
})
public class Deploy {...}
My interface where I consume SOAP
#WebService(targetNamespace = "http://www.something.com/ws/iss/nameWebConsume", name = "nameWebConsume")
#XmlSeeAlso({ObjectFactory.class})
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface CheckSomething {
#WebMethod
public void CheckSomething(
#WebParam(partName = "request", name = "CheckSomethingIn", targetNamespace = "http://www.something.com/ws/iss/nameWebConsume") CheckSomethingInType request,
#WebParam(partName = "headerRequest", name = "HeaderReq", targetNamespace = "http://www.something.com/ws/nss/general/Headers", header = true) HeaderRequestType headerRequest,
#WebParam(partName = "response", mode = WebParam.Mode.OUT, name = "CheckSomethingOut", targetNamespace = "http://www.something.com/ws/iss/nameWebConsume") javax.xml.ws.Holder<CheckSomethingOutType> response,
#WebParam(partName = "headerResponse", mode = WebParam.Mode.OUT, name = "HeaderRes", targetNamespace = "http://www.something.com/ws/nss/general/Headers", header = true) javax.xml.ws.Holder<HeaderResponseType> headerResponse
) throws CheckSomethingFault;
}
That's it.
I you need more files where I have configuration I will update my post.
Update 1
I have a response in windows good (with data) and when I try in linux I have an error says: Error in data integration cvc-complex-type 2.4: in element

Related

How do I call a request that has entity in it?

(1) The class I described below includes three strings and one entity.
(2) The text I sent as a call is as follows.
(3) But I'm making the mistake.
1:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {"tesisatKod", "islemGuid", "islemTutari", "islemTuru"})
#XmlRootElement(name = "secondStageRequest")
public class SecondStageRequest {
protected String tesisatKod;
protected String islemGuid;
// protected Date sorguSaatTarih;
protected String islemTutari;
protected IslemTuru islemTuru;
}
2:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xc="http://xml.cinigaz.com.tr">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" wsse:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>admin</wsse:Username>
<wsse:Password>pwd1234</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<xc:secondStageRequest>
<xc:tesisatKod>bbb</xc:tesisatKod>
<xc:islemGuid>bbb</xc:islemGuid>
<xc:islemTutari>bbb</xc:islemTutari>
<xc:islemTuru>
<xc:islemTuruId> 1</xc:islemTuruId>
<xc:islemTuruAdi> aaa</xc:islemTuruAdi>
</xc:islemTuru>
</xc:secondStageRequest>
</soapenv:Body>
</soapenv:Envelope>
3:
WARN 20148 --- [nio-9020-exec-2] s.w.s.s.e.i.PayloadValidatingInterceptor : XML validation error on request: cvc-type.3.1.2: Element 'xc:islemTuru' is a simple type, so it must have no element information item [children].

JAX-WS add Username-Token to SOAP-Header

I have a JAX-WS Client generated from WSDL files.
Setting Headers worked so far with following code:
WSBindingProvider bp = (WSBindingProvider) port;
bp.setOutboundHeaders(
Headers.create(new QName("http://schemas.xmlsoap.org/ws/2005/08/addressing", "To", "wsa"), "--To--"),
Headers.create(new QName("http://schemas.xmlsoap.org/ws/2005/08/addressing", "Action", "wsa"), "--Action--"),
Headers.create(new QName("http://schemas.xmlsoap.org/ws/2005/08/addressing", "MessageID", "wsa"), UUID.randomUUID().toString())
);
Which produces (as desired) the following XML snippet:
<S:Header>
<To
xmlns="http://schemas.xmlsoap.org/ws/2005/08/addressing">--to--
</To>
<Action
xmlns="http://schemas.xmlsoap.org/ws/2005/08/addressing">--action--
</Action>
<MessageID
xmlns="http://schemas.xmlsoap.org/ws/2005/08/addressing">fe1b400a-e724-4486-8618-b1d36a0acbbb
</MessageID>
</S:Header>
But I need the following chained Tags, which I couldn't acheive with Headers.create(...):
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="PartnerId" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>--username--</wsse:Username>
</wsse:UsernameToken>
</wsse:Security>
Any ideas how I can add this to the header?
The following code works for me:
private static final String SCHEMA = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
private static final String SCHEMA_PREFIX = "wsse";
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
// Create a SOAP header
try {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader header = soapEnvelope.getHeader();
// Add the security SOAP header element
SOAPHeaderElement security = header.addHeaderElement(new QName(SCHEMA, "Security", SCHEMA_PREFIX));
SOAPElement usernameToken = security.addChildElement("UsernameToken", SCHEMA_PREFIX);
SOAPElement usernameElement = usernameToken.addChildElement("Username", SCHEMA_PREFIX);
SOAPElement passwordElement = usernameToken.addChildElement("Password", SCHEMA_PREFIX);
Name typeName = soapEnvelope.createName("type");
passwordElement.addAttribute(typeName, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
usernameElement.setTextContent(USERNAME);
passwordElement.setTextContent(PASSWORD);
((WSBindingProvider) webServicePort).setOutboundHeaders(Headers.create(security));
} catch (SOAPException e) {
logger.severe("Error setting SOAP header");
e.printStackTrace();
}
The XML is as follows:
<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<env:Header>
<wsse:Security env:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</env:Header>
<env:Body>
...

Using JAX-WS to send SOAP request with headers

The request which I want to send is :-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:idm="http://integration.standardandpoors.com/Schema/IDM">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-23762130">
<wsu:Created>2013-06-09T06:00:44.733Z</wsu:Created>
<wsu:Expires>2013-06-09T08:00:44.733Z</wsu:Expires>
</wsu:Timestamp>
<wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" EncodingType="SSHA" ValueType="AccessManagerSSOSecurityToken" wsu:Id="OAMToken">TOKEN HARE</wsse:BinarySecurityToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<idm:findUserById>
<applicationName>APP ID</applicationName>
<userId>USER ID</userId>
</idm:findUserById>
</soapenv:Body>
</soapenv:Envelope>
My current java code is
public class WsClient{
public static void main(String[] args) throws Exception {
IdmService sis = new IdmService();
IdmWebServicePort si = sis.getIdmWebServiceImplPort();
WSBindingProvider bp = (WSBindingProvider)si;
Element node = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"> <wsu:Timestamp xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"Timestamp-23762130\"><wsu:Created>2013-06-09T06:00:44.733Z</wsu:Created> <wsu:Expires>2013-06-09T08:00:44.733Z</wsu:Expires></wsu:Timestamp><wsse:BinarySecurityToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" EncodingType=\"SSHA\" ValueType=\"AccessManagerSSOSecurityToken\" wsu:Id=\"OAMToken\">token here</wsse:BinarySecurityToken></wsse:Security>".getBytes())).getDocumentElement();
bp.setOutboundHeaders(
Headers.create(node)
);
//si.getSecurityChallengeQuestionsAndAnswersForUser("APP NAME", "USER ID");
User u=si.findUserById("MSA", "test100#sandp.com");
System.out.println(u.getFirstName());
}
}
error which I am getting is :-
Exception in thread "main" java.lang.NoSuchMethodError: com.sun.xml.bind.api.JAXBRIContext.newInstance

Setting up an XML response for SOAP

I'm having a real hard time with this issue.
Basically I've built a WebService using Java/JAX-WS, this is my Interface
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
#WebService
public interface OperationsInterface {
#WebResult(name = "result")
LoginResponse Login(#WebParam(name = "login") Login login);
#WebResult(name = "result")
String Purchase(#WebParam(name = "purchase") Purchase purchase);
}
Login is just a POJO that contains 2 strings (username and password)
LoginResponse is another POJO, it has this
String status;
int code;
String message;
SubscriptionTier subscriptionTier;
String accountNumber;
String firstName;
String lastName;
Nothing fancy, pretty simple in fact. The request is something like this
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ott="http://ott.amentum.net/">
<soapenv:Header/>
<soapenv:Body>
<ott:Login>
<login>
<username>USERNAME</username>
<password>1234</password>
</login>
</ott:Login>
</soapenv:Body>
</soapenv:Envelope>
And the response comes like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:LoginResponse xmlns:ns2="http://ott.amentum.net/">
<result>
<accountNumber>0110000076</accountNumber>
<code>1</code>
<firstName>JOHN</firstName>
<lastName>DOE</lastName>
<message>Login has been successful.</message>
<status>success</status>
<subscriptionTier>
<tier>TVOD</tier>
<tier>CANAL</tier>
<tier>CATCHUP</tier>
</subscriptionTier>
</result>
</ns2:LoginResponse>
</soap:Body>
</soap:Envelope>
As far as I know, this is correct, however, my customer is expecting something like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:LoginResponse xmlns:ns2="http://ott.amentum.net/">
<accountNumber>0410089676</accountNumber>
<code>1</code>
<firstName>MARIA DEL CARMEN</firstName>
<lastName>PADILLA MARTIN</lastName>
<message>Login has been successful.</message>
<status>success</status>
<subscriptionTier>
<tier>TVOD</tier>
<tier>CANAL</tier>
<tier>CATCHUP</tier>
</subscriptionTier>
</ns2:LoginResponse>
</soap:Body>
</soap:Envelope>
They want me to remove the result tag, which is the name of the LoginResponse object I created to return the information.
Is there a way to do this?
Thanks in advance

Adding custom Soap Header to Webservice Request

I have generated stub for a webserivce using apache axis2 and I want to add custom soap header to the request. I want the soap header to look like this
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:soapHeader xmlns:ns1="urn:oasis:names:core" soapenv:mustUnderstand="0">
<ns1:Username>myuser</ns1:Username>
<ns1:Password>mypass</ns1:Password>
</ns1:soapHeader>
</soapenv:Header>
and I am writing this code
org.apache.axiom.soap.SOAPEnvelope env = null;
org.apache.axiom.om.OMFactory omFactory = org.apache.axiom.om.OMAbstractFactory.getOMFactory();
org.apache.axiom.om.OMElement omElement = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "soapHeader", "ns1"));
org.apache.axiom.om.OMElement omElement1 = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "Username", "ns1"));
org.apache.axiom.om.OMElement omElement2 = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "Password", "ns1"));
omElement.addChild(omElement1);
omElement.addChild(omElement2);
omElement1.setText("myuser");
omElement2.setText("mypass");
addHeader(omElement, env);
but I am not getting the required soap header. This is what im getting
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:soapHeader xmlns:ns1="urn:oasis:names:core" soapenv:mustUnderstand="0">
<ns1:Username>myuser</ns1:Username>
</ns1:soapHeader>
</soapenv:Header>
as you can see password is missing. I want to know what I am doing wrong.

Categories

Resources