Java SDK: ClassCastException when casting to javax.net.ssl.HttpsURLConnection in SFOAuthService

  • 1
  • Problem
  • Updated 3 months ago
  • (Edited)
Using the ShareFile Java SDK 3.1.5 I get a ClassCasstException in SFOAuthService:authenticate on the following line: 
connection = (HttpsURLConnection)SFConnectionManager.openConnection(e)
I assume it occurs because it expects a javax.net.ssl.HttpsURLConnection, but as we use weblogic the openConnection(e)-call returns a weblogic.net.http.HttpsURLConnection, which cannot be cast to javax.net.ssl.HttpsURLConnection. Both classes extends java.net.HttpURLConnection.

Telling weblogic to use the Sun Http-handler by adding the line below works, but it is not a preferable option as our system has multiple Http-integrations.
set JAVA_OPTIONS=%JAVA_OPTIONS% -DUseSunHttpHandler=true
Another option seems to be replacing the SFOAuthService-class with my own implementation that casts to weblogic.net.http.HttpsURLConnection or simply a java.net.HttpURLConnection, but do anyone have any other suggestions?
Photo of Øystein Molnes

Øystein Molnes

  • 8 Posts
  • 0 Reply Likes

Posted 4 months ago

  • 1
Photo of Nilesh Pawar

Nilesh Pawar

  • 10 Posts
  • 1 Reply Like
@Øystein Molnes   Currently there is no other option than to do the explicit casting. Going forward SFConnectionManager  will be depreacated and replaced it with a connection factory which deals with a generic interface IHttpsConnection allowing us to switch between okhttp, HttpsUrlConnection etc. But there is no formal timeline to release this to public SDK yet.
Photo of Øystein Molnes

Øystein Molnes

  • 8 Posts
  • 0 Reply Likes
Thanks for your reply.

Why is the cast done explicitly to javax.net.ssl.HttpsURLConnection in the methods below? Could it rather be a cast to the more generic java.net.HttpURLConnection, which is extended by both sun's and weblogic's implementation of HttpsURLConnection, or does the implementation depend on using the Https class? I see the SFConnectionManager:connect returns the even more generic java.net.URLConnection. 
  • SFOAuthService.authenticate
  • SFUploadRunnable:uploadChunk
  • UploadHelper:getChunkUploadConnection
  • MultiThreadedUploadManager:finalizeUpload


(Edited)