Https Post using Java in webmethod 8.2

[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();
}

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

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.

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

HTH,
RMG

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

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

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?

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.

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)

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

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.

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]$

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.

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

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.

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?

You should put try jars under the lib not jars.

IntegrationServer/lib/rt.jar

IntegrationServer/lib/jsse.jar

Hi Vikas,

Can you please your java code which you complied?

I tried all possible path and still same error.

Thanks in advance

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();
}

Hi Rajesh,
whether your issue is resolved??