on 12-12-2005 1:50 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Hi Jason,
This link gives you more information on the difference
http://www.innovation.ch/java/HTTPClient/urlcon_vs_httpclient.html
Regards
Vishnu
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.