Moodle: Invalid parameter exception - moodle

I'm trying to make a
http://domain.com/webservice/rest/server.php?wstoken=4725a345345435342322a6560b068547297748e17&wsfunction=mod_forum_get_forum_discussions_paginated
with post data:
{
"forumid":2438
}
Headers:
Accept: application/json
Content-Type: application/json
But I get the error:
<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="invalid_parameter_exception">
<ERRORCODE>invalidparameter</ERRORCODE>
<MESSAGE>Invalid parameter value detected</MESSAGE>
</EXCEPTION>
I have my moodle session as a cookie. What am I doing wrong here?

Maybe try putting forumid in the url?
http://domain.com/webservice/rest/server.php?forumid=2438&wstoken=4725a345345435342322a6560b068547297748e17&wsfunction=mod_forum_get_forum_discussions_paginated
https://tracker.moodle.org/browse/MDL-46458

Related

MTOM - Unexpected EOF in prolog at [row,col {unknown-source}]: [1,0]

I'm trying to send multipart/related request through postman. But I'm getting error:
<soap:Reason>
<soap:Text xml:lang="en">Unexpected EOF in prolog
at [row,col {unknown-source}]: [1,0]</soap:Text>
</soap:Reason>
Endpoint: POST https://sdummy.test.net/enterprise/soap?ServiceName=IntegrationManagementService
Headers I'm using:
Content-Type:multipart/related; start="<rootpart*7661941e-06d9-4961-af10-db612c7ffcc4#example.jaxws.sun.com>"; type="application/xop+xml"; boundary="uuid:7661941e-06d9-4961-af10-db612c7ffcc4"; start-info="text/xml"
Soapaction:http://www.taleo.com/ws/integration/toolkit/2011/05/management/IntegrationManagementService#submitLargeDocument
Accept:text/xml, multipart/related, text/html, image/gif, image/jpeg, *;q=.2, */*; q=.2
User-Agent:Oracle JAX-WS 2.1.5
Transfer-Encoding:chunked
Host:sdummy.test.net
Payload:
--uuid:7661941e-06d9-4961-af10-db612c7ffcc4
Content-Id: <rootpart*7661941e-06d9-4961-af10-db612c7ffcc4#example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/03/addressing" xmlns:tns="http://www.taleo.com/ws/integration/toolkit/2011/05/management">
<SOAP-ENV:Header>
<wsa:MessageID>ps_sd_7701</wsa:MessageID>
<wsa:Action>http://www.taleo.com/ws/integration/toolkit/2005/07/action/import</wsa:Action>
<wsa:ReplyTo>
<wsa:Address>http://www.taleo.com/ws/integration/toolkit/2005/07/addressing/queue</wsa:Address>
</wsa:ReplyTo>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<wsa:submitLargeDocument>
<wsa:Document>
<Include xmlns="http://www.w3.org/2004/08/xop/include" href="cid:51349b7a-562a-4e98-ab8c-736cfecb03eb#example.jaxws.sun.com"/>
</wsa:Document>
</wsa:submitLargeDocument>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--uuid:7661941e-06d9-4961-af10-db612c7ffcc4
Content-Id:<51349b7a-562a-4e98-ab8c-736cfecb03eb#example.jaxws.sun.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: binary
<ImportEntities>
<Candidate>
<EmailAddress>test11#mailinator.com</EmailAddress>
</Candidate>
</ImportEntities>
--uuid:7661941e-06d9-4961-af10-db612c7ffcc4--
Postman Generated cURL command:
curl --location --request POST 'https://stghilton.taleo.net/enterprise/soap?ServiceName=IntegrationManagementService' \
--header 'Content-Type: multipart/related; start="<rootpart*7661941e-06d9-4961-af10-db612c7ffcc4#example.jaxws.sun.com>"; type="application/xop+xml"; boundary="uuid:7661941e-06d9-4961-af10-db612c7ffcc4"; start-info="text/xml"' \
--header 'Soapaction: http://www.taleo.com/ws/integration/toolkit/2011/05/management/IntegrationManagementService#submitLargeDocument' \
--header 'Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *;q=.2, */*; q=.2' \
--header 'User-Agent: Oracle JAX-WS 2.1.5' \
--header 'Transfer-Encoding: chunked' \
--header 'Host: stghilton.taleo.net' \
--header 'Authorization: Basic UGhlbm9tOj80K2pTSlAz' \
--data-raw '--uuid:7661941e-06d9-4961-af10-db612c7ffcc4
Content-Id: <rootpart*7661941e-06d9-4961-af10-db612c7ffcc4#example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
<?xml version='\''1.0'\'' encoding='\''UTF-8'\''?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/03/addressing" xmlns:tns="http://www.taleo.com/ws/integration/toolkit/2011/05/management">
<SOAP-ENV:Header>
<wsa:MessageID>ps_sd_7701</wsa:MessageID>
<wsa:Action>http://www.taleo.com/ws/integration/toolkit/2005/07/action/import</wsa:Action>
<wsa:ReplyTo>
<wsa:Address>http://www.taleo.com/ws/integration/toolkit/2005/07/addressing/queue</wsa:Address>
</wsa:ReplyTo>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<wsa:submitLargeDocument>
<wsa:Document>
<Include xmlns="http://www.w3.org/2004/08/xop/include" href="cid:51349b7a-562a-4e98-ab8c-736cfecb03eb#example.jaxws.sun.com"/>
</wsa:Document>
</wsa:submitLargeDocument>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--uuid:7661941e-06d9-4961-af10-db612c7ffcc4
Content-Id:<51349b7a-562a-4e98-ab8c-736cfecb03eb#example.jaxws.sun.com>
Content-Type: text/xml; charset=ISO-8859-1
Content-Transfer-Encoding: binary
<ImportEntities>
<Candidate>
<EmailAddress>test11#mailinator.com</EmailAddress>
</Candidate>
</ImportEntities>
--uuid:7661941e-06d9-4961-af10-db612c7ffcc4--'
Can someone help me with this please?
From a purely technical point of view the only error I can see is your handling of the multipart structure.
More precisely, you need to skip a line (blank line) between the headers of each part and their body, e.g change the 3 lines :
Content-Id: <rootpart*7661941e-06d9-4961-af10-db612c7ffcc4#example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
<?xml version='\''1.0'\'' encoding='\''UTF-8'\''?>
To 4 lines :
Content-Id: <rootpart*7661941e-06d9-4961-af10-db612c7ffcc4#example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
<?xml version='\''1.0'\'' encoding='\''UTF-8'\''?>
At each part, e.g. also here :
Content-Transfer-Encoding: binary
<ImportEntities>
To
Content-Transfer-Encoding: binary
<ImportEntities>
It is mandatory in multipart content to split the header from the body by a blank line.

