KSOAP2 how to change Prefixes - java

I got little Problems with my generated code:
here the XML Structure that i need to have:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<soapenv:Envelope xmlns:v1="http://openclinica.org/ws/study/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="soapenc" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-27777511" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>xxxx</wsse:Username>
<wsse:Password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxxxxx</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<v1:listAllRequest/>
</soapenv:Body>
</soapenv:Envelope>
and hereĀ“s my Code that i have done:
declarePrefix("v1", NAMESPACE);
getBody().addTextNode(null, METHOD_NAME, "?");
XMLParentNode security = new XMLParentNodeImpl(HEADER_NAMESPACE, "Security");
security.addAttribute(HEADER_NAMESPACE,"mustUnderstand", "1");
XMLParentNode usernameToken = new XMLParentNodeImpl(UNT_NAMESPACE, "UsernameToken");
usernameToken.addTextNode(null, "wsse:Username", "root");
usernameToken.addTextNode(PASSTYPE, "wsse:Password", Constants.OC_PASSWORD);
security.addElement(usernameToken);
getHeader().addElement(security);
but the output looks like:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<soapenv:Envelope xmlns:v1="http://openclinica.org/ws/study/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<n0:Security n0:mustUnderstand="1" xmlns:n0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<n1:UsernameToken xmlns:n1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>xxxx</wsse:Username>
<n2:wsse:Password xmlns:n2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxxxxx</n2:wsse:Password>
</n1:UsernameToken>
</n0:Security>
</soapenv:Header>
<soapenv:Body>
<listAllRequest>?</listAllRequest>
</soapenv:Body>
</soapenv:Envelope>
you see i have some trouble with the lines
<n0:Security....
<n1:UsernameToken...
<n2:wsse:Password...
how can i change the n0,n1 etc... not just in the beginn of the line specialy on the tags like n0:mustUnderstand="1"
i tryed to declare prefixes etc but nothing changes tis object.
Can someone tell with what method i can change this things
Thanks a lot for helping
Christian

for all intrestet Users, i solved it that way:
declarePrefix("v1", NAMESPACE);
declarePrefix("soapenc", "soapenc");
getBody().addTextNode(null, METHOD_NAME, "?");
XMLParentNode security = new XMLParentNodeImpl(null, "wsse:Security");
security.declarePrefix("wsse", HEADER_NAMESPACE);
security.addAttribute(HEADER_NAMESPACE,"mustUnderstand", "1");
XMLParentNode usernameToken = new XMLParentNodeImpl(null, "wsse:UsernameToken");
usernameToken.declarePrefix("wsu", UNT_NAMESPACE);
usernameToken.addAttribute(null, "wsu:Id", "UsernameToken-27777511");
usernameToken.addTextNode(null, "wsse:Username", Constants.OC_Username);
usernameToken.addTextNode(null, "wsse:Password", Constants.OC_PASSWORD);
security.addElement(usernameToken);
getHeader().addElement(security);
the results not 100% simular to my outgoing code, but the request are working :)

Related

How to customize Axis Security Header for the following XML using Stub

