1 2 Previous Next 27 Replies Latest reply on Mar 2, 2007 11:53 AM by maeste

    WSContractConsumer API in a seam app

    maeste

      Hi,
      We are rewriting the core of our generic web based ws client (I spoke about it here some days ago) using a more standard and mantainable core based on JAX-WS and in particular on WSContractConsumer runtime API.
      We already done the most important steps of the job and all our test cases works perfectly.
      Now we are experincing problems when we deploy our apps (a seam ear) on jboss 4.0.5 with, of course, jbossws from the svn trunk.
      The problem is that WSContractConsumer doesn't generate .class file (but .java is generated correctly) when used inside the jboss container. The same class used out of container by our junit test case works perfectly.
      Here is the init method of our class:

      public void init(String wsdlURL) {
       try {
       WSContractConsumer wsImporter = WSContractConsumer.newInstance();
       wsImporter.setGenerateSource(true);
       File outputDir = new File("/home/oracle/testImp/tmp/");
       wsImporter.setOutputDirectory(outputDir);
       wsImporter.setSourceDirectory(outputDir);
       String tagetPkg = "it.javalinux.ws";// + (new Random()).nextInt();
       wsImporter.setTargetPackage(tagetPkg);
       wsImporter.consume(wsdlURL);
      
      
       FilenameFilter filter = new FilenameFilter() {
       public boolean accept(File dir, String name) {
       return name.endsWith("Service.class");
       }
       };
       File scanDir = new File("/home/oracle/testImp/tmp/it/javalinux/ws/");
       System.out.println(scanDir);
       String[] a = scanDir.list();
       for (int i = 0; i < a.length; i++) {
       System.out.println(a);
      
       }
      
       String[] children = scanDir.list(filter);
       String className =null;
       if (children != null) {
       className = children[0].substring(0, children[0].length() - 6);
      
       }
      
       classLoader = new URLClassLoader(new URL[]{outputDir.toURL()}, Thread.currentThread().getContextClassLoader());
       //URLClassLoader classLoader = new URLClassLoader(new URL[]{outputDir.toURL()}, Thread.currentThread().getContextClassLoader());
       Thread.currentThread().setContextClassLoader(classLoader);
      
       serviceClass = JavaUtils.loadJavaType("it.javalinux.ws." + className , classLoader);
       service = serviceClass.newInstance();
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
      


      What's happen is, as already said, that we find only .java file in this directory and not .class file. We don't get any exception from WSContractConsumer.

      Any ideas?
      Thanks in advance.

        • 1. Re: WSContractConsumer API in a seam app
          jason.greene

          Is JAVA_HOME pointing to a JRE or a JDK? The jdk tools.jar needs to be on the classpath so that the java compiler can be invoked. I am guessing this is the issue.

          • 2. Re: WSContractConsumer API in a seam app
            maeste

            Yes it is pointing to JDK.
            JRockit jdk (but already tryied sun jdk) 1.5
            And I tryied also to included tools.jar as java module in seam app, but it doesn't work too.
            If I set the JAVA_HOME to jre I get the expected exception:

             java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/jboss/com/sun/tools/ws/wscompile/CompileTool : com/sun/mirror/apt/AnnotationProcessorFactory
             at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
             at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
             at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
             at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:203)
             at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
             at $Proxy172.selectWsdl(Unknown Source)
             at it.javalinux.wise.seam.actions.WSDLManager$$FastClassByCGLIB$$1e4142b3.invoke(<generated>)
             at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
             at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
             at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:74)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
             at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:40)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
             at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
            Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/jboss/com/sun/tools/ws/wscompile/CompileTool : com/sun/mirror/apt/AnnotationProcessorFactory
             at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:174)
             at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
             at org.jboss.seam.interceptors.BijectionInterceptor.bijectNonreentrantComponent(BijectionInterceptor.java:79)
             at org.jboss.seam.interceptors.BijectionInterceptor.bijectComponent(BijectionInterceptor.java:58)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
             at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
             at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:21)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
             at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
             at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:52)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
            Caused by: java.lang.NoClassDefFoundError: org/jboss/com/sun/tools/ws/wscompile/CompileTool : com/sun/mirror/apt/AnnotationProcessorFactory
             at java.lang.ClassLoader.defineClass1(Native Method)
             at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
             at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
             at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
             at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
             at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
             at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
             at org.jboss.mx.loading.RepositoryClassLoader.findClassLocally(RepositoryClassLoader.java:672)
             at org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:652)
             at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClassLocally(RepositoryClassLoader.java:190)
             at org.jboss.mx.loading.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:131)
             at org.jboss.mx.loading.LoadMgr3.nextTask(LoadMgr3.java:399)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:517)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:405)
             at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
             at org.jboss.ws.tools.jaxws.impl.WSContractConsumerFactoryImpl.createImporter(WSContractConsumerFactoryImpl.java:34)
             at org.jboss.ws.tools.jaxws.api.WSContractConsumer.newInstance(WSContractConsumer.java:69)
             at org.jboss.ws.tools.jaxws.api.WSContractConsumer.newInstance(WSContractConsumer.java:56)
             at it.javalinux.wise.jaxCore.WSDynamicClient.init(WSDynamicClient.java:51)
             at it.javalinux.wise.seam.actions.WSDLManagerBean.selectWsdl(WSDLManagerBean.java:108)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
            09:04:19,963 ERROR [DebugPageHandler] redirecting to debug page
            java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/jboss/com/sun/tools/ws/wscompile/CompileTool : com/sun/mirror/apt/AnnotationProcessorFactory
            .......
            


            The most strange thing in my case is I didn't get exception

            Thanks for your time

            • 3. Re: WSContractConsumer API in a seam app
              jason.greene

              Ok, so I would recommend calling setMessageStream() on WSContractConsumer, that will give you any feedback messages that occur during processing.

              • 4. Re: WSContractConsumer API in a seam app
                jason.greene

                Also, when the sun compiler is invoked, it has to have a classpath, and that can't be derived from anything but the java.class.path system property. Whenever an app has advanced classloading, then this property only gives a parial picture of what jars are loaded. So, a likely case is that javac is running, but it's not compiling because a jar was not passed to the classpath. The message stream should report this condition.

                For this reason, there is a setAdditionalCompilerClassPath(), that you can call to place paths to any additional jars you have that are referenced from the source code.

                -Jason

                • 5. Re: WSContractConsumer API in a seam app
                  maeste

                  Ok, I see errors. It's a problem of classpath.
                  Now I have to investigate the problem.
                  I'll keep you informed
                  Thank you very much for the tip.

                  • 6. Re: WSContractConsumer API in a seam app
                    maeste

                    Hi Jason,
                    your hints helped me a lot in finding and solving problem in dynamic class generation.
                    Now it seems ok and all the apps seems to work not bad (well we still have some point open, but it basically works).
                    One of the opened points is about class loading when we use jaxws generated class to call webservices.
                    Generated class is always loaded correctly and also library (putted in ear and loaded as java module in application.xml using an isolated classloader in jboss-app) works perfectly after a fresh startup of the server.
                    The problem is on finding class in library's jars after an hot deployment. It doesn't work and we get a ClassNotFoundException (not always the same calss) when we invoke the endpoint operation.

                    Our class loading related code is:

                    classLoader = new URLClassLoader(new URL[]{outputDir.toURL()}, Thread.currentThread().getContextClassLoader());
                     URLClassLoader classLoader = new URLClassLoader(new URL[]{outputDir.toURL()}, Thread.currentThread().getContextClassLoader());
                     Thread.currentThread().setContextClassLoader(classLoader);
                    
                     serviceClass = JavaUtils.loadJavaType("it.javalinux.ws." + className , classLoader);
                     service = serviceClass.newInstance();
                    


                    The use of loaded class and other classes generated by wsConctractConsumer is in other methods of our utility class created and used by a Seam' Stateful bean.

                    We tried also to be more rude:
                    Properties prop = new Properties();
                    // BEGIN
                     SecurityAssociation.setPrincipal(new SimplePrincipal("admin"));
                     SecurityAssociation.setCredential("admin".toCharArray());
                     // END
                     prop.put( "java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" );
                     prop.put( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );
                     prop.put( "java.naming.provider.url", "jnp://localhost:1099");
                     InitialContext ctx = new InitialContext(prop);
                     RMIAdaptor rmiserver = (RMIAdaptor) ctx.lookup("jmx/invoker/RMIAdaptor");
                     ObjectName onameBean = new ObjectName("seam.jboss.org:loader=Wise");
                     rmiserver.invoke(onameBean, "newClassLoader" , new Object[]{outputDir.toURL(),true}, new String[]{"java.net.URL","boolean"});
                    
                    


                    But we get the same error.

                    Any other useful hint?
                    Thanks in advance

                    • 7. Re: WSContractConsumer API in a seam app
                      jason.greene

                       

                      "maeste" wrote:
                      Hi Jason,
                      The problem is on finding class in library's jars after an hot deployment. It doesn't work and we get a ClassNotFoundException (not always the same calss) when we invoke the endpoint operation.

                      You mention that the invocation fails. Does the service class actually load successfully? Are you caching object references?

                      Is this code running in container? Are you hot deploying the client code? If so, the output folder will cease to exist after a hot deploy. The reason is that when you deploy your app its extracted in a tmp directory. Any relative file writes go there. When you redeploy a new directory is created, and thus the classes would be gone. If this is the case then you either need to regenerate them per redeploy, or store them in some absolute path name.



                      Our class loading related code is:
                      classLoader = new URLClassLoader(new URL[]{outputDir.toURL()}, Thread.currentThread().getContextClassLoader());
                       URLClassLoader classLoader = new URLClassLoader(new URL[]{outputDir.toURL()}, Thread.currentThread().getContextClassLoader());
                       Thread.currentThread().setContextClassLoader(classLoader);
                      
                       serviceClass = JavaUtils.loadJavaType("it.javalinux.ws." + className , classLoader);
                       service = serviceClass.newInstance();
                      


                      Be careful when replacing the context loader when running in a container. If you do this you should restore the original thread context loader.

                      -Jason

                      • 8. Re: WSContractConsumer API in a seam app
                        maeste

                         

                        "jason.greene@jboss.com" wrote:

                        You mention that the invocation fails. Does the service class actually load successfully? Are you caching object references?


                        Ok, let me explain a little:
                        Our app (called Wise, take a look to javalinuxlabs.org if you like to understand better ideas behind) generate client on the fly. I mean that it generate client code when you select a wsdls. Then the client code is generated and a generic web based interface too. After an hot deployment you have to restart the navigation flow and other client class wll be generated. No cache and no generated class reusing.

                        Is this code running in container? Are you hot deploying the client code? If so, the output folder will cease to exist after a hot deploy. The reason is that when you deploy your app its extracted in a tmp directory. Any relative file writes go there. When you redeploy a new directory is created, and thus the classes would be gone. If this is the case then you either need to regenerate them per redeploy, or store them in some absolute path name.

                        Yes I know. I think all things are done considering all jboss deployment standards. Just for clarify: we don't have problem loading our generated class, but (after redeployment) we experiences problem in loading classes of jbossws or javax.* contained in jars deployed inside the ear apps.
                        Here is my complete utility class (sorry, this is becoming a long post):
                        /*
                         * Created on 11/02/2007
                         *
                         * To change the template for this generated file go to
                         * Window - Preferences - Java - Code Generation - Code and Comments
                         */
                        package it.javalinux.wise.jaxCore;
                        
                        import [...]
                        public class WSDynamicClient {
                        
                         private Class serviceClass;
                         private Class endPointClass;
                        
                        
                         private Object service;
                         private Object endPoint;
                         URLClassLoader classLoader;
                        
                         private Map<String, Method> endPoints;
                        
                         private Map<String, Method> webMethods;
                        
                         private String tmpDeployDir;
                        
                         public void init(String wsdlURL, String cid,String userName, String password) {
                         try {
                         WSContractConsumer wsImporter = WSContractConsumer.newInstance();
                         wsImporter.setGenerateSource(true);
                         //wsImporter.setMessageStream(System.out);
                         setCurrentTmpDeployDir();
                         System.out.println(tmpDeployDir);
                         List<String> cp = defineAdditionalCompilerClassPath();
                         wsImporter.setAdditionalCompilerClassPath(cp);
                        
                        
                         File outputDir = new File(tmpDeployDir + "/WSDLS/" + cid);
                         if (!outputDir.exists()) {
                         outputDir.mkdir();
                         }
                         wsImporter.setOutputDirectory(outputDir);
                         wsImporter.setSourceDirectory(outputDir);
                         String targetPkg = "it.javalinux.ws";
                         wsImporter.setTargetPackage(targetPkg);
                         wsImporter.consume(getUsableWSDL(wsdlURL,userName,password));
                        
                         String className = getServiceClassName(outputDir);
                         Properties prop = new Properties();
                        // BEGIN
                         SecurityAssociation.setPrincipal(new SimplePrincipal("admin"));
                         SecurityAssociation.setCredential("admin".toCharArray());
                         // END
                         prop.put( "java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" );
                         prop.put( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );
                         prop.put( "java.naming.provider.url", "jnp://localhost:1099");
                         InitialContext ctx = new InitialContext(prop);
                         RMIAdaptor rmiserver = (RMIAdaptor) ctx.lookup("jmx/invoker/RMIAdaptor");
                         ObjectName onameBean = new ObjectName("seam.jboss.org:loader=Wise");
                         rmiserver.invoke(onameBean, "newClassLoader" , new Object[]{outputDir.toURL(),true}, new String[]{"java.net.URL","boolean"});
                         //classLoader = new URLClassLoader(new URL[]{outputDir.toURL()}, Thread.currentThread().getContextClassLoader());
                         //URLClassLoader classLoader = new URLClassLoader(new URL[]{outputDir.toURL()}, Thread.currentThread().getContextClassLoader());
                         //Thread.currentThread().setContextClassLoader(classLoader);
                        
                         serviceClass = JavaUtils.loadJavaType("it.javalinux.ws." + className , classLoader);
                         service = serviceClass.newInstance();
                         } catch (Exception e) {
                         e.printStackTrace();
                         }
                         }
                        
                         private String getUsableWSDL(String wsdlURL, String userName, String password) {
                         if (StringUtils.trimToNull(userName) == null || StringUtils.trimToNull(password) == null) {
                         return wsdlURL;
                         }
                         return null;
                         }
                        
                         private String getServiceClassName(File outputDir) {
                         String className =null;
                         FilenameFilter filter = new FilenameFilter() {
                         public boolean accept(File dir, String name) {
                         return name.endsWith("Service.class");
                         }
                         };
                         File scanDir = new File(outputDir.getAbsolutePath() + "/it/javalinux/ws/");
                         System.out.println(scanDir);
                        
                         String[] children = scanDir.list(filter);
                        
                         if (children != null) {
                         className = children[0].substring(0, children[0].length() - 6);
                        
                         }
                         return className;
                         }
                        
                         private List<String> defineAdditionalCompilerClassPath() {
                         List<String> cp = new LinkedList<String>();
                         cp.add(tmpDeployDir + "jboss-jaxws.jar");
                         cp.add(tmpDeployDir + "jaxb-api.jar");
                         cp.add(tmpDeployDir + "jaxb-impl.jar");
                         cp.add(tmpDeployDir + "jaxb-xjc.jar");
                         return cp;
                         }
                        
                         private void setCurrentTmpDeployDir() {
                         tmpDeployDir = Thread.currentThread().getContextClassLoader().getResource("jboss-jaxws.jar").getPath().substring(5);
                         tmpDeployDir = tmpDeployDir.substring(0, tmpDeployDir.lastIndexOf("!")) + "-contents/" ;
                        
                         }
                        
                         public List<String> getEndPointList() {
                         endPoints = new HashMap<String, Method>();
                         for (Method method : serviceClass.getMethods()) {
                         WebEndpoint annotation = method.getAnnotation(WebEndpoint.class);
                         if (annotation != null) {
                         endPoints.put(annotation.name(),method);
                         }
                         }
                         return new ArrayList<String>(endPoints.keySet());
                         }
                        
                         public void selectEndPoint(String name) throws Exception {
                        
                         Method method = endPoints.get(name);
                         endPoint = serviceClass.getMethod(method.getName(), method.getParameterTypes()).invoke(service, (Object[]) null);
                         endPointClass = serviceClass.getMethod(method.getName(), method.getParameterTypes()).getReturnType();
                         }
                        
                         public List<String> getWebMethod() {
                         webMethods = new HashMap<String, Method>();
                        
                         for (Method method : endPointClass.getMethods()) {
                         WebMethod annotation = method.getAnnotation(WebMethod.class);
                         if (annotation != null) {
                         webMethods.put(annotation.action(),method);
                         }
                         }
                        
                         return new ArrayList<String>(webMethods.keySet());
                         }
                        
                         public Object invokeOperation(String methodName, Object[] args) throws Exception {
                         Method methodToInvoke = webMethods.get(methodName);
                         return endPoint.getClass().getMethod(methodToInvoke.getName(),methodToInvoke.getParameterTypes()).invoke(endPoint, args);
                         }
                        
                         public List<WebParameter> getWebParams(String methodName) {
                         LinkedList<WebParameter> parameters = new LinkedList<WebParameter>();
                         Method method = webMethods.get(methodName);
                         Annotation[][] annotations = method.getParameterAnnotations();
                         Class[] methodparameterTypes = method.getParameterTypes();
                         for (int i = 0; i < annotations.length; i++) {
                         for (int j = 0; j < annotations.length; j++) {
                         if (annotations[j] instanceof WebParam ) {
                         parameters.add(new WebParameter(methodparameterTypes,((WebParam) annotations[j]).name()));
                         break;
                         }
                         }
                         }
                         return parameters;
                        
                         }
                        
                        }
                        
                        


                        Be careful when replacing the context loader when running in a container. If you do this you should restore the original thread context loader.

                        -Jason

                        • 9. Re: WSContractConsumer API in a seam app
                          maeste

                          Ops, something went wrong in my last post and the final part of my message doesn't be visible:

                          "jason.greene@jboss.com" wrote:


                          Be careful when replacing the context loader when running in a container. If you do this you should restore the original thread context loader.

                          -Jason

                          I suspected it is too aggressive. What is the best way to tell the current class loader to include also my generated client class?

                          Many many tanks for your time

                          • 10. Re: WSContractConsumer API in a seam app
                            jason.greene

                             

                            "maeste" wrote:
                            Ops, something went wrong in my last post and the final part of my message doesn't be visible:
                            "jason.greene@jboss.com" wrote:


                            Be careful when replacing the context loader when running in a container. If you do this you should restore the original thread context loader.

                            -Jason

                            I suspected it is too aggressive. What is the best way to tell the current class loader to include also my generated client class?

                            Many many tanks for your time


                            You don't actually need to mess with the context classloader. Once a class is loaded you can freely pass the class reference around. The JVM associates the class reference to the loader that loaded it, and that loader is preserved until all class references are garbage collected. The only scenario to replace a context loader is if you are using an API that uses it, and doesnt offer a mechanism to pass the loader directly. However, when you do this you must use a try finally block that restores the context loader to the original version.

                            So, your problems might go away if remove the context loader assignment, and the RMIAdaptor hack.

                            • 11. Re: WSContractConsumer API in a seam app
                              maeste

                              Hi Jason,
                              sorry to bore you one more, but last night I made some tests and problem still in place.

                              Probably I misunderstood your suggestion, but if I remove the contextCalssloader setting line I get a ClassNotFoundException on one of wsContractConsumer generated class calling the getXXXPort method on generated *Service class.

                              It was the reason that drive me to change the contextClassLoader.
                              Are there some better ways?
                              And was I able to explain what I'm trying to do?

                              Thanks a lot

                              • 12. Re: WSContractConsumer API in a seam app
                                jason.greene

                                Apparently we do use the context loader on the client side. So you will need to change it, however restore it immediately after obtaining the port:

                                ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
                                
                                Foo foo;
                                
                                try
                                {
                                 Thread.currentThread().setContextClassLoader(newLoader);
                                 foo = FooService.getPort();
                                }
                                finally
                                {
                                 Thread.currentThread().setContextClassLoader(oldLoader);
                                }
                                
                                


                                Make sure to remove the JMX classloader calls as well. If it still fails I would need to see the stack trace of the CNFE.

                                -Jason

                                • 13. Re: WSContractConsumer API in a seam app
                                  maeste

                                  Thanks. I try it immediatly. I'll keep you post

                                  • 14. Re: WSContractConsumer API in a seam app
                                    maeste

                                    No luck. I changed as suggested the method selectEndPoint in my class (posted in a previous message)
                                    Here is the stack trace:

                                    strUrl: MatchingPort
                                    21:42:58,674 ERROR [STDERR] java.lang.reflect.InvocationTargetException
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,675 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,675 ERROR [STDERR] at it.javalinux.wise.jaxCore.WSDynamicClient.selectEndPoint(WSDynamicClient.java:181)
                                    21:42:58,675 ERROR [STDERR] at it.javalinux.wise.seam.actions.WSDLManagerBean.readOperations(WSDLManagerBean.java:147)
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,675 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.seam.interceptors.BijectionInterceptor.bijectNonreentrantComponent(BijectionInterceptor.java:79)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.seam.interceptors.BijectionInterceptor.bijectComponent(BijectionInterceptor.java:58)
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,675 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,675 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
                                    21:42:58,675 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
                                    21:42:58,676 ERROR [STDERR] at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:36)
                                    21:42:58,676 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,677 ERROR [STDERR] Caused by: org.jboss.ws.WSException: Cannot load java type: it.javalinux.ws.SmaugWSException_Exception
                                    21:42:58,677 ERROR [STDERR] at org.jboss.ws.metadata.umdm.FaultMetaData.getJavaType(FaultMetaData.java:144)
                                    21:42:58,677 ERROR [STDERR] at org.jboss.ws.core.jaxws.DynamicWrapperGenerator.generate(DynamicWrapperGenerator.java:138)
                                    21:42:58,677 ERROR [STDERR] at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.addFault(JAXWSMetaDataBuilder.java:296)
                                    21:42:58,677 ERROR [STDERR] at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.processWebMethod(JAXWSMetaDataBuilder.java:745)
                                    21:42:58,677 ERROR [STDERR] at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.processWebMethods(JAXWSMetaDataBuilder.java:763)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.ws.metadata.builder.jaxws.JAXWSClientMetaDataBuilder.rebuildEndpointMetaData(JAXWSClientMetaDataBuilder.java:205)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPortInternal(ServiceDelegateImpl.java:207)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPort(ServiceDelegateImpl.java:148)
                                    21:42:58,678 ERROR [STDERR] at javax.xml.ws.Service.getPort(Service.java:116)
                                    21:42:58,678 ERROR [STDERR] at it.javalinux.ws.MatchingService.getMatchingPort(MatchingService.java:56)
                                    21:42:58,678 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,678 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,678 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,678 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,678 ERROR [STDERR] at it.javalinux.wise.jaxCore.WSDynamicClient.selectEndPoint(WSDynamicClient.java:181)
                                    21:42:58,678 ERROR [STDERR] at it.javalinux.wise.seam.actions.WSDLManagerBean.readOperations(WSDLManagerBean.java:147)
                                    21:42:58,678 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,678 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,678 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,678 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.seam.interceptors.BijectionInterceptor.bijectNonreentrantComponent(BijectionInterceptor.java:79)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.seam.interceptors.BijectionInterceptor.bijectComponent(BijectionInterceptor.java:58)
                                    21:42:58,678 ERROR [STDERR] Caused by: java.lang.ClassNotFoundException: it.javalinux.ws.SmaugWSException_Exception
                                    21:42:58,678 ERROR [STDERR] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                                    21:42:58,678 ERROR [STDERR] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                                    21:42:58,678 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                                    21:42:58,678 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.ws.core.utils.JavaUtils.loadJavaType(JavaUtils.java:148)
                                    21:42:58,678 ERROR [STDERR] at org.jboss.ws.metadata.umdm.FaultMetaData.getJavaType(FaultMetaData.java:134)
                                    21:42:58,679 ERROR [STDERR] at org.jboss.ws.core.jaxws.DynamicWrapperGenerator.generate(DynamicWrapperGenerator.java:138)
                                    21:42:58,679 ERROR [STDERR] at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.addFault(JAXWSMetaDataBuilder.java:296)
                                    21:42:58,679 ERROR [STDERR] at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.processWebMethod(JAXWSMetaDataBuilder.java:745)
                                    21:42:58,679 ERROR [STDERR] at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.processWebMethods(JAXWSMetaDataBuilder.java:763)
                                    21:42:58,679 ERROR [STDERR] at org.jboss.ws.metadata.builder.jaxws.JAXWSClientMetaDataBuilder.rebuildEndpointMetaData(JAXWSClientMetaDataBuilder.java:205)
                                    21:42:58,679 ERROR [STDERR] at org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPortInternal(ServiceDelegateImpl.java:207)
                                    21:42:58,679 ERROR [STDERR] at org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPort(ServiceDelegateImpl.java:148)
                                    21:42:58,679 ERROR [STDERR] at javax.xml.ws.Service.getPort(Service.java:116)
                                    21:42:58,679 ERROR [STDERR] at it.javalinux.ws.MatchingService.getMatchingPort(MatchingService.java:56)
                                    21:42:58,679 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,679 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,679 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,679 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,679 ERROR [STDERR] at it.javalinux.wise.jaxCore.WSDynamicClient.selectEndPoint(WSDynamicClient.java:181)
                                    21:42:58,679 ERROR [STDERR] at it.javalinux.wise.seam.actions.WSDLManagerBean.readOperations(WSDLManagerBean.java:147)
                                    21:42:58,679 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,679 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,679 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,679 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,679 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                                    21:42:58,680 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                                    21:42:58,680 ERROR [STDERR] java.lang.NullPointerException:
                                    21:42:58,681 ERROR [STDERR] at it.javalinux.wise.jaxCore.WSDynamicClient.getWebMethod(WSDynamicClient.java:192)
                                    21:42:58,681 ERROR [STDERR] at it.javalinux.wise.seam.actions.WSDLManagerBean.readOperations(WSDLManagerBean.java:152)
                                    21:42:58,681 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,681 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,681 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,681 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,681 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                                    21:42:58,681 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                                    21:42:58,681 ERROR [STDERR] at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
                                    21:42:58,681 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
                                    21:42:58,681 ERROR [STDERR] at org.jboss.seam.interceptors.BijectionInterceptor.bijectNonreentrantComponent(BijectionInterceptor.java:79)
                                    21:42:58,681 ERROR [STDERR] at org.jboss.seam.interceptors.BijectionInterceptor.bijectComponent(BijectionInterceptor.java:58)
                                    21:42:58,681 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,681 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,682 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,682 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,682 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
                                    21:42:58,682 ERROR [STDERR] at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
                                    21:42:58,682 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
                                    21:42:58,682 ERROR [STDERR] at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:36)
                                    21:42:58,682 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    21:42:58,682 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    21:42:58,682 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    21:42:58,682 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                                    21:42:58,682 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
                                    21:42:58,682 ERROR [STDERR] at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
                                    


                                    If you need some more information or you want to see the generated class or the wsdls let me know.

                                    Thank you

                                    1 2 Previous Next