Postman test fails while parsing the xml soap response

I am using POSTMAN to send a SOAP request and below is my soapenv response received. I would like to test for the below value received in my postman test, but the post man test fails, could someone advise on what to do here ?
LicStatus
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:schemas.general.com.au:api:other">
<soapenv:Header xmlns:urn="urn:schemas.general.com.au:api:other" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<header xmlns:urn="urn:schemas.general.com.au:api:other" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/General/1.0/">
<msg-id>005056B9-3921-A1E9-A327-64509F7362DC</msg-id>
<messageoptions noreply="true"/>
</header>
</soapenv:Header>
<soapenv:Body>
<getSupplierDataResponse xmlns:urn="urn:schemas.general.com.au:api:other" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:schemas.general.com.au:api:other" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns6="http://schemas.cordys.com/default_005056B9-5D92-A1E9-904D-128C719CE2DD" xmlns:ns5="http://schemas.cordys.com/casemanagement/1.0" xmlns:ns4="http://schemas.XXTGGHG.org/2004/07/STRD.Models" xmlns:ns3="urn:schemas.general.com.au:canonical:technical:v1" xmlns:ns2="urn:schemas.general.com.au:api:other" xmlns:bpm="http://schemas.cordys.com/default" xmlns:sm="http://www.w3.org/2005/07/scxml" xmlns:instance="http://schemas.cordys.com/bpm/instance/1.0">
<CustomerData>
<DateLicenceExpires>28/01/2020</DateLicenceExpires>
<Demonstration_Method>Certification</Demonstration_Method>
<AuditLastAuditDate>05/03/2018</AuditLastAuditDate>
<AuditOutcome>Non Compliance</AuditOutcome>
<HeadOfficeRegion/>
<ScopeOfLicencing>YES</ScopeOfLicencing>
<LicStatus>Licensed</LicStatus>
</CustomerData>
<OperationResult xmlns="urn:schemas.general.com.au:canonical:technical:v1">
<Status>00</Status>
<StatusMessage>Success</StatusMessage>
</OperationResult>
</getSupplierDataResponse>
</soapenv:Body>
</soapenv:Envelope>
Below is the post man test:
pm.test('Verify the LicStatus', function() {
var responseJson = xml2Json(responseBody);
pm.expect(responseJson.results[0].LicStatus).to.eql("Licensed");
})
Try something like this:
pm.test('Verify the LicStatus', function() {
var xmlTree = xml2Json(responseBody);
var licenseStatus = xmlTree['soapenv:Envelope']['soapenv:Body'].getSupplierDataResponse.CustomerData.LicStatus;
pm.expect(licenseStatus).to.eql("Licensed");
})

