Mule http request returns complete soap message - web-services

Below http:outbound-endpoint returns the expected response as CDATA but when i change it to http:request it returns the whole SOAP message instead of just CDATA. I don't want to write any custom code to extract the CDATA.
Any help is appreciated!
Flow works with http:outbound-endpoint:
<flow name="Client">
<logger message="REQUEST : #[payload]" level="WARN"/>
<http:outbound-endpoint exchange-pattern="request-response" address="http://server:8080/RoomStatusService/webservices.asmx" >
<cxf:jaxws-client clientClass="com.test.webservices.WebServices" operation="UpdateRoomStatus" port="WebServicesSoap" />
</http:outbound-endpoint>
<logger message="RESPONSE : #[payload]" level="WARN"/>
</flow>
Expected Response:
REQUEST : <?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><InspBy>AUTO</InspBy><RoomNumber>402</RoomNumber><RoomStatus>3</RoomStatus><Wing>ST</Wing></RoomStatusDetail>
RESPONSE : <UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult>
Flow doesn't work with http:request:
<http:request-config name="CONFIG" host="server" port="8080" doc:name="HTTP Request Configuration"/>
<flow name="Client">
<logger message="REQUEST : #[payload]" level="WARN"/>
<cxf:jaxws-client clientClass="com.test.webservices.WebServices" operation="UpdateRoomStatus" port="WebServicesSoap" />
<http:request config-ref="CONFIG" path="RoomStatusService/webservices.asmx" method="POST" doc:name="HTTP" >
<http:success-status-code-validator values="0..599"/>
</http:request>
<logger message="RESPONSE : #[payload]" level="WARN"/>
</flow>
Incorrect Response:
REQUEST : <?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><InspBy>AUTO</InspBy><RoomNumber>402</RoomNumber><RoomStatus>3</RoomStatus><Wing>ST</Wing></RoomStatusDetail>
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><UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/"><UpdateRoomStatusResult><UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult></UpdateRoomStatusResult></UpdateRoomStatusResponse></soap:Body></soap:Envelope>
Sample Request & Response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://testsoftware.com/webservices/">
<soapenv:Header/>
<soapenv:Body>
<web:UpdateRoomStatus>
<web:UpdateRoomStatusRequest><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><Wing>ET</Wing><RoomNumber>50102</RoomNumber><RoomStatus>1</RoomStatus><InspBy>test</InspBy></RoomStatusDetail>]]></web:UpdateRoomStatusRequest>
</web:UpdateRoomStatus>
</soapenv:Body>
</soapenv:Envelope>
<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>
<UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/">
<UpdateRoomStatusResult><UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult></UpdateRoomStatusResult>
</UpdateRoomStatusResponse>
</soap:Body>
</soap:Envelope>

http:outbound is not doing anything but it is the tag which removes the SOAP envelope around the response. If you are consuming SOAP web service, better use Web service consumer.

You can use replace function to remove soap envelope like as below.Once you receive the payload ,use Set payload :
#[message.payloadAs(String).replace('<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>
<UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/">','')]
and again use replace function to remove end part of Soap envelope and then pretty print the response
<mulexml:xml-prettyprinter-transformer xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" newlines="false" indentEnabled="false" padText="false" trimText="true"/>

Related

Error reading XMLStreamReader by django request

My xml data:
xml_payload =
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Authentication >
<username>blabla</username>
<password>123456789</password>
</Authentication>
</soap:Header>
<soap:Body>
<data>
<title>Test title</title>
<content>Test body format</content>
</data>
</soap:Body>
</soap:Envelope>
My request in django project:
try:
url = "http://someurls.com"
res = requests.post(url=url, data=xml_payload, headers={'Content-type': 'application/xml'})
return response.content, response.status_code
except Exception as e:
print(e)
return None, 500
When i hit the request using postman then i get response is given bellow:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Error reading XMLStreamReader.</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>'
It returns an error. I am surfing around the internet but didn't find any answer which is fulfilled my query.
Try to pass the xml payload as follows:
xml_payload = """<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Authentication >
<username>blabla</username>
<password>123456789</password>
</Authentication>
</soap:Header>
<soap:Body>
<data>
<title>Test title</title>
<content>Test body format</content>
</data>
</soap:Body>
</soap:Envelope>"""
Afterd days, i finally found the answer. When i create a xml payload by python then python invisibly add "\n" at the end of every line. So when i replaced those "\n" then i works perfectly.
xml_payload = xml_payload.replace("\n", "")

Building SOAP request from WSDL

