Where can I find an example on how to set up https in java where https is not supported
Does anyone have a good example of how to do https over http (or socket)? The built-in java framework doesn't support https out of the box, but I'm sure it should be possible using some third party libraries or source snippets.
If someone can point me in the right direction, I would be very grateful
source to share
As bitover said, you can use the apache http components. A simple example where the https page requires user credentials:
public static void main (String[] args){
HttpClient httpclient = new DefaultHttpClient();
// Note that the specified port 443 corresponds with the SSL service
((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials(
new AuthScope("www.moneytrackin.com", 443),
new UsernamePasswordCredentials("user", "password"));
// Https page to access
HttpGet httpget = new HttpGet("https://www.moneytrackin.com/api/rest/getBalance");
HttpResponse response;
try {
response = httpclient.execute(httpget);
System.out.println("State: "+response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
String result= convertStreamToString(instream);
System.out.println("Data: "+result);
instream.close();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
More examples in this blog .
source to share
Which profile are you using? MIDP comes with an HTTS handler. I just checked the code. This package,
com.sun.midp.io.j2me.https
implements the HttpsConnection interface.
EDIT:
I think your best bet is to find an older version of BouncyCastle JCE that works with your Java version. BC JCE comes with this class for handling SSL,
http://www.bouncycastle.org/docs/docs1.3/org/bouncycastle/crypto/tls/TlsProtocolHandler.html
This test shows you how to make a simple HTTPS request.
source to share
Apache HttpCore is what you need. More details: http://hc.apache.org/httpcomponents-core/index.html
Br, Gabi
source to share
From what I remember, with HttpComponents, you just set up a socket factory to use SSLSocketFactory and it works; however SSLSocketFactory was added in Java 1.4.
Honestly, I would not have thought that the Apache HttpComponents API would work even in the limited environment you described ... you will most likely need an older version, from the back when called HttpClient (I think) and part of Jakarta Commons.
Good luck.
source to share
JBoss netty has a sample HTTP client , you just need to add SSlHandler to HTTPRequestHandler and HTTPResponseHandler.
source to share