Skip to Content

How to consume HTTP destination via Java deployed on SCP


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!



Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 23, 2018 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!



    Add comment
    10|10000 characters needed characters exceeded

  • Apr 23, 2018 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.

    Add comment
    10|10000 characters needed characters exceeded