0

I'm trying to use URL Fetch API to make Https requests to my backend service.

I'm using HttpsURLConnection because my backend is using a self-signed certificate and I need to validate that certificate as trusted.

This snippet

...
URL url = new URL("https://example.com/api");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(sslContext.getSocketFactory());

throws

java.lang.ClassCastException: com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection cannot be cast to javax.net.ssl.HttpsURLConnection

I know that App Engine employs its own handler for url.openConnection() which returns a sibling to HttpsURLConenction, which is why the cast fails.

Is there a way for me to use HttpsURLConnection with URLfetch? Are there other options to connect to my backend via Https?

Tony Tang
  • 93
  • 1
  • 1
  • 5
  • Have a look at http://stackoverflow.com/questions/17866754/dropbox-java-api-with-gwt-authentication-problems this looks similar to me. – pradex Oct 19 '15 at 17:08
  • You can enable / disable certificate validation in the urlfetch low level api (https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/urlfetch/FetchOptions). That won't work for self signed certificates though... Also http://stackoverflow.com/questions/4939701/can-i-use-urlfetch-with-self-signed-certifications-over-ssl – konqi Oct 19 '15 at 17:22
  • Thanks for the links. Seems like `HttpsURLConnection` is simply unsupported... I thought it would be possible because appengine white lists HttpsURLConnection. I guess I'll have to get a CA for my backend then – Tony Tang Oct 19 '15 at 17:40

0 Answers0