tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samwun9988 <leiwun2...@gmail.com>
Subject Re: Can't invoke web service
Date Tue, 13 Sep 2011 15:25:47 GMT
Hi, I am not sure how to invoke a remote web service call in Junit Test with
OpenEJB?
I have implemented two methods, one is add(x,y) which is just a local web
service function; another one is findAll() which is calling a remote web
service located in a remote JBOSS AS7 web server.

During junit testing, add(x,y) method returns the correct result, which
means the web service class is being called correctly.

but when the junit test invoked findAll() method, it couldn't found the
method and thrown the following error:



> -------------------------------------------------------------------------------
> Test set: org.superbiz.calculator.CalculatorTest
> -------------------------------------------------------------------------------
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 14.85 sec
> <<< FAILURE!
> testCategoryManagerViaRemoteInterface(org.superbiz.calculator.CalculatorTest) 
> Time elapsed: 14.757 sec  <<< ERROR!
> javax.ejb.EJBException: The bean encountered a non-application exception;
> nested exception is: 
>         java.lang.RuntimeException: Error reading XMLStreamReader.
>         at
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:363)
>         at
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:288)
>         at $Proxy73.findAll(Unknown Source)
>         at
> org.superbiz.calculator.CalculatorTest.testCategoryManagerViaRemoteInterface(CalculatorTest.java:122)
>         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:597)
>         at junit.framework.TestCase.runTest(TestCase.java:168)
>         at junit.framework.TestCase.runBare(TestCase.java:134)
>         at junit.framework.TestResult$1.protect(TestResult.java:110)
>         at junit.framework.TestResult.runProtected(TestResult.java:128)
>         at junit.framework.TestResult.run(TestResult.java:113)
>         at junit.framework.TestCase.run(TestCase.java:124)
>         at junit.framework.TestSuite.runTest(TestSuite.java:232)
>         at junit.framework.TestSuite.run(TestSuite.java:227)
>         at
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
>         at
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
>         at
> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
>         at
> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
>         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:597)
>         at
> org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
>         at $Proxy0.invoke(Unknown Source)
>         at
> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
>         at
> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
>         at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
> Caused by: java.lang.RuntimeException: Error reading XMLStreamReader.
>         at
> org.superbiz.calculator.CategoryManagerImpl.findAll(CategoryManagerImpl.java:47)
>         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:597)
>         at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
>         at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
>         at
> org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:174)
>         at
> org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:93)
>         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:597)
>         at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
>         at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
>         at
> org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:129)
>         at
> org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:45)
>         at
> org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:66)
>         at
> org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:72)
>         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:597)
>         at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
>         at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
>         at
> org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:130)
>         at
> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:226)
>         at
> org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:178)
>         at
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:255)
>         at
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:235)
>         at
> org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:92)
>         at
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:284)
>         ... 27 more
>  

Here is the method in my junit test class:



> CategoryManagerLocal cat = (CategoryManagerLocal)
> initialContext.lookup("CategoryManagerImplLocal");
>         assertEquals(2, cat.add(1, 1));
>         System.out.println("Result: "+cat.add(1,1)); // <-- this method
> returns 2.
>          System.out.println("Size: "+cat.findAll().size()); // <-- here it
> thrown error exception.
> 

CategoryManagerLocal.java file:



> package org.superbiz.calculator;
> 
> import ix.houseware.category.service.CategorySubcategories;
> import java.util.Collection;
> import javax.ejb.Local;
> 
> @Local
> public interface CategoryManagerLocal {
>     Collection<CategorySubcategories> findAll();
> //    Collection<CategorySubcategories> find(final String name, final
> String desc);
>     int add(int a, int b);
> }
> 

CategoryManagerImpl.java file:



