cancel
Showing results for 
Search instead for 
Did you mean: 

How to send Https request by Java code in XI Adapter

Former Member
0 Kudos

Hi, Friends

I developed an XI adapter which will send cXML request to an cXML server, the connection will be Https.

I use following java code to send https request, it works fine for http request (for example: http://service.abc.com), but failed for https request(for

example: https://service.abc.com). I use the java class URL and URLConnection in java.net package to set up a connection.

Who can tell me why https request failed? Thanks very much.

The code is below:

<i>URL url = new URL(address);

URLConnection http = url.openConnection();

http.setDoInput(true);

http.setDoOutput(true);

http.setUseCaches(false);

http.setRequestMethod("POST");

http.connect();

OutputStreamWriter out = new OutputStreamWriter(http.getOutputStream());

out.write(payload);

out.flush();

BufferedReader in = new BufferedReader(new InputStreamReader(http.getInputStream()));

String input = "";

while ((input = in.readLine()) != null) {

resultxml += input;

}

in.close();

out.close();</i>

Best Regards,

Jason

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Jason,

I can strongly recommend the open source library Jakarta Commons for creating Java HTTPS client. See http://jakarta.apache.org/commons/httpclient/ and in particular the SSL guide http://jakarta.apache.org/commons/httpclient/sslguide.html.

Kind regards, Guy Crets

Former Member
0 Kudos

Thanks, Guy, I use HttpClient to send https request on PCK, it works fine.

But I am not clear what's the difference between java.net.URLConnect and HttpClient, it seems they do the same thing, but HttpClient can work on PCK/XI, but URLConnection not.

Thanks and Regards,

Jason

Former Member
0 Kudos

Hi Jason,

The Apache Commons project is contains libraries of useful Java functions from developers working on other Apache project. These libraries extend the functionality in standard Java.

In case of HttpClient, this library provides a much richer functionality than available in standard Java with URLConnection.

Kind regards, Guy Crets

Former Member
0 Kudos

Hi Jason,

This link gives you more information on the difference

http://www.innovation.ch/java/HTTPClient/urlcon_vs_httpclient.html

Regards

Vishnu

Former Member
0 Kudos

thanks, Vishnu, I understood the difference.

Kind Regards,

Jason

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks, Vishnu and Guy.

I'm developing and testing XI adapter on PCK, how should I configure the PCK so that it can support https? (PCK is SP14 and the JRE version is 1.4.2.)

If I use Apache HttpClient to send https request as below, will it be better than direct java.net.URLConnection?

<b>HttpClient httpclient = new HttpClient();

GetMethod httpget = new GetMethod("https://service.abc.com/");

try {

httpclient.executeMethod(httpget);

String resp = httpget.getResponseBodyAsString();

System.out.println(httpget.getStatusLine());

System.out.println(resp);

} catch (Exception e) {

e.printStackTrace();

} finally {

httpget.releaseConnection();

}</b>

Thanks & Regards,

Jason

Message was edited by: Jason Wang

Former Member
0 Kudos

Hi Jason,

for Https, you need to install JSSE and that has to be in your classpath and also (in the program) you should add this to system property and add a new security provider (to the security class object).

Hope this helps

Regards

Vishnu