Basic auth credentials using headers in soap on groovy

I'm trying to connect to WSDL server, which requires basic auth along with the body. I tried hitting with SOAPUI, and was able to do so. While working for the same in groovy and using wslite package for SOAP call, I'm getting error as "Password required".
I tried the tutorial on https://github.com/jwagenleitner/groovy-wslite, but the method described (in Usage block) didn't help.
I'm using groovy for this.
Below is the raw code from SOAP UI, with response 200OK
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:w="http://xmlns.oracle.com/Enterprise/Tools/schemas/W_CHKLST_CREATE_REQ.1">
<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" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-83C962CC24EAB67F1D15586306447678"><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:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">JLTdeK6Yg3D64+2qz5xnbA==</wsse:Nonce><wsu:Created>2019-05-23T16:57:24.767Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header>
<soapenv:Body>
<w:helloWorld/>
</soapenv:Body>
</soapenv:Envelope>
which results in a 200OK from SOAPUI
HTTP/1.1 200 OK
Date: Wed, 22 May 2019 21:54:12 GMT
Content-Type: text/xml; charset=UTF-8
Content-Length: 3570
My Groovy Code,
def client = new SOAPClient("URL of WSDL")
def response = client.send(SOAPAction: "someAction",
connectTimeout:10000,
readTimeout:20000,
useCaches:false,
followRedirects:false) {
version SOAPVersion.V1_2 // SOAPVersion.V1_1 is default
soapNamespacePrefix "soapenv" // "soap-env" is default
envelopeAttributes "xmlns:ns":"http://example.weather.org"
header {
security("xmlns:ns20":"http://SecurityOpenXSD"){
"ns20:Username"("username")
"ns20:Password"("password")
}
}
body {
"ns:helloWorld" {
}
}
}
which gives soap xml as
<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'
xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
<wsse:UsernameToken wsu:Id='UsernameToken-83C962CC24EAB67F1D15586299636605'>
<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:Nonce
EncodingType='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'>
JLTdeK6Yg3D64+2qz5xnbA==
</wsse:Nonce>
<wsu:Created>2019-05-23T10:07:52.913Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
But i get error as password required,
<?xml version="1.0" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<Code><Value>SOAP-ENV:Receiver</Value></Code>
<Reason><Text>null</Text></Reason>
<Detail><IBResponse type="error" xmlns=""><DefaultTitle> Error Response</DefaultTitle>
<StatusCode>20</StatusCode>
<DefaultMessage><![CDATA[User Password required]]></DefaultMessage>
</IBResponse></Detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

Invalid SOAPAction in ASP.net Storefront

