1

Adapter JS

function getCitiesByCountry(countryName)

{ 

 var request =
    var request=
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
   <soapenv:Header/>
   <soapenv:Body>
      <web:GetCitiesByCountry>
         <!--Optional:-->
         <web:CountryName>INDIA</web:CountryName>
      </web:GetCitiesByCountry>
   </soapenv:Body>
</soapenv:Envelope>;

var input =

 {
    method: 'post',
    returnedContentType: 'xml',
    path: '/globalweather.asmx',
    body: {
        content: request.toString(),
        contentType: 'text/json; charset=utf-8'
    }
};
var result = MFP.Server.invokeHttp(input);
return result.Envelope.Body;
};

Adapter XML

<displayName>JavaScriptSOAP</displayName>
<description>JavaScriptSOAP</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>www.webservicex.net</domain>
        <port>80</port>
    </connectionPolicy>
</connectivity>

<procedure name="getCitiesByCountry" secured ="false"/>

Index.js

   function submitRequest()
 {
  var resourceRequest = new             WLResourceRequest("adapters/JavaScriptSOAP/getCitiesByCountry", WLResourceRequest.POST);
  resourceRequest.setQueryParameter("params", "['India']");
  resourceRequest.send().then(
   function(response) {
        alert('response   '+JSON.stringify(response.responseText));
   },
        function(response) {

        alert("HTTP Failure  "+JSON.stringify(response));
     }
    );
    }

I need to pass parameters to http Adapters.It contains Country Name.I have included the Country name in Index js file itself.While previewing the app,I receive the error code 415,

And in console I received as

[AUDIT   ] CWWKS1100A: Authentication did not succeed for user ID test. An invalid user ID or password was specified.
[AUDIT   ] CWWKS1100A: Authentication did not succeed for user ID test. An invalid user ID or password was specified.
[AUDIT   ] CWWKS1100A: Authentication did not succeed for user ID test. An invalid user ID or password was specified.

I have:

Eclipse Java EE IDE for Web Developers. Version: Mars.2 Release (4.5.2) Build id: 20160218-0600 Windows 7

What authentication I have to give .How to overcome the error??

Janaki Narayanan
  • 523
  • 6
  • 24

3 Answers3

1

A 415 is "Unsupported media type". This means that the server decided that the request you sent does not contain the type of data that the server thinks it should.

The reason you are getting this is because you are sending a POST request without a body and with query parameters. What you can do to solve this is to change the POST request to a GET request. Just change

 WLResourceRequest("adapters/JavaScriptSOAP/getCitiesByCountry", WLResourceRequest.POST);

to

 WLResourceRequest("adapters/JavaScriptSOAP/getCitiesByCountry", WLResourceRequest.GET);
Moty Drimer
  • 181
  • 4
0

You are passing the arguments incorrectly. params is an array therefore your code should look like

function submitRequest() { var resourceRequest = new WLResourceRequest("adapters/JavaScriptSOAP/getCitiesByCountry", WLResourceRequest.POST); resourceRequest.setQueryParameter("params", "['India']"); resourceRequest.send().then( function(response) { alert('response '+JSON.stringify(response.responseText)); }, function(response) { alert("HTTP Failure "+JSON.stringify(response)); } ); }
Yoel Nunez
  • 2,108
  • 1
  • 13
  • 19
0

Try to add secured="false" to the procedure declaration in the XML file:

<procedure name="getCitiesByCountry" secured="false"/>
Shmulik Bardosh
  • 299
  • 1
  • 6