How to apply namespace qualifier on parent tag only - soap

I have a soap request that needs to look like this, with the 'user:' qualifier ONLY pertaining to the 'getTopQuestions' tag. Here is what the request SHOULD look like:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<user:getTopQuestions>
<interfaceId>4</interfaceId>
<numberOfQuestions>10</numberOfQuestions>
</user:getTopQuestions>
</soap:Body>
</soap:Envelope>
However, my request looks like this. As you can see, the 'user:' namespace qualifier is attached to the children tags of the parent 'user:getTopQuestions'
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<user:getTopQuestions>
<user:interfaceId>4</user:interfaceId>
<user:numberOfQuestions>10</user:numberOfQuestions>
</user:getTopQuestions>
</soap:Body>
</soap:Envelope>
How do I get the 'user:' namespace qualifier off of the child tags 'interfaceId' and 'numberOfQuestions'?
Here is my request:
$.soap({
url,
method: options.method,
data: options.data || {},
success: soapResponse => {
let responseContent = `${options.method}Response`;
let body = 'Body';
let data = soapResponse.toJSON();
if (data['soap:Body']) {
responseContent = `ns1:${responseContent}`;
body = `soap:${body}`;
}
data = data[body][responseContent];
deferred.resolve(data);
},
error: SOAPResponse => {
deferred.reject(SOAPResponse);
},
namespaceQualifier: "user:",
envAttributes: {
'xmlns:user': '/com/intelliresponse/search/user'
},
SOAPAction: " "
});

Can you remove the ":" from the namespaceQualifier as suggested here
https://github.com/zachofalltrades/jquery.soap
use namespaceQualifier: 'myns', // used as namespace prefix for all
instead of namespaceQualifier: ':myns' //with a colon

Related

wiremock request matching from key=value pair

I am using json mapping to match the request. The request coming as content-type application/x-www-form-urlencoded which means as a Key=value pair and the value contains xml data. For example:
REQUEST=<?xml version="1.0" encoding="UTF-8"?>
<n:request xmlns:n="schema uri" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="schema location">
<header userId="userId" password="password" requesterId="123" version="100" language="de">
<product>xxx</product>
</header>
<subject>
<party externalIdentifier="1">
<address externalIdentifier="11">
<person>
<firstName>rinku</firstName>
<lastName>chy</lastName>
<birthDate>1973-12-10</birthDate>
</person>
<street>street</street>
<number>12</number>
<countryCode>de</countryCode>
<zipCode>123</zipCode>
<city>city</city>
</address>
</party>
</subject>
</n:request>
The purpose is to find the product name and the person's name. I have tried both xpath as well as query parameters expression to match the request as stated in http://wiremock.org/docs/request-matching/. But couldn't manage to get a solution yet.For example
{
"request": {
"method": "POST",
"urlPattern": "/mock.*",
"queryParameters": {
"product": {
"matches": "xxx"
}
},
// tried both seperately
"bodyPatterns": [
{
"matchesXPath": "//*[local-name()='request']/*[local-name()='header']/*[local-name()='product'][text()='xxx']"
}
]
},
"response": {
"status": 200,
"bodyFileName": "response.xml",
"headers": {
"Content-Type": "text/xml; charset=UTF-8",
"Content-Location": "response.xml"
}
}
}
Always getting the same error "[WireMock] (qtp2017957857-34) Warning: failed to parse the XML document. Reason: Content is not allowed in prolog.
Can anyone have a clue how to match such a request?
I found the solution. There is an option to intercept and modify requests. Visit -> http://wiremock.org/docs/extending-wiremock/ in the section "Intercepting and modifying requests".
public class RequestFilter extends StubRequestFilter {
#Override
public RequestFilterAction filter(Request request) {
// removed "REQUEST=" from request body
Request modifyRequest = RequestWrapper.create()
.transformBody(requestBody -> Body.fromOneOf(null, requestBody.asString().substring(8)), null, null))
.wrap(request);
return RequestFilterAction.continueWith(modifyRequest);
}
#Override
public String getName() {
return "my-request-filter";
}}

Resolve email adress from x500 address in EWS

