Topic
  • 1 reply
  • Latest Post - ‏2012-10-18T13:18:51Z by ShmulikB
SystemAdmin
SystemAdmin
2327 Posts

Pinned topic How do I create an HTTP SOAP Adapter with basic authorization?

‏2012-10-07T02:49:39Z |
How does one implement a SOAP HTTP Adapter that uses basic authorization? I could not find it anywhere on the getstarted modules or the developer guide.

So what I did is look up the definition for the WL.Server.invokeHttp function and found the following:

* @param options * The invokeHttp function accepts the following JSON block of * parameters:<br> 
{ method : 
'get' or 
'post', * returnedContentType: 
'xml' or 
'html', returnedContentEncoding : * 
'encoding', path: value, parameters: 
{name1: value1, ÔøΩ 
}, * headers: 
{name1: value1, ÔøΩ 
}, cookies: 
{name1: value1, ÔøΩ 
}, * body: 
{ contentType: 
'text/xml; charset=utf-8' or similar * value, content: stringValue 
}, transformation: 
{ type: 
'void', * 
'default', or 
'xslFile', xslFile: fileName 
} 
}


With this I figured that I can pass the authorization details in the headers ( headers: {name1: value1, ÔøΩ } ) as name value pair, see below

var input = 
{ method : 
'post', returnedContentType: 
'xml', path: 
'/xxx/xxx/xx', headers: 
{ Authorization: 
'Basic user:password' 
}, body: 
{ content : request.toString(), contentType : 
'text/xml; charset=utf-8', 
} 
};


And I got the following exception:

org.springframework.security.core.codec.InvalidBase64CharacterException

The authorization name value pair is expected to be passed in as a Base64 encoded string like the one below:

var input = 
{ method : 
'post', returnedContentType: 
'xml', path: 
'/xxx/xxx/xx', headers: 
{ Authorization: 
'Basic dXNlcjpwYXNzd29yZA==' 
}, body: 
{ content : request.toString(), contentType : 
'text/xml; charset=utf-8', 
} 
};

Now it all seems simple now but it took some playing with, because the word basic goes inside the actual value along with encoded string.
I was wondering if there is a place where the user and password goes and it takes care of the encoding and placing it in the header or is this the way to implement?

Also how can I get the E4X encoder for XML documents to work, I have to declare it as string other wise I get all kinds of errors with the eclipse JavaScript validator:

var request = 
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http://www.domain.com/PartSelectService-v1" xmlns:ns="http://www.domain.com/PartSelectCommon/2011-07-21">' + 
'<soapenv:Header/>' + 
'<soapenv:Body>' + 
'<par:BaseVehicleSearch>' + 
'<par:PSRequestHeader>' + 
'<ns:SvcVersion>1.0</ns:SvcVersion>' + 
'</par:PSRequestHeader>' + 
'<par:Years from="2000" to="2000"></par:Years>' + 
'<par:Region Id="2"/>' + 
'<par:VehicleType Id="5"/>' + 
'</par:BaseVehicleSearch>' + 
'</soapenv:Body>' + 
'</soapenv:Envelope>';

Thank you for any clarifications provided on these topics.

Roberto Lema
  • ShmulikB
    ShmulikB
    20 Posts

    Re: How do I create an HTTP SOAP Adapter with basic authorization?

    ‏2012-10-18T13:18:51Z  
    Hi

    Regarding the input var -
    Don't put a comma after the last pair of the body object (or any object):

    body: {
    content : request.toString(),
    contentType : 'text/xml; charset=utf-8'
    }

    Regarding the soap request -
    Don't make it as a string, just leave it as an object and regard the exceptions of the eclipse javascript validator.

    You can find all this information in Training Module 5.3 – Using HTTP adapters with SOAP Services.