> @Stateless
> //@WebService(name = "CategoryWebService", targetNamespace =
> "http://service.category.houseware.ix/")
> @WebService(
>         portName = "CategoryWebServiceImplPort",
>         serviceName = "CategoryManagerWebService",
>         targetNamespace = "http://service.category.houseware.ix/",
>         endpointInterface =
> "ix.houseware.category.service.CategoryWebService")
> //@LocalBean
> public class CategoryManagerImpl implements CategoryWebService,
> CategoryManagerLocal {
> //    @WebServiceRef(wsdlLocation =
> "META-INF/wsdl/www.ixsystems.com.au/category-ws-0.0.1-SNAPSHOT/services.wsdl")
>     @WebServiceRef(wsdlLocation =
> "http://www.ixsystems.com.au/category-ws-0.0.1-SNAPSHOT/services?wsdl")
>     private CategoryWebService_Service service;
>     
> //    private static final Logger logger =
> Logger.getLogger(CategoryManagerImpl.class);
> 
>     @Override
>     public List<CategorySubcategories> findAll() {
>         List<CategorySubcategories> result = new
> ArrayList<CategorySubcategories>();
>         try { // Call Web Service Operation
>             ix.houseware.category.service.CategoryWebService port =
> service.getCategoryWebServiceImplPort();
>             result = port.findAll();
> //            logger.info("Result = " +result.toString());
>             System.out.println("Result = "+result);
>         } catch (Exception ex) {
>             throw new RuntimeException(ex.getMessage()); // <-- here it
> thrown error exception.
>         }
>         return result;
>     }
>     
>       
>     @Override
>             public int add(int a, int b) {
>                 return a+b;
>     }
> 
>     @Override
>     public void createCategory(String name, String desc) {
>         throw new UnsupportedOperationException("Not supported yet.");
>     }
> 
> }
> 
> 

CategoryWebService.java file:



> 
> package ix.houseware.category.service;
> 
> import java.util.List;
> import javax.jws.Oneway;
> import javax.jws.WebMethod;
> import javax.jws.WebParam;
> import javax.jws.WebResult;
> import javax.jws.WebService;
> import javax.xml.bind.annotation.XmlSeeAlso;
> import javax.xml.ws.RequestWrapper;
> import javax.xml.ws.ResponseWrapper;
> 
> 
> /**
>  * This class was generated by the JAX-WS RI.
>  * JAX-WS RI 2.1.3-b02-
>  * Generated source version: 2.1
>  * 
>  */
> @WebService(name = "CategoryWebService", targetNamespace =
> "http://service.category.houseware.ix/")
> @XmlSeeAlso({
>     ObjectFactory.class
> })
> public interface CategoryWebService {
> 
> 
>     /**
>      * 
>      * @return
>      *     returns
> java.util.List<ix.houseware.category.service.CategorySubcategories>
>      */
>     @WebMethod
>     @WebResult(targetNamespace = "")
>     @RequestWrapper(localName = "findAll", targetNamespace =
> "http://service.category.houseware.ix/", className =
> "ix.houseware.category.service.FindAll")
>     @ResponseWrapper(localName = "findAllResponse", targetNamespace =
> "http://service.category.houseware.ix/", className =
> "ix.houseware.category.service.FindAllResponse")
>     public List<CategorySubcategories> findAll();
> 
>     /**
>      * 
>      * @param desc
>      * @param name
>      * @return
>      *     returns
> java.util.List<ix.houseware.category.service.CategorySubcategories>
>      */
>     @WebMethod
>     @WebResult(targetNamespace = "")
>     @RequestWrapper(localName = "find", targetNamespace =
> "http://service.category.houseware.ix/", className =
> "ix.houseware.category.service.Find")
>     @ResponseWrapper(localName = "findResponse", targetNamespace =
> "http://service.category.houseware.ix/", className =
> "ix.houseware.category.service.FindResponse")
>     public List<CategorySubcategories> find(
>         @WebParam(name = "name", targetNamespace = "")
>         String name,
>         @WebParam(name = "desc", targetNamespace = "")
>         String desc);
> 
>     /**
>      * 
>      * @param desc
>      * @param name
>      */
>     @WebMethod
>     @Oneway
>     @RequestWrapper(localName = "createCategory", targetNamespace =
> "http://service.category.houseware.ix/", className =
> "ix.houseware.category.service.CreateCategory")
>     public void createCategory(
>         @WebParam(name = "name", targetNamespace = "")
>         String name,
>         @WebParam(name = "desc", targetNamespace = "")
>         String desc);
> 
> }
> 
> 
What is wrong with my code and / or project setup?


Thanks
Sam

--
View this message in context: http://openejb.979440.n4.nabble.com/Can-t-invoke-web-service-tp3804670p3810367.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Mime
View raw message