I am using EWS in meteor js app and I am using lather to compose the soap request.
I would like to get all meetings form Exchange, and I need meeting's organiser email address (SMTP), but it always retreive x500 addrress like:
/O=ABCD/OU=EXCHANGE ADMINISTRATIVE GROUP (ABCDEFGH)/CN=RECIPIENTS/CN=ABCD00000"
I have searched for a solution and found this:
NameResolutionCollection coll = service.ResolveName("/O=ABCD/OU=EXCHANGE ADMINISTRATIVE GROUP (ABCDEFGH)/CN=RECIPIENTS/CN=ABCD00000", ResolveNameSearchLocation.DirectoryOnly,true)
But I am not using C#, how can this be done in technology free fashion.
A ResolveName SOAP request should look something like https://msdn.microsoft.com/en-us/library/office/aa563518(v=exchg.150).aspx eg
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2007_SP1" />
</soap:Header>
<soap:Body>
<m:ResolveNames ReturnFullContactData="true" SearchScope="ActiveDirectoryContacts">
<m:UnresolvedEntry>test</m:UnresolvedEntry>
</m:ResolveNames>
</soap:Body>
</soap:Envelope>
So in Lather based on the other example on that page something like
var lather = require('lather');
var resolveName = {
'm:ResolveNames' : {
attributes : [
{ ReturnFullContactData : 'true' },
{ SearchScope : 'ActiveDirectoryContacts' },
],
'm:UnresolvedEntry' : '/O=ABCD/OU=EXCHANGE ADMINISTRATIVE GROUP (ABCDEFGH)/CN=RECIPIENTS/CN=ABCD00000',
},
};
lather.up({
body : resolveName,
headers : {
Authorization : lather.basicAuth(exchangeUserName, exchangePassword),
},
additionalNamespaces : [
'xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"',
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"',
],
method : 'POST',
url : 'https://outlook.office365.com/EWS/Exchange.asmx',
}, function(error, res, body) {
...
});
Should work (but maybe some changes are required)
Cheers
Glen

smartface.io call a web service

I am using smartface.io to call a soap web service. My code is as below. when I call it returns a error says "Server Error" But when I call it from browser it works well.
var requestString =
'' +
'' +
'' +
'' +
'admin#borapay.com' +
'Admin#123456<>' +
'' +
'' +
'';
var getRate = new SMF.Net.WebClient({
URL : "http://172.98.72.148/borapay/WebServices/CustomerServices.asmx",
httpMethod : "POST",
requestHeaders : [
"Content-Type: text/xml;charset=UTF-8",
"SOAPAction: http://tempuri.org/UserLogin"
],
onSyndicationSuccess : function (e) {
},
onServerError : function (e) {
alert("onServerError");
},
requestString : requestString,
responseHandling : SMF.Net.ResponseHandling.forceText,
timeoutInterval : 120
});
getRate.run()
Your request string seems wrong, it should be full envelope like;
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bora="http://bora-pay.com/">
<soapenv:Header/>
<soapenv:Body>
<bora:UserLogin>
<!--Optional:-->
<bora:userName>admin#borapay.com</bora:userName>
<!--Optional:-->
<bora:password>Admin#123456<></bora:password>
</bora:UserLogin>
</soapenv:Body>
</soapenv:Envelope>
But you need to convert that as a Java Script string.

AngularJS DELETE with Tomcat causes 405 Request method 'DELETE' not supported

