Can A Web Service Take An Abstract Class As A Parameter?

I am new to J2EE and web services so please excuse me if I am clumsy with my terminology.

I am developing a web service using JAX-WS. I want the parameter to be an abstract class because I want to pass a composite object (composite pattern). The parameter should be the abstract component class so I can pass either a node or a leaf. Is this possible?

I have tried two methods already:

1) Implement the composite classes in a seperate package called "myserver.messages" that both the client and server use.

2) Put the composite's class implementations directly in the server source and try to get the client to generate all of the class artifacts for the composite (component, leaf and composite classes).

I am using NetBeans 5.5 to generate my client and the artifacts used to connect to the web service.

In both cases I end up with only the abstract component class artifact being generated. I cannot pass the concrete leaf or composite object to the web service operation. The first case gives me an error because the parameter is defined as an abstract class from the client package and the parameter that Im actually passing was from the myserver.messages pacakge. The second case gives me an error because it doesn't know what the leaf and composite classes are that Im trying to instantiate.

Id be happy to clarify if I was unclear. If anyone happens to know where reference material related to this question may be then please let me know. Thanks in advance!

Justin

[1531 byte] By [jphilli9a] at [2007-11-27 5:32:02]
# 1

I think my problem might be more general. I am having trouble passing any class that I define (classes that are not part of the JAVA api) as a parameter to a web service operation. Is there any reference material on how this is done? All I could find was the hello world example in the JAX-WS tutorial that takes a java String as a parameter. thanks

Justin

jphilli9a at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Look at the JAXB 2.1 XmlSeeAlso annotation and the JAX-WS supplychain sample.
dkohlerta at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
When you refer to the supplychain example do you mean the Coffe Break Application (Ch 36) in the Java EE 5 Tutorial?
jphilli9a at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Ah, I found the supplychain example. I thought you might have been refering to the coffe break example because it forms a supply chain from the customer through the coffe break server to the distributor. I didnt know that there was a JAX-WS 2.1.1 which has a whole bunch of good examples. Thanks

jphilli9a at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Hi Justin,

I had the same problem as you. I am using a Web Services generated by another department in my company and all I had was the WSDL. Generated classes from the WSDL.

Lots of abstract classes where they expected you to pass in concrete classes. I got the same error on the server side, it was trying to instantiate the abstract class, not the concrete class I sent in.

Came across this blog that helped me a lot:

http://weblogs.java.net/blog/kohlert/archive/2006/10/jaxws_and_type.html

Turns out, you need to set a @XmlSeeAlso annotation on your generated JAXB classes. You need JAXB 2.1 to do this.

For me, all I had to do was to switch to JAXB 2.1 from JAXB 2.0. My code generation tool (JBoss's wsimport tool) did the rest. It put in the @XmlSeeAlso annotations in the right place.

Check out the blog for details. Hope this helps.

Joe

jizzoea at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Thanks, that does help. That is exactly what I need to do. Does jax-ws and jaxb 2.1 work on the Java application server platform edition 9, update 1? When I tried to deploy my project using the XmlSeeAlso annotation I got errors. I read the documentation for JAX-WS 2.1 and it says you need Glassfish

Promoted Build v2 41a.

jphilli9a at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
If you want to use AS 9 update 1 you will have to update it with the latest jars from jax-ws 2.1.1 or use Glassfish v2 beta. You can get JAX-WS at http://jax-ws.dev.java.net and Glassfish from http://glassfish.dev.jave.net.
dkohlerta at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8

My issue is about passing a Java Object to web service operation as parameter.

When I code the webservice operation to accept java class object as parameter, the webservice project is not getting deployed (It complies). I Use Netbeans 5.5 and Sun Java System Application Server 9.

I get the message ?b>Problem encountered during annotation processing?/b> in Application server console. If I change, the paramenter to ArrayList or string it gets deployed.

Please find the webservice code with annotation and Transfer object . Hope that some body had experinced the same before. Please advice.

import to.TestTO;

import javax.ejb.Stateless;

import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebService;

@Stateless()

@WebService()

public class TestTOWS {

/**

* Web service operation

*/

@WebMethod

public String addTestToByObject(@WebParam(name = "testTo") TestTO testTo) {

// TODO implement operation

System.out.println("Inside addTestToByObject");

return testTo.getName();

}

}

Here is the transfer object JavaBean.

package to;

public class TestTO {

/** Creates a new instance of TestTO */

public TestTO() {

}

private int id;

private String name;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

}

Here is the Log

Problem encountered during annotation processing;

see stacktrace below for more information.

java.lang.NullPointerException

at com.sun.tools.ws.processor.modeler.annotation.WebServiceAP.isSubtype(WebServiceAP.java:418)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceAP.isRemote(WebServiceAP.java:413)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisitor.isLegalType(WebServiceVisitor.java:817)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisitor.isLegalParameter(WebServiceVisitor.java:710)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisitor.isLegalMethod(WebServiceVisitor.java:669)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisitor.methodsAreLegal(WebServiceVisitor.java:624)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisitor.isLegalImplementation(WebServiceVisitor.java:542)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisitor.shouldProcessWebService(WebServiceVisitor.java:352)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisitor.visitClassDeclaration(WebServiceVisitor.java:145)

at com.sun.tools.apt.mirror.declaration.ClassDeclarationImpl.accept(ClassDeclarationImpl.java:95)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceAP.buildModel(WebServiceAP.java:347)

at com.sun.tools.ws.processor.modeler.annotation.WebServiceAP.process(WebServiceAP.java:232)

at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(AnnotationProcessors.java:60)

at com.sun.tools.apt.comp.Apt.main(Apt.java:454)

at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:448)

at com.sun.tools.apt.main.Main.compile(Main.java:1075)

at com.sun.tools.apt.main.Main.compile(Main.java:938)

at com.sun.tools.apt.Main.processing(Main.java:95)

at com.sun.tools.apt.Main.process(Main.java:85)

at com.sun.tools.apt.Main.process(Main.java:67)

at com.sun.tools.ws.wscompile.CompileTool.buildModel(CompileTool.java:605)

at com.sun.tools.ws.wscompile.CompileTool.run(CompileTool.java:538)

at com.sun.tools.ws.util.ToolBase.run(ToolBase.java:56)

at com.sun.tools.ws.util.WSToolsObjectFactoryImpl.wsgen(WSToolsObjectFactoryImpl.java:44)

at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1820)

at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2089)

at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:396)

at com.sun.enterprise.deployment.backend.EjbModuleDeployer.deploy(EjbModuleDeployer.java:138)

at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:160)

at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)

at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)

at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)

at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:266)

at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:739)

at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:174)

at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:210)

error: compilation failed, errors should have been reported

wsgen successful

wsgen successful

Message was edited by:

ahamedkabir_SCR

Message was edited by:

ahamedkabir_SCR

Message was edited by:

ahamedkabir_SCR

Message was edited by:

ahamedkabir_SCR

ahamedkabir_SCRa at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9

I got rid of the annotation issue. I am using netbeans 5.5.1. When i tried to creatre the webservice from a web project, it worked fine for me. If we use ejb project to create the webservice, there are deplyoment issues with annotation. When you test the client make sure to use the generated annotated value objects to contact the webservice methods.

ahamedkabir_SCRa at 2007-7-12 14:57:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...