Hi
Can someone help me with this please?
The function returning a List without any generic.
public List getAnyClass(@WebParam(name = "gid")String gid);
We would like to have it this way because we have 55 classes, many of which do
not have a common parent class that we can use in the generics for List<...>.
We cannot use an interface either, because it does not seem to work.
We are declaring all the classes using
props.put("jaxb.additionalContextClasses", classes);
and these classes appear in the WSDL.
Regards
Rahul
The detailed codebase with the exception is given below
[email protected]
Rahul Dev <[EMAIL PROTECTED]> wrote: Hi
Your suggestion works to an extent, but the following codebase still gives
problems:
public class Company implements Serializable {
private static final long serialVersionUID = 1L;
public String gid;
public String Name;
}
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
public String gid;
public String lastName;
public String firstName;
public Set privileges;
}
@WebService
public interface AuthService {
//Can contain any serializable class
public List getAnyClass(@WebParam(name = "gid")String gid);
}
@WebService(endpointInterface = "com.company.auth.service.AuthService",
serviceName = "corporateAuthService")
public class AuthServiceImpl implements AuthService {
public List getAnyClass(String gid) {
List Ret = new ArrayList();
Employee EmployeeObj = new Employee();
EmployeeObj.gid = gid;
EmployeeObj.lastName = "bond";
EmployeeObj.firstName = "james";
Ret.add(EmployeeObj);
Company CompanyObj = new Company();
CompanyObj.gid = gid;
CompanyObj.Name = "MI5";
Ret.add(EmployeeObj);
return Ret;
}
}
public class Server {
public static void main(String[] args) {
AuthServiceImpl implementor = new AuthServiceImpl();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setServiceClass(AuthService.class);
svrFactory.setAddress("http://localhost:9000/authService");
svrFactory.setServiceBean(implementor);
svrFactory.getInInterceptors().add(new LoggingInInterceptor());
svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
//Define the serializable classes
Class classes[] = new Class[] {Employee.class, Company.class};
HashMap props = new HashMap();
props.put("jaxb.additionalContextClasses", classes);
svrFactory.setProperties(props);
svrFactory.create();
}
}
public final class Client {
private Client() {
}
public static void main(String args[]) throws Exception {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(AuthService.class);
factory.setAddress("http://localhost:9000/authService");
AuthService client = (AuthService) factory.create();
List Employees = client.getAnyClass("0223938");
System.out.println("Server said: " + Employees.size());
System.exit(0);
}
}
I get the following exception:
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element
(uri:"", local:"return"). Expected elements are (none)
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:552)
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:465)
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:105)
at
org.apache.cxf.interceptor.DocLiteralInInterceptor.getPara(DocLiteralInInterceptor.java:235)
at
org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:120)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:449)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2029)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1865)
at
org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:170)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:593)
at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
at $Proxy33.getAnyClass(Unknown Source)
at com.company.auth.client.Client.main(Client.java:26)
Kindly advice.
Thanks
Rahul
Daniel Kulp wrote:
Are you using ServerFactoryBean or are you using a JAX-WS
style "Endpoint.publish"?
Basically, you need to set the property:
jaxb.additionalContextClasses
to a Class[].
For that ServerFactoryBean stuff, just call:
Class classes[] = .......
bean.getProperties().put("jaxb.additionalContextClasses"
classes);
before you call create().
For the other case, I'm not sure, but I think you do:
Endpoint ep = Endpoint.create(....);
ep.setProperty("jaxb.additionalContextClasses"
classes);
ep.publish(...);
Alternatively, we do have samples in the docs on how to set the databinding
programmaticly (look in the Aegis databinding section). You can create your
own instance of JAXBDataBinding, call the setAdditionalClass(...) method, set
that into the factory, etc....
Dan
On Wednesday 20 August 2008 1:12:17 am Rahul Dev wrote:
> Thanks Dan for your mail.
>
> The server is started as a standalone server. Is there a way by which we
> can use API's to register these 55 classes manually inside the standalone
> source code?
>
> Managing external XML files for these would be difficult from a maintenance
> point.
>
> We are dynamically detecting the classes during bootup and would like to
> have all these classes dynamically loaded.
>
> Rahul
>
> Daniel Kulp wrote:
> Are you talking about JAXB databinding?
>
> If so, there are a couple options:
>
> 1) Add the XmlSeeAlso annotation to the interface and point it at all 55
> classes.
>
> 2) If at least one class in the package containing the 55 classes is picked
> up via a parameter on another method or something, you can put a jaxb.index
> file in the package that is just a list of all the class names (minus the
> package).
>
> 3) There is also a jaxb.extraclasses property that can be added to the
> configuration of the endpoint to have it load additional classes. See:
> http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/resources/extra
>jaxbclass.xml
>
> Dan
>
> On Tuesday 19 August 2008 11:43:15 am Rahul Dev wrote:
> > Hi,
> >
> > I have a WS interface that looks like this
> > public List getResults(Date FromDate, Date ToDate);
> >
> > The problem is that List can return any of the 55 java pojo model classes
> > that we have defined. None of these implement any interface either.
> >
> > When I generate WSDL, I would like all these 55 classes to appear in the
> > XSD so that the client can recognize them.
> >
> > Because the return type is List and the list can contain any object that
> > implements Serializable, the client can never know what objects can come.
> >
> > Is there a way by which I can define these 55 custom classes?
> > Rahul
--
Daniel Kulp
[EMAIL PROTECTED]
http://www.dankulp.com/blog