Error - org.xml.sax.SAXParseException; systemId: http://schemas.xmlsoap.org/soap/envelope/; lineNumber: 1; columnNumber: 1; Premature end of file - rest-assured

I am getting an error as org.xml.sax.SAXParseException; systemId: http://schemas.xmlsoap.org/soap/envelope/; lineNumber: 1; columnNumber: 1; Premature end of file.
while running a matcher clause in xsd validation in rest assured
The request and the response is successful and getting a status code as 200. But when performing the action as body(matchesXsdInClasspath("addinteger.xsd")); it is showing the above error message.
Not being able to resolve the error.
My Code -
package soap_request.get_request;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
import java.io.File;
import java.io.FileInputStream;
import org.apache.commons.io.IOUtils;
import org.testng.annotations.Test;
import io.restassured.http.ContentType;
import static io.restassured.matcher.RestAssuredMatchers.matchesXsdInClasspath;
import static org.hamcrest.Matchers.equalTo;
public class get_request {
#Test
public void getListOfUsers() throws Exception {
File xmlFile = new File("C:\\Users\\das_k\\Downloads\\addinteger.xml");
if (xmlFile.exists()) {
FileInputStream oFIS = new FileInputStream(xmlFile);
String requestBody = IOUtils.toString(oFIS,"UTF-8");
oFIS.close();
baseURI = "http://dneonline.com/";
given().
contentType("text/xml").
accept(ContentType.XML).
body(requestBody).
when().
post("calculator.asmx").
then().
statusCode(200).
log().all().
and().
body("//*:AddResult.text()", equalTo("24")).
and().
body(matchesXsdInClasspath("addinteger.xsd"));
} else {
throw new Exception("The xml file specified does not exist");
}
}
}
My response -
<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>
<AddResponse xmlns="http://tempuri.org/">
<AddResult>24</AddResult>
</AddResponse>
</soap:Body>
</soap:Envelope>
xsd file -
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
targetNamespace="http://tempuri.org/">
<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
<xs:element name="AddIntegerResponse">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="AddIntegerResult"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Related

Where can i find a list of error in SONOS documentation? error 1028 from SOAP response

in a soap call to add songs to a saved queue (AddURIToSavedQueue) in SONOS, I receive a response with error 1028 but I can't figure out what the problem is, could you tell me in the documentation where I can find the list of errors?
my call body
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:AddURIToSavedQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
<ObjectID>SQ:19</ObjectID>
<UpdateID></UpdateID>
<EnqueuedURI>https://xxx.it/xxx/xx-001.mp3</EnqueuedURI>
<EnqueuedURIMetaData></EnqueuedURIMetaData>
<AddAtIndex>0</AddAtIndex>
</u:AddURIToSavedQueue>
</s:Body>
</s:Envelope>
my response
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
<errorCode>1028</errorCode>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
this is my code in flutter (Dart)
addURI() async {
var playlist = await Player().getDataFromPl();
var brani = playlist['lista']['brano'];
for (var brano in brani) {
final localizedDt = tz.TZDateTime.from(DateTime.now(), rome);
String formattedTime = DateFormat('HH:mm:ss').format(localizedDt);
print('SONOS: $formattedTime');
if (brano['ora'].compareTo(formattedTime) > 0) {
final String soapEnvelope = """
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:AddURIToSavedQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
<ObjectID>$queueID</ObjectID>
<UpdateID></UpdateID>
<EnqueuedURI>https://xxx.xxx.it/${brano['nome']}</EnqueuedURI>
<EnqueuedURIMetaData></EnqueuedURIMetaData>
<AddAtIndex>${brani.indexOf(brano)}</AddAtIndex>
</u:AddURIToSavedQueue>
</s:Body>
</s:Envelope>
""";
final sonosUri =
Uri.parse('http://$ipAddress/MediaRenderer/AVTransport/Control');
final response = await http.post(
sonosUri,
headers: {
'Content-Type': 'application/xml',
'soapaction':
'urn:schemas-upnp-org:service:AVTransport:1#AddURIToSavedQueue'
},
body: soapEnvelope,
);
}
}
stopSonos();
playSonos();
}

Flutter SOAP: How to using SOAP in Flutter?

How to using SOAP Api calls in Flutter? I have tried rest calls is working fine. I need to build SOAP calls in flutter. Kindly share how to call SOAP in flutter
refer this link sucessfully call SOAP https://dartpad.dartlang.org/2561dd3579e45d1eb730
void functionCall() async {
var envelope = '''
<?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>
<GetAllCity xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
''';
http.Response response = await http.post(
'http://www.i2isoftwares.com/SSKSService/sskss.asmx',
headers: {
"Content-Type": "text/xml; charset=utf-8",
"SOAPAction": "http://tempuri.org/GetAllCity",
"Host": "www.i2isoftwares.com"
//"Accept": "text/xml"
},
body: envelope);
var rawXmlResponse = response.body;
// Use the xml package's 'parse' method to parse the response.
xml.XmlDocument parsedXml = xml.parse(rawXmlResponse);
print("DATAResult=" + response.body);
}

