Failed to return Java object !
ericmacau May 12, 2006 3:57 AMHello,
Can JBossWS return a Java object(Java Bean) ? When I try to return a bean, it just raised the following exception. But those primitive types and String are no problem at all. The following are my codes:
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.rpc.Service;
import eric.ws.reales.CategoryInterface;
import eric.ws.reales.ProductCategory;
/**
* Client.java
*
* @author Chao Hoi Ka, Eric
*
*/
public class Client {
private static CategoryInterface port;
/**
* @param args
*/
public static void main(String[] args) {
try {
InitialContext iniCtx = getInitialContext();
Service service = (Service) iniCtx
.lookup("java:comp/env/service/CategoryService");
port = (CategoryInterface) service.getPort(CategoryInterface.class);
port.addCategory(1, "testing", "tesing again");
port.addCategory(1, "testingx", "tesing againx");
System.out.println("<<<<"+port.echo("welcome"));
ProductCategory cat = port.findById(1);
System.out.println(">>>>" + cat.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
protected static InitialContext getInitialContext(String clientName)
throws NamingException {
InitialContext iniCtx = new InitialContext();
Hashtable env = iniCtx.getEnvironment();
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
env.put("j2ee.clientName", clientName);
return new InitialContext(env);
}
/**
* Get the client's env context
*/
protected static InitialContext getInitialContext() throws NamingException {
return getInitialContext("jbossws-client");
}
}
....
@WebMethod
public ProductCategory findById(long id) {
Object obj = em.find(ProductCategory.class, id);
if (obj != null) {
return (ProductCategory)obj;
} else {
return null;
}
}
...
The following are the generated codes by wstools.
/*
* JBossWS WS-Tools Generated Source
*
* Generation Date: Fri May 12 15:50:00 GMT+08:00 2006
*
* This generated source code represents a derivative work of the input to
* the generator that produced it. Consult the input for the copyright and
* terms of use that apply to this source code.
*/
package eric.ws.reales;
public class ProductCategory
{
protected java.lang.String description;
protected long id;
protected java.lang.String name;
protected eric.ws.reales.Collection products;
public ProductCategory(){}
public ProductCategory(java.lang.String description, long id, java.lang.String name, eric.ws.reales.Collection products){
this.description=description;
this.id=id;
this.name=name;
this.products=products;
}
public java.lang.String getDescription() { return description ;}
public void setDescription(java.lang.String description){ this.description=description; }
public long getId() { return id ;}
public void setId(long id){ this.id=id; }
public java.lang.String getName() { return name ;}
public void setName(java.lang.String name){ this.name=name; }
public eric.ws.reales.Collection getProducts() { return products ;}
public void setProducts(eric.ws.reales.Collection products){ this.products=products; }
}
/*
* JBoss, the OpenSource EJB server
* Distributable under LGPL license. See terms of license at gnu.org.
*/
//Auto Generated by jbossws - Please do not edit!!!
package eric.ws.reales;
import javax.xml.rpc.*;
public interface CategoryService extends javax.xml.rpc.Service
{
public eric.ws.reales.CategoryInterface getCategoryInterfacePort() throws ServiceException;
}
/*
* JBossWS WS-Tools Generated Source
*
* Generation Date: Fri May 12 15:50:00 GMT+08:00 2006
*
* This generated source code represents a derivative work of the input to
* the generator that produced it. Consult the input for the copyright and
* terms of use that apply to this source code.
*/
package eric.ws.reales;
public interface CategoryInterface extends java.rmi.Remote
{
public void addCategory(long long_1,java.lang.String string_1,java.lang.String string_2) throws java.rmi.RemoteException;
public void deleteCategory(long long_1) throws java.rmi.RemoteException;
public java.lang.String echo(java.lang.String string_1) throws java.rmi.RemoteException;
public eric.ws.reales.ProductCategory findById(long long_1) throws java.rmi.RemoteException;
public eric.ws.reales.ProductCategory findByName(java.lang.String string_1) throws java.rmi.RemoteException;
public void updateCategory(long long_1,java.lang.String string_1,java.lang.String string_2) throws java.rmi.RemoteException;
}
java.rmi.RemoteException: Call invocation failed with code [Client] because of: javax.xml.rpc.JAXRPCException: Cannot create or send response message; nested exception is: javax.xml.rpc.soap.SOAPFaultException: javax.xml.rpc.JAXRPCException: Cannot create or send response message at org.jboss.ws.jaxrpc.CallImpl.invokeInternal(CallImpl.java:715) at org.jboss.ws.jaxrpc.CallImpl.invoke(CallImpl.java:398) at org.jboss.ws.jaxrpc.CallProxy.invoke(CallProxy.java:164) at $Proxy2.findById(Unknown Source) at test.Client.main(Client.java:46) Caused by: javax.xml.rpc.soap.SOAPFaultException: javax.xml.rpc.JAXRPCException: Cannot create or send response message at org.jboss.ws.jaxrpc.SOAPFaultExceptionHelper.getSOAPFaultException(SOAPFaultExceptionHelper.java:100) at org.jboss.ws.binding.soap.SOAPBindingProvider.unbindResponseMessage(SOAPBindingProvider.java:505) at org.jboss.ws.jaxrpc.CallImpl.invokeInternal(CallImpl.java:704) ... 4 more