Skip to Content

How to consume HTTP destination via Java deployed on SCP

Apr 23 at 01:13 PM


avatar image


any idea how to consume HTTP destination (XSJS service) from Java application deployed on SCP? The XSJS service is protected via basic authentication. I know how to consume HTTP destination just fine when there's no authentication involved. I would like to be able to consume it also with the basic authentication on. The runtime environment for the Java app is Tomcat 8. I was not able to find any examples or tutorials describing the process.

The neo-java-web-sdk-3 connectivity sample application consumes HTTP destination with no basic authentication just fine but returns status 401 (Unauthorised) for any destinations protected by the basic authentication :(

The official documentation does not supply any example for Tomcat 8 runtime. Only for Java EE 6.

Any help is much appreciated!



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

2 Answers

Best Answer
Peter Hrebik Apr 23 at 02:21 PM

I've managed to resolve my own problem. I've realized I can access destination properties to get the credentials and then simply use the standard Java:

BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = destConfiguration.getProperty("User") + ":" + destConfiguration.getProperty("Password");
String encodedAuthorization = enc.encode( userpassword.getBytes() );
urlConnection.setRequestProperty("Authorization", "Basic "+ encodedAuthorization);

Happy days!



10 |10000 characters needed characters left characters exceeded
Gregor Wolf
Apr 23 at 01:47 PM

You only need to switch to Basic Authentication in the destination configuration and provide the username and password. Then there should be no difference than using a HTTP destination without authentication.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Thanks for your reply Gregor. Exactly. This is something I expect to work just fine but unfortunately this approach does not work for destinations with basic authentication enabled (of course with the predefined credentials) and returns the 401. The solution I proposed above works perfectly.




Do you use the Additional Properties to store the Username / Password or the fields on the left?