views:

518

answers:

3

I am getting a practical issue and the issue can be dascribed as follows.

We are developing a component (Say a plugin) to do some task when an event is triggered within an external CMS using the API provided by them. They have provided some jar libraries, So what we are doing is implementing an Interface provided by them. Then an internal method is called when an event is triggered. (The CMS is creating only one instance of class when the first event triggers, then it just executes the method with each event trigger)

The function can be summarized as follows,

import com.external.ProvidedInterface;


public class MonitorProgram implements ProvidedInterface{

   public void process(){
      //This method is called when an event is triggered in CMS
   }

}

Within our class we are using "javax.net.ssl.HttpsURLConnection" (JAVA 1.5). But HttpsURLConnection migrated to javax.net.ssl from com.sun.net.ssl for 1.4. But it seems the CMS I am referring to (We dont know their implementation actually) uses something like this

System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

leading to a ClassCastException in our code.

I think my question is clear. In our case we cant set VM parameters,

-Djava.protocol.handler.pkgs=

Also we cant set it back using,

System.setProperty("")

because the VM instance is same for CMS and our program.

What can I do for get this problem resolved? And idea or experiences?

A: 
  1. Find the offending class in the stack trace
  2. Use jad or a similar tool to decompile it.
  3. Fix the name of the property
  4. Compile the resulting file and either replace the .class file in the CMS's jar or put it into a place which is earlier in the classpath.
  5. Use ant to automate this process (well, the compile and build of the JAR; not the decompiling)
  6. When it works, make sure you save everything (original file, changed file, build file) somewhere so you can easily do it again.

While this may sound like a ridiculous or dangerous way to fix the issue, it will work. Especially since your CMS provider doesn't seem to develop his product actively.

Aaron Digulla
We are not authorized to make changes to the CMS provided archives. Even we are not releasing them. It is customers responsibility to obtain those Jar files
Chathuranga Chandrasekara
How about filing a bug report asking them to fix this?
Aaron Digulla
+1  A: 

This is not clear for me.

Do you want to overwrite a system property? You can do this.

Overwrite the System.property before calling the external library method and when the method returns you can set the old System.property back

    final String propertyName = "Property";
    String oldProperty = System.getProperty(propertyName);
    System.setProperty(propertyName,"NEW_VALUE");
    monitorProgram.process();
    System.setProperty(propertyName,oldProperty);

Or do you want to prevent, that the called process overwrites the system.property? And why you can not set the system property by hand?

Markus Lausberg
Hi, I added a comment above with explanation to original post.
Chathuranga Chandrasekara
+1  A: 

I don't think you are going to have much success getting two pieces of code to use different properties.

In your own code however, you can define your own URLStreamHandlerFactory. Doing this will allow you to create a javax.net.ssl.HttpsURLConnection from a URL. While protocol handlers aren't the easiest thing to figure out, I think you can get them to do the job.

See http://java.sun.com/developer/onlineTraining/protocolhandlers/

brianegge