Parse using XMLDictionary

I am using 'XMLDictionary' to parse xml. In one case I am getting the following dictionary(after converting NSData response to NSDictionary using 'dictionaryWithXMLData')
{
"__name" = "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" = {
GetPublicationsListResponse = {
GetPublicationsListResult = 0;
"_xmlns" = "http://questbase.org/";
publicationsList = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<publications>\n <publication>\n <pin>4533-1490-8280</pin>\n <title>Unsecure Assessment</title>\n <isSecure>0</isSecure>\n </publication>\n <publication>\n <pin>5123-4751-0595</pin>\n <title>Secure Assessment</title>\n <isSecure>1</isSecure>\n </publication>\n</publications>";
studentID = "4795e7fc-5c98-4ec4-a155-5f719f14ef3e";
};
};
}
Here, object for key publicationList is in xml and I am stuck trying to convert it into NSDictionary. Plz help.
Original xml request made was in the form:
<?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:Header>
<SecurityHeader xmlns="http://questbase.org/">
<Password>string</Password>
</SecurityHeader>
</soap:Header>
<soap:Body>
<GetPublicationsList xmlns="http://questbase.org/">
<accountName>string</accountName>
<userName>string</userName>
<password>string</password>
<ipAddress>string</ipAddress>
<userAgent>string</userAgent>
</GetPublicationsList>
</soap:Body>
</soap:Envelope>
and the response is as follows:
<?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>
<GetPublicationsListResponse xmlns="http://questbase.org/">
<GetPublicationsListResult>int</GetPublicationsListResult>
<studentID>guid</studentID>
<publicationsList>string</publicationsList>
</GetPublicationsListResponse>
</soap:Body>
</soap:Envelope>

SOAP REQUEST USING Ruby without using any gem

http = Net::HTTP.new('rty.makemytrip.com', 80)
http.use_ssl = false
path="http://rty.makemytrip.com/btd_Webs_CreateIncident/MMT_Webs_CreateIncident.asmx?op=CreateIncident"
# Create the SOAP Envelope
data = <<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<CreateIncident xmlns="http://MakeMyTrip.org/">
<FirstName>#{params[:name]}</FirstName>
<Email>#{params[:email]}</Email>
<CityOfResidence>#{params[:city]}</CityOfResidence>
<MobilePhone>#{params[:mobile]}</MobilePhone>
</CreateIncident>
</SOAP:Body>
</SOAP-ENV:Envelope>
EOF
# Set Headers
headers = {
'Content-Type' => 'Content-Type: application/soap+xml; charset=utf-8'
}
# Post the request
resp, data = http.post(path, data, headers)
# Output the results
logger.error "code = >>>>>>>>#{resp.code}"
logger.error "Response message = >>>>>>>>Message =#{resp.message}"
resp.each { |key, val|
logger.error "key>#{key}>>>>>#{val}"
}
logger.error "data>>>>>#{ data}"
it gives us this error
code = >>>>>>>>500
Response message = >>>>>>>>Message =Internal Server Error
key>x-powered-by>>>>>ASP.NET
key>x-aspnet-version>>>>>2.0.50727
key>connection>>>>>close
key>content-type>>>>>text/xml; charset=utf-8
key>date>>>>>Thu, 19 Sep 2013 08:35:13 GMT
key>server>>>>>Microsoft-IIS/7.5
key>content-length>>>>>442
key>cache-control>>>>>private
data>>>>>
<?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>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---> 'SOAP' is an undeclared namespace. Line 8, position 5.</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
what is wrong in this code
The error is 'SOAP' is an undeclared namespace. Line 8, position 5. It complains on this string <SOAP:Body> in your request, because namespace SOAP wasn't declared.
So, you declared SOAP-ENV as namespace for http://schemas.xmlsoap.org/soap/envelope/ and I think it should be changed to <SOAP-ENV:Body>. And don't forget to change </SOAP:Body> to </SOAP-ENV:Body> too.

Creating soap request with http build

Im trying to make a soap request using httpbuilder. I need to pass some authentication parameters in the head section.
My code is as follows
def String WSDL_URL = 'http://ws.tradetracker.com/soap/affiliate?wsdl'
def http = new HTTPBuilder( WSDL_URL , ContentType.TEXT )
String soapEnvelope =
"""<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap-env:Header>
<authenticate>
<customerID>id</customerID>
<passphrase>pass</passphrase>
<demo>true</demo>
</authenticate>
</soap-env:Header>
<soap12:Body>
<getConversionTransactions xmlns="xmlns':'http://schemas.xmlsoap.org/wsdl">
<affiliateSiteID>id</affiliateSiteID>
</getConversionTransactions>
</soap12:Body>
</soap12:Envelope>"""
http.request( Method.POST, ContentType.TEXT ) {
body = soapEnvelope
response.success = { resp, xml ->
String xm = xml.readLines()
println "XML was ${xm}"
def territories = new XmlSlurper().parseText(
'<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:http://ws.webgains.com/aws.php" xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"><ns1:getFullUpdatedEarningsResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><rpc:result>return</rpc:result><return enc:itemType="ns1:fullLinesArray" enc:arraySize="1" xsi:type="ns1:fullReportArray"><item xsi:type="ns1:fullLinesArray"><transactionID xsi:type="xsd:int">39367137</transactionID><affiliateID xsi:type="xsd:int">59987</affiliateID><campaignName xsi:type="xsd:string">www.tikcode.com</campaignName><campaignID xsi:type="xsd:int">136755</campaignID><date xsi:type="xsd:dateTime">2013-05-13T15:04:48</date><validationDate xsi:type="xsd:dateTime">2013-05-13T15:04:48</validationDate><delayedUntilDate xsi:type="xsd:string"></delayedUntilDate><programName xsi:type="xsd:string">Miniinthebox - US</programName><programID xsi:type="xsd:int">4611</programID><linkID xsi:type="xsd:string">95661</linkID><eventID xsi:type="xsd:int">7285</eventID><commission xsi:type="xsd:float">0.06</commission><saleValue xsi:type="xsd:float">0.8</saleValue><status xsi:type="xsd:string">confirmed</status><paymentStatus xsi:type="xsd:string">notcleared</paymentStatus><changeReason xsi:nil="true"/><clickRef xsi:nil="true"/><clickthroughTime xsi:type="xsd:dateTime">2013-05-13T14:58:33</clickthroughTime><landingPage xsi:type="xsd:string">http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgains</landingPage><country xsi:type="xsd:string">ES</country><referrer xsi:type="xsd:string">http%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D</referrer></item></return></ns1:getFullUpdatedEarningsResponse></env:Body></env:Envelope>').declareNamespace("ns1":"http://ws.webgains.com/aws.php")
println "aaaaaaaaaaaaaaaa"+ territories.Body.getFullUpdatedEarningsResponse.return.item.transactionID
}
response.failure = { resp, xml ->
println "pues peto, no se porque"+xml.readLines()
}
}
Im getting the following error and I dont have any clue wants wrong
<?xml version="1.0" encoding="UTF-8"?>, <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Body><env:Fault><env:Code><env:Value>env:Sender</env:Value></env:Code><env:Reason><env:Text>Body must be present in a SOAP envelope</env:Text></env:Reason></env:Fault></env:Body></env:Envelope>
Namespace for Envelope and its corresponding Header element is mismatching.
<soap12:Envelope> should have <soap12:Header> instead you have <soap-env:Header>. The payload becomes invalid in the header element so body becomes unreachable.
Like #dmahapatro said you have a problem in your XML. Anyway checking your code I've noted that you are using HTTPBuilder directly. Maybe you can try to use groovy-wslite (https://github.com/jwagenleitner/groovy-wslite) to make SOAP requests. It's very simple to call and process the response. There is a plugin for Grails, despite I'm not using the plugin, but the groovy-wslite directly.
BuildConfig.groovy
dependencies {
compile 'com.github.groovy-wslite:groovy-wslite:0.7.2'
runtime 'com.github.groovy-wslite:groovy-wslite:0.7.2'
}
In a Grails Service for instance:
def cnpj = "999999999906"
def clientSOAP = new SOAPClient('https://www.soawebservices.com.br/webservices/producao/cdc/cdc.asmx')
def response = clientSOAP.send (SOAPVersion.V1_2,
"""<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<PessoaJuridicaNFe xmlns="SOAWebServices">
<Credenciais>
<Email>xxxxx</Email>
<Senha>xxxxx</Senha>
</Credenciais>
<Documento>${cnpj}</Documento>
</PessoaJuridicaNFe>
</soap12:Body>
</soap12:Envelope>"""
)
//processing the response (very simple...)
Client client = new Client()
client.webServiceMsg = response.PessoaJuridicaNFeResponse.PessoaJuridicaNFeResult.Mensagem.text()
client.nome = response.PessoaJuridicaNFeResponse.PessoaJuridicaNFeResult.RazaoSocial.text()
//etc...

Resources