webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Https Post using Java in webmethod 8.2

  • 1.  Https Post using Java in webmethod 8.2

    Posted Wed June 05, 2013 10:46 AM

    [b]Hi All

    Here the story why we want to use java code:

    Current we have below requirement to achieve at our integration. We need to pass cookie manually in the https header for a webservice.

    When we checked with software AG document we understood that it is not possible

    “Integration Server automatically adds the Cookie header to the HTTP header and supplies any cookies established between Integration Server and the HTTP serverwith which it is interacting. If you supply the Cookie header to transportHeaders, Integration Server prepends the values you supply to the already established Cookie header value”

    Current story:

    So we concluded to write a java code to invoke the webservice: But the connection fails due to certificate issue.

    Included the java.security file to override the SSL authentication. but it fails while compliation as no class found

    Please can some one letme know how to hit a service using https protocal and post data in webmethod. Any other option to invoke the webserivce by passing cooke in the header

    here is the code snap

    try
    {
    IDataCursor pipelineCursor = pipeline.getCursor();
    String Soap_data = IDataUtil.getString( pipelineCursor, “Soap_data” );
    String Cookie_SSO = IDataUtil.getString( pipelineCursor, “Cookie_SSO” );
    String destUrl = “https://xxxxxxxxxxxxxxxxxxxxxxx”;

    //open connection
    URL url1 = new URL(destUrl);
    HttpsURLConnection connect = (HttpsURLConnection)url1.openConnection();
    connect.setDoOutput(true);
    connect.setDoInput(true);
    connect.setRequestMethod(“POST”);
    connect.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”);
    connect.setRequestProperty(“Content-Length”, Integer.toString(Soap_data.length()));
    connect.setRequestProperty(“Cookie”, Cookie_SSO);
    connect.setRequestProperty(“User-Agent”, “Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0”);
    connect.setInstanceFollowRedirects(false);

    TrustManager trustAllCerts = new TrustManager
    {
    new X509TrustManager()
    {
    public java.security.cert.X509Certificate getAcceptedIssuers()
    {
    return null;
    }
    public void checkClientTrusted(java.security.cert.X509Certificate certs, String authType)
    {
    }
    public void checkServerTrusted(java.security.cert.X509Certificate certs, String authType)
    {
    }
    }
    };
    IDataUtil.put( pipelineCursor, "before ", “yes” );
    //Post data
    DataOutputStream wr = new DataOutputStream (connect.getOutputStream ());
    IDataUtil.put( pipelineCursor, "After ", “yes” );
    wr.writeBytes(Soap_data);
    wr.flush ();
    wr.close ();

    // Get Cookie
    IDataUtil.put( pipelineCursor, “cookie”, connect.getHeaderField(“Set-Cookie”));

    // Get Response
    InputStream is = connect.getInputStream();
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));
    String line;
    StringBuffer response = new StringBuffer();
    while((line = rd.readLine()) != null)
    {
    response.append(line);
    response.append(‘\n’);
    IDataUtil.put( pipelineCursor, “logonResult”, response.toString()
    );
    }

    rd.close();

    pipelineCursor.destroy();
    connect.disconnect();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }


    #webMethods
    #Integration-Server-and-ESB


  • 2.  RE: Https Post using Java in webmethod 8.2

    Posted Wed June 05, 2013 11:34 AM

    It’s a little bit research involved question…will try to check if any work around for this:


    #webMethods
    #Integration-Server-and-ESB


  • 3.  RE: Https Post using Java in webmethod 8.2

    Posted Wed June 05, 2013 12:11 PM

    Hi,
    when developer compiles java code it throws the error and line number where the problem is. Please check at what line of code it is throwing the error. In shared tab you can import the classes you are using in your code and then try compiling your code and see what error is coming.


    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: Https Post using Java in webmethod 8.2

    Posted Wed June 05, 2013 03:05 PM

    OK did the JS compiled properly and in the Shared tab can you list the imports you have been used?

    HTH,
    RMG


    #webMethods
    #Integration-Server-and-ESB


  • 5.  RE: Https Post using Java in webmethod 8.2

    Posted Thu June 06, 2013 05:45 AM

    I have imported all these class

    java.security.KeyStore
    java.security.SecureRandom
    java.util.Random
    java.lang.Object
    java.security.Security
    java.security.cert.X509Certificate
    javax.net.ssl.X509TrustManager
    javax.net.ssl.TrustManager
    java.io.InputStreamReader
    javax.net.ssl.HttpsURLConnection
    java.io.OutputStream
    java.net.URLEncoder
    java.util.*
    java.security.SecureRandom
    java.util.Random

    But i am still getting the below error

    /usr/apl/wm80/is3/IntegrationServer/packages/EAI_SALESPORTAL_KPI/code/source/EAI_SALESPORTAL_KPI/java.java:164: cannot find symbol
    symbol : class security
    location: class EAI_SALESPORTAL_KPI.java
    public java.security.cert.X509Certificate[] getAcceptedIssuers()
    ^
    /usr/apl/wm80/is3/IntegrationServer/packages/EAI_SALESPORTAL_KPI/code/source/EAI_SALESPORTAL_KPI/java.java:168: cannot find symbol
    symbol : class security
    location: class EAI_SALESPORTAL_KPI.java
    public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)

    I have imported the required class still this error


    #webMethods
    #Integration-Server-and-ESB


  • 6.  RE: Https Post using Java in webmethod 8.2

    Posted Thu June 06, 2013 06:31 AM

    Hi Rajesh,
    What doubt i am having after seeing the error code is the whether “rt.jar” is available in the class path or not as this jar file contains all the security related classes and it should be available in the class path.

    Please check the class path and confirm if it is available.

    Regards,
    Vikas


    #webMethods
    #Integration-Server-and-ESB


  • 7.  RE: Https Post using Java in webmethod 8.2

    Posted Thu June 06, 2013 07:53 AM

    Yes i have checked can find lot other jar not the one mentioned by you.

    But can the naming be different? any other file can have this security jar?

    Can you share the jar and let me know where to place? there is also option to place the jar in individual folder can i do that?


    #Integration-Server-and-ESB
    #webMethods


  • 8.  RE: Https Post using Java in webmethod 8.2

    Posted Thu June 06, 2013 08:18 AM

    Hi Rajesh,
    As per my knowledge no other jar contains security class. Also rt.jar is a basic jar file comes along with all the installation of java sdk. Go to your JVM folder inside your webMethods installation directory there go inside jre then lib, there you can find ‘rt.jar’ and from there you can copy and place it inside <package name (where your java code resides)>/code/jars/static folder. Try reloading the package if does not work then try restarting the IS and then check.


    #Integration-Server-and-ESB
    #webMethods


  • 9.  RE: Https Post using Java in webmethod 8.2

    Posted Thu June 06, 2013 08:51 AM

    Hi,

    i placed the jar file in below location

    IntegrationServer/packages/package name/code/jars

    -rwxr-xr-x 1 Jun 6 13:39 rt.jar

    i restarted the server as well but still the same error

    /usr/apl/wm80/is3/IntegrationServer/packages/EAI_SALESPORTAL_KPI/code/source/EAI_SALESPORTAL_KPI/java.java:165: cannot find symbol
    symbol : class security
    location: class EAI_SALESPORTAL_KPI.java
    public java.security.cert.X509Certificate[] getAcceptedIssuers()
    ^
    /usr/apl/wm80/is3/IntegrationServer/packages/EAI_SALESPORTAL_KPI/code/source/EAI_SALESPORTAL_KPI/java.java:169: cannot find symbol
    symbol : class security
    location: class EAI_SALESPORTAL_KPI.java
    public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)


    #webMethods
    #Integration-Server-and-ESB


  • 10.  RE: Https Post using Java in webmethod 8.2

    Posted Thu June 06, 2013 11:22 AM

    Rajesh,

    You should place the jar in this location as mentioned above:

    packages/code/jars/static folder. Try reloading the package if does not work then try restarting the IS and then check.

    Also put in the IS/lib/jars (just to make sure and need a IS restart for this)

    HTH,
    RMG


    #Integration-Server-and-ESB
    #webMethods


  • 11.  RE: Https Post using Java in webmethod 8.2

    Posted Thu June 06, 2013 12:01 PM

    Hi Rajesh,
    I tried your code and found you need to place jsse.jar (this jar can be found to same place where you found rt.jar)to classpath and import javax.security.cert.* class to your code. Then this error will go away.


    #Integration-Server-and-ESB
    #webMethods


  • 12.  RE: Https Post using Java in webmethod 8.2

    Posted Mon June 10, 2013 06:22 AM

    Hi,

    I placed the other file as you mentioned and restarted the server still same compliation error.

    I have imported the javax.security.cer.*

    [ ~]$ cd IntegrationServer/packages/EAI_SALESPORTAL_KPI/code/jars/static/
    [ static]$ ls
    jsse.jar rt.jar
    [static]$


    #Integration-Server-and-ESB
    #webMethods


  • 13.  RE: Https Post using Java in webmethod 8.2

    Posted Mon June 10, 2013 07:04 AM

    Hi Rajesh,
    Not sure what is going wrong in your case. Try placing these files in IntegrationServer\lib\jars\ then restart the server. It should solve the problem. For me now no error in the code compilation.


    #webMethods
    #Integration-Server-and-ESB


  • 14.  RE: Https Post using Java in webmethod 8.2

    Posted Mon June 10, 2013 07:22 AM

    Hi,

    I placed the jar in the mentioned folder Integartion/lib/jars

    still same error

    /usr/apl/wm80/is3/IntegrationServer/packages/EAI_SALESPORTAL_KPI/code/source/EAI_SALESPORTAL_KPI/java.java:172: cannot find symbol
    symbol : class security
    location: class EAI_SALESPORTAL_KPI.java
    public void checkServerTrusted(java.security.cert.X509Certificate certs, String authType)
    ^
    3 errors

    use using same class? java.security.cert.X509Certificate


    #webMethods
    #Integration-Server-and-ESB


  • 15.  RE: Https Post using Java in webmethod 8.2

    Posted Mon June 10, 2013 07:56 AM

    Hi Rajesh,
    Error indicates about jar file is not in the class path. Even for me in the starting same error but after placing jar in classpath issue got resolved. In your case only one thing i can suggest to check the about page and see if jar is listed there. If it is not listed then jar is not available in the class path else check with SAG support.


    #webMethods
    #Integration-Server-and-ESB


  • 16.  RE: Https Post using Java in webmethod 8.2

    Posted Mon June 10, 2013 08:22 AM

    i can see the jar being listed in the about page on my IS server

    IntegrationServer/lib/jars/rt.jar

    IntegrationServer/lib/jars/jsse.jar

    IntegrationServer/packages/EAI_SALESPORTAL_KPI/code/jars/static/rt.jar

    IntegrationServer/packages/EAI_SALESPORTAL_KPI/code/jars/static/jsse.jar

    Still not working, do i need to update the jar is some other path?


    #Integration-Server-and-ESB
    #webMethods


  • 17.  RE: Https Post using Java in webmethod 8.2

    Posted Mon June 10, 2013 12:12 PM

    You should put try jars under the lib not jars.

    IntegrationServer/lib/rt.jar

    IntegrationServer/lib/jsse.jar


    #webMethods
    #Integration-Server-and-ESB


  • 18.  RE: Https Post using Java in webmethod 8.2

    Posted Tue June 11, 2013 08:42 AM

    Hi Vikas,

    Can you please your java code which you complied?

    I tried all possible path and still same error.

    Thanks in advance


    #Integration-Server-and-ESB
    #webMethods


  • 19.  RE: Https Post using Java in webmethod 8.2

    Posted Tue June 11, 2013 09:23 AM

    Hi Rajesh,
    It is your code but very little change.
    try
    {
    IDataCursor pipelineCursor = pipeline.getCursor();
    String Soap_data = IDataUtil.getString( pipelineCursor, “Soap_data” );
    String Cookie_SSO = IDataUtil.getString( pipelineCursor, “Cookie_SSO” );
    String destUrl = “https://xxxxxxxxxxxxxxxxxxxxxxx”;

    //open connection
    URL url1 = new URL(destUrl);
    HttpsURLConnection connect = (HttpsURLConnection)url1.openConnection();
    connect.setDoOutput(true);
    connect.setDoInput(true);
    connect.setRequestMethod(“POST”);
    connect.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”);
    connect.setRequestProperty(“Content-Length”, Integer.toString(Soap_data.length()));
    connect.setRequestProperty(“Cookie”, Cookie_SSO);
    connect.setRequestProperty(“User-Agent”, “Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0”);
    connect.setInstanceFollowRedirects(false);

    TrustManager trustAllCerts = new TrustManager
    {
    new X509TrustManager()
    {
    public javax.security.cert.X509Certificate getAcceptedIssuers()
    {
    return null;
    }
    public void checkClientTrusted(javax.security.cert.X509Certificate certs, String authType)
    {
    }
    public void checkServerTrusted(javax.security.cert.X509Certificate certs, String authType)
    {
    }
    }
    };
    IDataUtil.put( pipelineCursor, "before ", “yes” );
    //Post data
    DataOutputStream wr = new DataOutputStream (connect.getOutputStream ());
    IDataUtil.put( pipelineCursor, "After ", “yes” );
    wr.writeBytes(Soap_data);
    wr.flush ();
    wr.close ();

    // Get Cookie
    IDataUtil.put( pipelineCursor, “cookie”, connect.getHeaderField(“Set-Cookie”));

    // Get Response
    InputStream is = connect.getInputStream();
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));
    String line;
    StringBuffer response = new StringBuffer();
    while((line = rd.readLine()) != null)
    {
    response.append(line);
    response.append(‘\n’);
    IDataUtil.put( pipelineCursor, “logonResult”, response.toString()
    );
    }

    rd.close();

    pipelineCursor.destroy();
    connect.disconnect();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }


    #webMethods
    #Integration-Server-and-ESB


  • 20.  RE: Https Post using Java in webmethod 8.2

    Posted Wed June 12, 2013 05:30 AM

    Hi Rajesh,
    whether your issue is resolved??


    #webMethods
    #Integration-Server-and-ESB


  • 21.  RE: Https Post using Java in webmethod 8.2

    Posted Tue June 18, 2013 06:44 AM

    Rajesh, two things, may be stupid.

    1. some of the security classes are supported in jvm1.4+
    2. since you have imported the class in java program, can you try using
      public X509Certificate getAcceptedIssuers() instead of
      public java.security.cert.X509Certificate getAcceptedIssuers()

    i do not see any reason for adding jarfiles to your packages as most of the classes used are core java apis.

    D.C.


    #webMethods
    #Integration-Server-and-ESB


  • 22.  RE: Https Post using Java in webmethod 8.2