You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "javierllorente (via GitHub)" <gi...@apache.org> on 2023/10/13 12:19:10 UTC

[I] Java Web and EE's jersey conflicts with user-contributed plugin's jersey [netbeans]

javierllorente opened a new issue, #6566:
URL: https://github.com/apache/netbeans/issues/6566

   ### Apache NetBeans version
   
   Apache NetBeans 19
   
   ### What happened
   
   If you enable the "Java Web and EE" feature, the "REST Client" plugin stops working.
   I think it is because of having different `jersey` versions in the classpath; 
   `2.34`* (Java Web and EE) vs `3.1.3`* (REST Client).
   
   *https://github.com/apache/netbeans/blob/master/enterprise/websvc.restlib/src/org/netbeans/modules/websvc/swdp/swdp.xml
   *https://github.com/javierllorente/netbeans-rest-client/blob/main/pom.xml
   
   
   `java.lang.ClassCastException: class org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable cannot be cast to class org.glassfish.jersey.internal.spi.AutoDiscoverable (org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable is in unnamed module of loader org.netbeans.StandardModule$OneModuleClassLoader @7c185a1b;`
   
   ### How to reproduce
   
   1. Install "REST Client" from the plugin manager
   2. Open a new tab (Tools -> REST Client)
   3. Type in any REST URL
   4. Observe you get the response
   5. Enable "Java Web and EE" feature (Tools -> Plugins -> Installed)
   6. Repeat 3.
   7. Observe you get an exception. Response is not displayed
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   openSUSE Tumbleweed 20230902
   
   ### JDK
   
   17.0.8.1
   
   ### Apache NetBeans packaging
   
   Apache NetBeans provided installer, Other
   
   ### Anything else
   
   ```
   SEVERE [org.openide.util.RequestProcessor]: Error in RequestProcessor com.javierllorente.netbeans.rest.client.ui.RestClientTopComponent$$Lambda$1103/0x00007f9fdc8b8ed8
   java.lang.ClassCastException: class org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable cannot be cast to class org.glassfish.jersey.internal.spi.AutoDiscoverable (org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable is in unnamed module of loader org.netbeans.StandardModule$OneModuleClassLoader @7c185a1b; org.glassfish.jersey.internal.spi.AutoDiscoverable is in unnamed module of loader org.netbeans.StandardModule$OneModuleClassLoader @5bf2b5a1)
   	at java.base/java.util.TreeMap.put(TreeMap.java:795)
   	at java.base/java.util.TreeMap.put(TreeMap.java:534)
   	at java.base/java.util.TreeSet.add(TreeSet.java:255)
   	at java.base/java.util.AbstractCollection.addAll(AbstractCollection.java:336)
   	at java.base/java.util.TreeSet.addAll(TreeSet.java:309)
   	at org.glassfish.jersey.model.internal.CommonConfig.configureAutoDiscoverableProviders(CommonConfig.java:613)
   	at org.glassfish.jersey.client.ClientConfig$State.configureAutoDiscoverableProviders(ClientConfig.java:390)
   	at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:445)
   	at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:317)
   	at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:834)
   	at org.glassfish.jersey.client.ClientRequest.getClientRuntime(ClientRequest.java:181)
   	at org.glassfish.jersey.client.JerseyWebTarget.onBuilder(JerseyWebTarget.java:371)
   	at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:199)
   	at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:38)
   	at com.javierllorente.netbeans.rest.client.RestClient.request(RestClient.java:187)
   	at com.javierllorente.netbeans.rest.client.ui.RestClientTopComponent.lambda$request$4(RestClientTopComponent.java:284)
   	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1419)
   	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
   	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
   [catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2034)
   ```
   
   ### Are you willing to submit a pull request?
   
   Yes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] Java Web and EE's jersey conflicts with user-contributed plugin's jersey [netbeans]

Posted by "javierllorente (via GitHub)" <gi...@apache.org>.
javierllorente closed issue #6566: Java Web and EE's jersey conflicts with user-contributed plugin's jersey
URL: https://github.com/apache/netbeans/issues/6566


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] Java Web and EE's jersey conflicts with user-contributed plugin's jersey [netbeans]

Posted by "javierllorente (via GitHub)" <gi...@apache.org>.
javierllorente commented on issue #6566:
URL: https://github.com/apache/netbeans/issues/6566#issuecomment-1783756492

   @matthiasblaesing Interesting! This could be also helpful in other situations. Good to know.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] Java Web and EE's jersey conflicts with user-contributed plugin's jersey [netbeans]

Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on issue #6566:
URL: https://github.com/apache/netbeans/issues/6566#issuecomment-1783757738

   Problem and solution seems similar to that described in https://netbeans.apache.org/wiki/main/wiki/DevFaqModuleCCE/ too.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] Java Web and EE's jersey conflicts with user-contributed plugin's jersey [netbeans]