I'm using Spring Data Neo4j Rest backend served on Tomcat (8.0.27) with Angular frontend, all served locally at http://localhost:8080/. When I try to delete a record with either $http.delete() or with $resource().delete(), tomcat returns a 405 not supported error.
However, using $http({method: 'DELETE', url: '/competitors/13'}) works fine. Unfortunately, this does not allow me to use the angular $resource service instead of $http, which is my goal. (As an aside, PUT creates the same 405 response as DELETE)
I am also able to use DELETE from command line. This works fine:
curl -X DELETE http://localhost:8080/competitors/13
I have disable csrf in WebSecurityConfig in case that has anything to do with it.
I have also added readonly init-param to web.xml to try to force tomcat to accept DELETE, like so:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Proto v2 Application</display-name>
<servlet>
<servlet-name>proto</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>proto</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Since I've verified that the server is able to perform the delete, I will omit all Java code. Here is my complete .js file with the angular module:
var magneticApp = angular.module('magneticApp', ['ngResource'])
.controller('defaultCtrl', function ($scope, $http, $resource, baseUrl) {
$scope.Competitor = $resource("/competitors/:id", {id: "#id"});
$scope.listItems = function () {
var query = $scope.Competitor.get(function () {
console.log('inside query');
});
query.$promise.then(
function successCallback(data) {
$scope.competitors = data._embedded.competitors;
},
function errorCallback(data) {
console.log('error:');
console.dir(data);
}
);
};
/*
* THIS DELETE FUNCTION RETURNS A 405 NOT SUPPORTED ERROR
*/
$scope.deleteItem = function (item) {
var query = $scope.Competitor.delete({}, item.itemId);
query.$promise.then(
function successCallback(data) {
console.log('success:');
$scope.competitors.splice($scope.competitors.indexOf(item), 1);
},
function errorCallback(data) {
console.log('error:');
console.dir(data);
}
);
};
/*
* THIS DELETE FUNCTION WORKS PROPERLY
*/
$scope.deleteItemWorksCorrectly = function (item) {
$http({method: 'DELETE', url: '/competitors/' + item.itemId})
.then(
function successCallback(data) {
$scope.competitors.splice($scope.competitors.indexOf(item), 1);
},
function errorCallback(data) {
console.log('delete error');
console.dir(data);
}
);
};
$scope.adjustActive = function (item) {
item.id = item.itemId;
console.log('adjustActive');
console.dir(item);
$http.post('/competitors', item)
.success(function (data) {
$http.get('/competitors').success(function (data) {
console.dir(data._embedded.competitors);
$scope.competitors = data._embedded.competitors;
});
});
};
$scope.addItem = function (itemName) {
var item = {name: itemName};
$http.post('/competitors', item)
.success(function (data) {
$http.get('/competitors').success(function (data) {
console.dir(data._embedded.competitors);
$scope.competitors = data._embedded.competitors;
//magneticApp.controller('defaultCtrl').$scope.competitors = data._embedded.competitors;
});
});
};
$scope.listItems();
});
Can anyone shed some light on this? Thanks.

UrlFetchApp Authentication failed Freshbooks

So I am trying to communicate with the freshbooks api by making the sample request detailed on the developers page of freshbooks (http://developers.freshbooks.com/). We are doing token-based authentication as opposed to using OAuth.
I have my code logging the responses to my requests in a spreadsheet. The responses it has been logging are as follows:
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="http://www.freshbooks.com/api/" status="fail">
<error>Authentication failed.</error>
<code>20010</code>
</response>
I have been able to authenticate when using a curl command in console, but not when running the script. Below is the code I used. Left out the logging to spreadsheet part and our specific url and authToken:
// Sample function to call into an API using basic HTTP auth
function freshbooksTest () {
var url = ;
var authToken = ;
var unamepass =authToken+":X";
var digestfull = "Basic "+unamepass;
var payload = '<request method="system.current"></request>';
var options =
{
"method" : "post",
"muteHttpExceptions": true,
"headers" : {"Authorization": digestfull},
"payload" : payload
};
var response = UrlFetchApp.fetch(url, options);
var xml = response.getContentText();
}
I have checked out threads where people are having similar problems, but the solutions were either not applicable to my situation, or have already been tried. Any suggestions are welcome.
Not specifically familiar with UrlFetchApp, but if it doesn't do it for you, you'll need to Base64 encode digestfull before you send it in the header.
Looks like you need to base 64 encode your auth token. Code should look like this:
function freshbooksTest () {
var url = ;
var authToken = ;
var unamepass = authToken+":X";
var digestfull = "Basic "+ Utilities.base64Encode(unamepass);
var payload = '<request method="system.current"></request>';
var options =
{
"method" : "post",
"muteHttpExceptions": true,
"headers" : {"Authorization": digestfull},
"payload" : payload
};
var response = UrlFetchApp.fetch(url, options);
var xml = response.getContentText();
}