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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to