Skip to Content
0

How to call an internal HCP servlet from an XSJS service (Service to Service call)

Jan 15, 2017 at 08:26 PM

96

avatar image

Dear all,

On HCP, I have created a servlet to send email with an external email account.

Now, I would like to call this service from an XSJS service using the HTTP outbound API but I am struggling to make it working.

First of all, when I test my servlet from Postman, it works as expected without authentication or specific certificat...

But, then when I call this service from my XSJS service, I am not getting any response and actually, I am getting an HTTP code 302 as return code. Do you have any idea why ?

Here is the content of my http destination:

description = "eMail";
host = "myservletXXXac000000.hana.ondemand.com";
port = 443;
proxyType = http;
proxyHost = "proxy";
proxyPort = 8080;
authType = none;
useSSL = true;
sslHostCheck = false;

For the port, I tried 443 and 8443 without success

Here is my XSJS code:

var dest = $.net.http.readDestination("courseducoeur.compagnon.services.anonymous", "servlet_mail");
var client = new $.net.http.Client();
//var req = new $.net.http.Request($.net.http.POST, "/mail");
var req = new $.web.WebRequest($.net.http.POST, "/mail");

//req.headers.set("host", "cdcmailac478bd45.hana.ondemand.com");  
req.headers.set("Content-Type", "application/json;charset=UTF-8");

req.setBody(JSON.stringify(oData));
client.request(req, dest); 
var response = client.getResponse(); 

On the XS admin side, I created a new Trust Store and uploaded the certificate that I have downloaded from my servlet page including the certificate for the domain hana.ondemand.com. Here, I am not sure if this is the right was to do it...

Anyway, after a lot of different tries, I am still getting this error 302. Any idea why? Am I using the right authentication mode, port, hostname ?

Is the keystore really needed when calling internal application in HCP ? What is the right process ?

Thanks in advance for your help !

Best regards,

Nico.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Nicolas COTTIN
Jan 26, 2017 at 10:08 PM
0

Yes, I have found :)

Actually, the service URL was incomplete. So, using the full URL including the servlet class name helped

var req = new $.web.WebRequest($.net.http.POST, "/mail/ServletMail");

ServletMail is my Servlet's name. In the associated web.xml, there is a servlet mapping pattern /mail pointing to this class and this is what it was causing the HTTP 302 "error".

Share
10 |10000 characters needed characters left characters exceeded
Dawid Banas Jan 20, 2017 at 01:33 PM
0

Have you found any solution?

Share
10 |10000 characters needed characters left characters exceeded