package de.eknori.traveler; import java.io.BufferedReader; import java.io.InputStreamReader; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.httpclient.protocol.Protocol; public class TravelerApiSSLTest { public static UsernamePasswordCredentials myCreds = null; public static String userName = "username"; public static String password = "password"; public static String server = "YourHostOrIpAddress"; /** * @param args */ public static void main(String[] args) throws Exception { @SuppressWarnings("deprecation") Protocol myhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443); HttpClient client = new HttpClient(); final HttpState state = client.getState(); final HttpClientParams params = client.getParams(); GetMethod httpget = null; try { if (userName.length() > 0 && password.length() > 0) { myCreds = new UsernamePasswordCredentials(userName, password); params.setAuthenticationPreemptive(true); state.setCredentials(AuthScope.ANY, myCreds); client.getHostConfiguration().setHost(server, 443, myhttps); httpget = new GetMethod("/api/traveler/approvedapps"); BufferedReader in = null; client.executeMethod(httpget); if (httpget.getStatusCode() == 200) { in = new BufferedReader(new InputStreamReader( httpget.getResponseBodyAsStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } } in.close(); } } finally { httpget.releaseConnection(); } } }