I need to execute a SOAP request to an external server. I have never worked with SOAP before, but I know the basics of REST.
I've been given this following WSDL file and this example query:
<Messages>
<Version Ds_Version="0.0">
<Message>
<Detail>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Detail>
</Message>
</Version>
<Signature>UfECD0KD9Wwo1iqY6PYZoJxw8KwMUz8m18bgLyH3BCI=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
I'm using Postman in order to test the API. Following some instructions I found on the internet, I added a Content-Type HTTP header with value text/xml and the SOAPAction HTTP header with value consultaOperaciones as found in the WSDL file.
I've set this body:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body xmlns:m="http://webservices.apl02.redsys.es">
<m:consultaOperacionesRequest>
<Messages>
<Version Ds_Version="0.0">
<Message>
<Transaction>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Transaction>
</Message>
</Version>
<Signature>1KoxTgTakbTprzJ2N/e9JJ8yw/C3QzeNafbUMCNGSFM=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
</m:consultaOperacionesRequest>
</soap:Body>
</soap:Envelope>
However, when I send the request I receive the following error message:
<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>
<soapenv:Fault>
<faultcode>Server</faultcode>
<faultstring>Internal Error</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
It's a generic SOAP error message, therefore I think that the problem has to be related to the codification instead of the external service.
Thanks in advance.
In the WSDL file you will see that the XML should be sent as a string:
<element name="consultaOperaciones">
<complexType>
<sequence>
<element name="cadenaXML" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
Hence the XML sent should be:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.apl02.redsys.es">
<soapenv:Header/>
<soapenv:Body>
<web:consultaOperaciones>
<cadenaXML><![CDATA[
<Messages>
<Version Ds_Version="0.0">
<Message>
<Detail>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Detail>
</Message>
</Version>
<Signature>UfECD0KD9Wwo1iqY6PYZoJxw8KwMUz8m18bgLyH3BCI=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
]]>
</cadenaXML>
</web:consultaOperaciones>
</soapenv:Body>
</soapenv:Envelope>
Note that we are using CDATA because as mentioned the XML message should be sent as a string based on the WSDL. I have tried running it and got the response:
<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>
<p259:consultaOperacionesResponse xmlns:p259="http://webservices.apl02.redsys.es">
<consultaOperacionesReturn><![CDATA[<Messages><Version Ds_Version="0.0"><Message><ErrorMsg><Ds_ErrorCode>XML0023</Ds_ErrorCode></ErrorMsg></Message></Version></Messages>]]></consultaOperacionesReturn>
</p259:consultaOperacionesResponse>
</soapenv:Body>
</soapenv:Envelope>
This means that your message is being parsed now because there are no server errors and a consultaOperacionesResponse is being sent which looks legit. The error seems to be related to the data being sent but in general the API is working fine as expected.

Amadeus Cancel PNR XML returning empty response

I have been trying to cancel reservation on Amadeus and each time I do that with a valid PNR, it returns an empty response. Below is the sample code
cancelPNR Request XML
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<wmPNRCancel xmlns="http://traveltalk.com/wsPNRCancel">
<OTA_CancelRQ>
<POS>
<Source PseudoCityCode="*******" ISOCurrency="NGN">
<RequestorID Type="21" ID="********"/>
</Source>
<TPA_Extensions>
<Provider>
<Name>Amadeus</Name>
<System>Test</System>
<Userid>******</Userid>
<Password>**********</Password>
</Provider>
</TPA_Extensions>
</POS>
<UniqueID ID="******"/>
</OTA_CancelRQ>
</wmPNRCancel>
</soap:Body>
</soap:Envelope>
cancelPNR 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>
<wmPNRCancelResponse xmlns="http://traveltalk.com/wsPNRCancel" />
</soap:Body>
</soap:Envelope>
What could be wrong ? Please I need help

Apache CXF:The message has expired

Environment :
Apache CXF 2.7.8
Jboss EAP 6
SoapUI for testing client Side
I tried to implement for simple authentication i.e with password simple text type, it is working but when i tried to implement for password digest type ,then giving me exception:
unwinding now: org.apache.cxf.binding.soap.SoapFault: The message has
expired org.apache.ws.security.WSSecurityException: The message has
expired
I am giving new nonce value for each request and time within five min diff
WSS4JInInterceptor Bean class defination:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="orderProcess" implementor="demo.order.OrderProcessImpl" address="/OrderProcess" >
<jaxws:inInterceptors>
<bean
class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken"/>
<entry key="passwordType" value="PasswordDigest"/>
<entry key="passwordCallbackRef" value-ref="myPasswordCallback"/>
</map>
</constructor-arg>
</bean>
</jaxws:inInterceptors>
</jaxws:endpoint>
<bean id="myPasswordCallback" class="service.ServerPasswordCallback" />
</beans>
Client xml request Code:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ord="http://order.demo/"
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:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>joe</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">PE7F51/oyWFVMsiZURuUwjoZVPY=</wsse:Password>
<!--<wsu:Created>2013-12-17T13:12:00.429Z</wsu:Created>-->
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">efPSkfHXTM6NFDDD1CJHsw==</wsse:Nonce>
<wsu:Created>2013-12-23T12:17:15Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ord:processOrder>
<!--Optional:-->
<arg0>
<!--Optional:-->
<customerID>234</customerID>
<!--Optional:-->
<itemID>0908923</itemID>
<price>23423</price>
<qty>1000</qty>
</arg0>
</ord:processOrder>
</soapenv:Body>
</soapenv:Envelope>
When i tried to call the service i am getting exception as
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">ns1:MessageExpired</faultcode>
<faultstring>The message has expired</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Can any one tell me where i am making mistake?
I suspect this is a bug in earlier version of wss4j. If you are parsing the date using SimpleDateFormat, you might want to set the time zone to UTC (Zulu time).
sdf.setTimeZone("UTC");
This however has been fixed in 2.0-beta.
http://grepcode.com/file/repo1.maven.org/maven2/org.apache.wss4j/wss4j-ws-security-dom/2.0-beta/org/apache/wss4j/dom/message/token/UsernameToken.java#226
Edit: This is not a bug in wss4j. The specification states that the time zone must be in UTC.

How to add prefix to namespace declaration in axis wsdd file?

Axis 1.4 based webservice.
The client sends following request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://org.mysite.services/service/np">
<SOAP-ENV:Body>
<ABC:createAction>
<ABC:resourceID>MyResource</ABC:resourceID>
</ABC:createAction>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Error :
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXParseException: The prefix ”ABC” for element
“ABC:createAction” is not bound.
</faultstring>
server-config.wsdd has following configuration :
<service name="MyService" provider="java:RPC" style="wrapped" use="literal">
<namespace>http://webservices.mysite.org</namespace>
UPDATE:
How the proper client request should look in this context ?