I am trying to automate the xml web services using Apache Axis Java API and I have generated the stubs. But my Below XML has header part which i need to customize manually using stub.
So I have used SOAPHeaderElement from stub class and designed the code. But I am getting extra namespace like xmlns:wsse="" in each node and soapenv: in header node.
So, please modify my code to get the exact format(Expected) as given below
Below is the XML Header Part:
<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:Header>
<wsse:Header mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>InternalServiceUser</wsse:Username>
<wsse:Password>123456</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</wsse:Header>
</soapenv:Header>
Below is the code:
SOAPHeaderElement wsseHeader = new SOAPHeaderElement(new PrefixedQName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Header", "wsse"));
String nullString = null;
MessageElement Security = new MessageElement(nullString, "wsse:Security");
MessageElement usernameToken = new MessageElement(nullString, "wsse:UsernameToken");
MessageElement username = new MessageElement(nullString, "wsse:Username");
MessageElement password = new MessageElement(nullString, "wsse:Password");
username.setObjectValue("InternalServiceUser");
usernameToken.addChild(username);
password.setObjectValue("123456");
usernameToken.addChild(password);
Security.addChild(usernameToken);
wsseHeader.addChild(Security);
wsseHeader.setActor(null);
wsseHeader.setMustUnderstand(true);
_call.addHeader(wsseHeader);
Expected Request XML Header part:
<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:Header>
<wsse:Header mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Security mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>InternalServiceUser</wsse:Username>
<wsse:Password>123456</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</wsse:Header>
</soapenv:Header>
Actual request XML header part which is generated after execution:
could not remove soapenv: in header tag and xmlns:wsse="" in Security, Username and password tags via code
<?xml version="1.0" encoding="UTF-8"?><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:Header>
<wsse:Header soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Security xmlns:wsse=""><wsse:UsernameToken xmlns:wsse="">
<wsse:Username xmlns:wsse="">InternalServiceUser</wsse:Username>
<wsse:Password xmlns:wsse="">123456</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</wsse:Header>
</soapenv:Header>

Send Soap Request in java with Authentication

I want to send a java soap req to a web service:
url: (https://webapplicaties.agro.nl/OpvragenPandEnergieLabel/EpbdOpvragenPandEnergieLabelService.asmx?WSDL)
This is the request:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:epb="http://schemas.ep-
online.nl/EpbdOpvragenPandEnergieLabelHeader"
xmlns:epb1="http://schemas.ep-
online.nl/EpbdOpvragenPandEnergieLabelRequest">
<soapenv:Header>
<epb:PandEnergieLabelHeader>
<epb:username>username</epb:username>
<epb:password>password</epb:password>
<epb:versienr>4</epb:versienr>
</epb:PandEnergieLabelHeader>
</soapenv:Header>
<soapenv:Body>
<epb1:GetPandEnergieLabel>
<epb1:Pand_postcode>postcode</epb1:Pand_postcode>
<epb1:Pand_huisnummer>housnr</epb1:Pand_huisnummer>
<epb1:Pand_huisnummer_toev>extra</epb1:Pand_huisnummer_toev>
</epb1:GetPandEnergieLabel>
</soapenv:Body>
</soapenv:Envelope>
and the response should be like this.
Which steps should I take to have a such a response?
<?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>
<PandEnergieLabel xmlns="http://schemas.ep-online.nl/EpbdExportTypes">
<Pand_gebouwklasse>W</Pand_gebouwklasse>
<Pand_is_op_basis_van_referentie_gebouw>false</Pand_is_op_basis_van_referentie_gebouw>
<Pand_opnamedatum>29-04-2011</Pand_opnamedatum>
<Pand_berekeningstype>EP</Pand_berekeningstype>
<Pand_energieprestatieindex>1.21</Pand_energieprestatieindex>
<Pand_energieklasse>B</Pand_energieklasse>
<Pand_energielabel_is_prive>false</Pand_energielabel_is_prive>
<Pand_forfaitaire>1.21</Pand_forfaitaire>
<Meting_geldig_tot>29-04-2021</Meting_geldig_tot>
<Pand_registratiedatum>29-04-2011</Pand_registratiedatum>
<Pand_postcode>1072XC</Pand_postcode>
<Pand_huisnummer>79</Pand_huisnummer>
<Pand_huisnummer_toev>A</Pand_huisnummer_toev>
<Pand_gebouwcode />
<Pand_gebouwtype>Portiekwoning</Pand_gebouwtype>
<Pand_gebouwsubtype>Tussenvloer</Pand_gebouwsubtype>
</PandEnergieLabel>
</soap:Body>
</soap:Envelope>
How should I use Variables inside the request to ask for multiple addresses (postcode, housnr, ...)
Thanks

wss4j doesn't see security header

I try to validate security header expiration using wss4j:
List<WSSecurityEngineResult> resultList = wsSecurityEngine.processSecurityHeader(doc,
"Actor", callbackHandler, crypto);
But wss4j doesn't see header content and result is null.
soap request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv: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"
soapenv:mustUnderstand="1">
<wsu:Timestamp wsu:Id="TS-CC2DD79172C7EFA866147066307733352">
<wsu:Created>2016-08-08T13:31:17.333Z</wsu:Created>
<wsu:Expires>2016-08-09T13:31:17.333Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
</soapenv:Body>
It doesn't throw any exception. Just security header is ignored. In debug it can find all ChildNodes (soapenv:Header, wsse:Security etc.)

How to remove the prefix to response element in web services

I am facing one weird issue in web services. Functionality is working fine,but the response have some unneccessary namespace to the response element, That prefix is not at all defined in the wsdl or stubs. How to remove the unneccessary prefixes in the response element, that namespace is not at all defined in the WSDL. Please help me out to resolve.
Output:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p30:realTimeWSProviderResponse xmlns:p30="http://eh.actimize.com">
<requestId/>
<searchDefinitionId/>
<generateAlert/>
Expected Output:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<RealTimeWSProviderResponse xmlns="http://eh.actimize.com">
<requestId xmlns=""/>
<searchDefinitionId xmlns=""/>
<generateAlert xmlns=""/>
<enableSuppression xmlns=""/>
<partyType xmlns=""/>
<partyKey xmlns=""/>
<names xmlns="">

How to add namespace in a SOAP envelope using axis with Java

I'm working on a web service project, where I need to alter the default namespace of a soap envelope. I am using axis-1.4. The following is the generated SOAP envelope.
<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>
<v1:addClaimRequest xmlns="">
<v1:ClaimsAddRq xsi:type="xsd:string"><ifx:RqUID>004030000075</ifx:RqUID>
</v1:ClaimsAddRq>
</v1:addClaimRequest>
</soapenv:Body>
</soapenv:Envelope>
Following is my Java code:
_call.setUseSOAPAction(true);
_call.setSOAPActionURI("v1");
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new QName("xmlns:v1=urn://shivamath.com/prodschnsmngt/v1/","v1:addClaimRequest"));
_call.addParameter("v1:ClaimsAddRq",org.apache.axis.Constants.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
_call.setTargetEndpointAddress(locator);
_call.setEncodingStyle("");
setRequestHeaders(_call);
setAttachments(_call);
Following is the expected namespace to generate:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="urn://grupoaval.com/prodschnsmngt/v1/"
xmlns:ifx="urn://grupoaval.com/xsd/ifx/">
<soapenv:Body>
<v1:addClaimRequest xmlns="">
<v1:ClaimsAddRq xsi:type="xsd:string"><ifx:RqUID>004030000075</ifx:RqUID>
</v1:ClaimsAddRq>
</v1:addClaimRequest>
</soapenv:Body>
Please guide me out of this problem.

Categories

Resources