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", "")
Related
Below is my sample SOAP response.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns4:createReservationResponse xmlns:ns2="http://www.xyz2.com/documentation/createEnvironment/input" xmlns:ns3="http://webservices.xyz.com/documentation/reservations/createReservation/output" xmlns:ns4="http://webservices.xyz.com/documentation/reservations/createReservation/input" xmlns:ns5="http://webservices.xyz.com/documentation/reservations/cancelReservation/input" xmlns:ns6="http://webservices.xyz.com/documentation/reservations/cancelReservation/output">
<return>
<!-- response data -->
</return>
</ns4:createReservationResponse>
</soap:Body>
</soap:Envelope>
How do i remove unwanted namespaces here in my case xmlns:ns2, xmlns:ns4, xmlns:ns5 and xmlns:ns6. I should only keep xmlns:ns3 in the response.
What should i change in my wsdl so that i can get the expected response as below.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns4:createReservationResponse xmlns:ns3="http://webservices.xyz.com/documentation/reservations/createReservation/output">
<return>
<!-- response data -->
</return>
</ns4:createReservationResponse>
</soap:Body>
</soap:Envelope>
Please help me out from this.
Thanks in adv.
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
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"/>
I'm trying to add a role using the WSO2 GReg admin service addRole using SoapUI. Unfortunately I get an error.
Using the following request I get the error "java.lang.ArrayIndexOutOfBoundsException: 3":
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mgt="http://mgt.user.carbon.wso2.org">
<soap:Header/>
<soap:Body>
<mgt:addRole>
<!--Optional:-->
<mgt:addRole>test</mgt:addRole>
</mgt:addRole>
</soap:Body>
</soap:Envelope>
Using the following request I get the error "Role name not valid. Role name must be a non null string with following format, ^[^~!#$;%^*+={}\|\\<>,\'\"]{3,30}$":
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mgt="http://mgt.user.carbon.wso2.org">
<soap:Header/>
<soap:Body>
<!--Optional:-->
<mgt:addRole>test</mgt:addRole>
</soap:Body>
</soap:Envelope>
Any idea's what I'm doing wrong?
Regards, nidkil
Can you try with the following Envelope?
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mgt="http://mgt.user.carbon.wso2.org">
<soap:Header/>
<soap:Body>
<mgt:addRole>
<mgt:roleName>test</mgt:roleName>
</mgt:addRole>
</soap:Body>
</soap:Envelope>
I'm sending the following:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<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>
<GetList xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">
<listName>{5DB680A5-EFCB-4F48-AC80-835AFBCE9FDA}</listName>
</GetList>
</soap:Body>
</soap:Envelope>
but am getting back results for GetListCollection
<?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><GetListCollectionResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListCollectionResult>...
am I doing something wrong?