What is the right SOAPAction for this request to ASPDotNetStoreFront?
< POST http://192.168.122.3/ASPDNSF0/ipx.asmx
User-Agent: libwww-perl/6.05
Content-Type: application/soap+xml; charset="utf-8"
SOAPAction: "http://www.aspdotnetstorefront.com/DoItUsernamePwd"
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap12:Body>
<DoitUsernamePwd xmlns="http://www.aspdotnetstorefront.com/">
<AuthenticationEmail>admin#aspdotnetstorefront.com</AuthenticationEmail>
<AuthenticationPassword>Admin$11</AuthenticationPassword>
<XMLInputRequestString>
<ASPDotNetStorefrontImport Version="7.1">
<Product action="Add">
<Name>my product name</Name>
<SKU>1234</SKU>
<Description><![CDATA[please
add some <b>data</b>]]></Description>
</Product>
</ASPDotNetStorefrontImport>
</XMLInputRequestString>
</DoitUsernamePwd>
</soap12:Body>
</soap12:Envelope>
> HTTP/1.1 500 Internal Server Error
Cache-Control: private
Date: Tue, 17 Sep 2013 22:34:31 GMT
Server: Microsoft-IIS/7.0
Content-Length: 1938
Content-Type: application/soap+xml; charset=utf-8
Client-Date: Tue, 17 Sep 2013 20:34:32 GMT
Client-Peer: 192.168.122.3:80
Client-Response-Num: 1
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 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"><env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"><wsa:Action>http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</wsa:Action><wsa:MessageID>urn:uuid:e8b22878-f37a-4362-8167-441ebab5be00</wsa:MessageID><wsa:RelatesTo>urn:uuid:18b7b7e3-7f65-4622-b093-a906a76b3aba</wsa:RelatesTo><wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To><wsse:Security><wsu:Timestamp wsu:Id="Timestamp-cd79b88a-3552-4d91-a8d7-d9e3cff73d73"><wsu:Created>2013-09-17T22:34:31Z</wsu:Created><wsu:Expires>2013-09-17T22:39:31Z</wsu:Expires></wsu:Timestamp></wsse:Security></env:Header><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action.
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at Microsoft.Web.Services3.WseProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
must be http://www.aspdotnetstorefront.com/DoItUsernamePwd
the same webservice says:
SOAPAction: "http://www.aspdotnetstorefront.com/DoItUsernamePwd"
put the error code for see the ploblem
good luck

Change HTTP response code in CXF SOAP Fault

I have this error
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Message part {http://soap.ws.server.wst.fit.cvut.cz/}createOrders was not recognized. (Does it exist in service WSDL?)</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
which is completely fine. But the problem is that CXF is returning Internal Server Error (HTTP 500). I would expect it to return 400 Bad Request because a wrong request is causing this. How can I change that?
DETAILS
The wrong request which produces the error above - there should be <soap:createOrder/> instead of <soap:createOrders/>.
POST http://localhost:8080/wst-server-1.0.0/services/soap/order
POST data:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.ws.server.wst.fit.cvut.cz/">
<soapenv:Header/>
<soapenv:Body>
<soap:createOrders/>
</soapenv:Body>
</soapenv:Envelope>
[no cookies]
Request Headers:
Content-Length: 238
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
I know maybe this is too late for the answer but another way to handle HTTP status code is using CXF interceptors.
you can add an interceptor in your server CXF configure
public class ServiceConfigurer implements CxfConfigurer {
#Override
public void configureServer(Server server) {
server.getEndpoint().getOutFaultInterceptors().add(new ChangingStatusCodeInterceptor();
}
}
and in your interceptor, you can change this
public class SaveInfluxDataInterceptor extends WSS4JOutInterceptor {
#Override
public void handleMessage(SoapMessage soapMessage) {
((Fault)exchange.get(Exception.class)).setStatusCode(202); // this is because of soap12OutFaultInterceptor look to this fault
// or you can use this
// exchange.getOutFaultMessage().put(Message.RESPONSE_CODE, 202);
}
}
I used Camel with CXF. maybe this solution should change in yours.