Posted by "javierllorente (via GitHub)" <gi...@apache.org>.
javierllorente commented on issue #6566:
URL: https://github.com/apache/netbeans/issues/6566#issuecomment-1778038844

   Disabling Jersey's feature autodiscovery makes "REST Client" compatible with NetBeans' "Java Web and EE" as suggested by @matthiasblaesing
   `.property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)`
   See https://github.com/apache/netbeans/pull/6582#issuecomment-1773871387


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] Java Web and EE's jersey conflicts with user-contributed plugin's jersey [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on issue #6566:
URL: https://github.com/apache/netbeans/issues/6566#issuecomment-1783264107

   @javierllorente I just found another work around (just FYI):
   
   ```diff
   --- a/src/main/java/com/javierllorente/netbeans/rest/client/RestClient.java
   +++ b/src/main/java/com/javierllorente/netbeans/rest/client/RestClient.java
   @@ -17,10 +17,7 @@
    
    import com.javierllorente.netbeans.rest.client.ui.RestClientOptionsPanel;
    import jakarta.json.stream.JsonGenerator;
   -import jakarta.ws.rs.ClientErrorException;
    import jakarta.ws.rs.HttpMethod;
   -import jakarta.ws.rs.ProcessingException;
   -import jakarta.ws.rs.ServerErrorException;
    import jakarta.ws.rs.client.Client;
    import jakarta.ws.rs.client.ClientBuilder;
    import jakarta.ws.rs.client.Entity;
   @@ -36,6 +33,7 @@
    import java.security.cert.X509Certificate;
    import java.util.List;
    import java.util.Map;
   +import java.util.concurrent.Callable;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.prefs.Preferences;
   @@ -85,6 +83,7 @@
        }
    
        private void buildClient(boolean verifySslCertificates) {
   +        runWithModuleCL(() -> {
            ClientConfig config = new ClientConfig()
                    .connectorProvider(new ApacheConnectorProvider())
                    .property(ClientProperties.CONNECT_TIMEOUT, 20000)
   @@ -94,6 +93,7 @@
            client = verifySslCertificates
                    ? ClientBuilder.newBuilder().withConfig(config).build()
                    : ClientBuilder.newBuilder().sslContext(getSslContext()).withConfig(config).build();
   +        });
        }
        
        private SSLContext getSslContext() {
   @@ -166,8 +166,8 @@
            return "URL: " + uri.toString() + ", status: " + status + ", time: " + time + " ms";
        }
    
   -    public String request(String resource, String method)
   -            throws ClientErrorException, ServerErrorException, ProcessingException {
   +    public String request(String resource, String method) {
   +        return runWithModuleCL(() -> {
            long startTime = System.currentTimeMillis();
            WebTarget target = client.target(resource);
    
   @@ -205,6 +205,7 @@
            }
            
            return str;
   +        });
        }
        
        private Response invoke(Invocation.Builder invocationBuilder, String method) {
   @@ -267,4 +268,29 @@
            return mediaType;
        }
    
   +    private static <V> V runWithModuleCL(Callable<V> c) {
   +        ClassLoader threadContextClassLoader = Thread.currentThread().getContextClassLoader();
   +        try {
   +            Thread.currentThread().setContextClassLoader(RestClient.class.getClassLoader());
   +            return c.call();
   +        } catch (Exception ex) {
   +            if (ex instanceof RuntimeException) {
   +                throw (RuntimeException) ex;
   +            } else {
   +                throw new RuntimeException(ex);
    }
   +        } finally {
   +            Thread.currentThread().setContextClassLoader(threadContextClassLoader);
   +        }
   +    }
   +
   +    private static void runWithModuleCL(Runnable c) {
   +        ClassLoader threadContextClassLoader = Thread.currentThread().getContextClassLoader();
   +        try {
   +            Thread.currentThread().setContextClassLoader(RestClient.class.getClassLoader());
   +            c.run();
   +        } finally {
   +            Thread.currentThread().setContextClassLoader(threadContextClassLoader);
   +        }
   +    }
   +}
   ```
   
   Jersey Client uses the thread context classloader to scan for classes. The NetBeans SystemClassloader is to wide. The idea is now to temporarily replace the thread context classloader with the module classloader (which only references a single jersey client) and resets it after the call. I tested with rest client and it seems to work.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] Java Web and EE's jersey conflicts with user-contributed plugin's jersey [netbeans]

Posted by "javierllorente (via GitHub)" <gi...@apache.org>.
javierllorente commented on issue #6566:
URL: https://github.com/apache/netbeans/issues/6566#issuecomment-1783932025

   Thanks Matthias and thanks Neil for your help!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists