I want to create a WebService with a wsdl based on interfaces. The annotation
XmlJavaTypeAdapter seems not to work. Here are my interfaces:
@XmlJavaTypeAdapter(GreetingImpl.Adapter.class)
public interface Greeting {
public void setMessage(String msg);
public String getMessage();
}
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface HelloWorldService {
@WebMethod
public Greeting getGreeting(String name);
}
And here are my classes:
public class GreetingImpl implements Greeting {
private String message;
public String getMessage()
{ return message;}
public void setMessage(String message)
{ this.message = message;}
public static class Adapter extends XmlAdapter < GreetingImpl, Greeting > {
public Greeting unmarshal(GreetingImpl v)
{ return v;}
public GreetingImpl marshal(Greeting v)
{ return (GreetingImpl) v;}
}
}
@WebService(serviceName = "HelloWorldWebService", portName =
"HelloWorldWebService", endpointInterface = "hello.HelloWorldService")
public class HelloWorldServiceImpl implements HelloWorldService{
public Greeting getGreeting(String name)
{ Greeting result = new GreetingImpl(); result.setMessage("Hello " + name); return result; }
}
The Error I get is:
Server Runtime Error: javax.xml.ws.WebServiceException
at
com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:269)
at
com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:87)
at
com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:59)
at javax.xml.ws.Endpoint.publish(Endpoint.java:156)
at HelloWorldServiceTest.beforeTest(HelloWorldServiceTest.java:54)
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.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at
org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at
org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.xml.ws.WebServiceException
at
com.sun.xml.internal.ws.model.RuntimeModel.createJAXBContext(RuntimeModel.java:201)
at com.sun.xml.internal.ws.model.RuntimeModel.postProcess(RuntimeModel.java:79)
at
com.sun.xml.internal.ws.modeler.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:255)
at
com.sun.xml.internal.ws.server.RuntimeEndpointInfo.createSEIModel(RuntimeEndpointInfo.java:170)
at
com.sun.xml.internal.ws.server.RuntimeEndpointInfo.init(RuntimeEndpointInfo.java:317)
at
com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:298)
at
com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:263)
... 24 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1
counts of IllegalAnnotationExceptions
hello.Greeting is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at hello.Greeting
at
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:361)
at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:217)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
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 com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:76)
at com.sun.xml.internal.ws.model.RuntimeModel$1.run(RuntimeModel.java:196)
at java.security.AccessController.doPrivileged(Native Method)
at
com.sun.xml.internal.ws.model.RuntimeModel.createJAXBContext(RuntimeModel.java:193)
... 30 more
this comes from jaxb-ri as JAXBContext context = JAXBContext.newInstance(Greeting.class, GreetingImpl.class, GreetingImpl.Adapter.class); fails as well
I want to create a WebService with a wsdl based on interfaces. The annotation XmlJavaTypeAdapter seems not to work. Here are my interfaces:
@XmlJavaTypeAdapter(GreetingImpl.Adapter.class) public interface Greeting { public void setMessage(String msg); public String getMessage(); }
@WebService @SOAPBinding(style = SOAPBinding.Style.RPC) public interface HelloWorldService { @WebMethod public Greeting getGreeting(String name); }
And here are my classes:
public class GreetingImpl implements Greeting { private String message;
public String getMessage()
{ return message;}
public void setMessage(String message)
{ this.message = message;}
public static class Adapter extends XmlAdapter < GreetingImpl, Greeting > {
public Greeting unmarshal(GreetingImpl v)
{ return v;}
public GreetingImpl marshal(Greeting v)
{ return (GreetingImpl) v;}
} }
@WebService(serviceName = "HelloWorldWebService", portName = "HelloWorldWebService", endpointInterface = "hello.HelloWorldService") public class HelloWorldServiceImpl implements HelloWorldService{
public Greeting getGreeting(String name)
{ Greeting result = new GreetingImpl(); result.setMessage("Hello " + name); return result; }
}
The Error I get is:
Server Runtime Error: javax.xml.ws.WebServiceException at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:269) at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:87) at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:59) at javax.xml.ws.Endpoint.publish(Endpoint.java:156) at HelloWorldServiceTest.beforeTest(HelloWorldServiceTest.java:54) 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.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74) at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33) at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75) at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45) at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66) at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: javax.xml.ws.WebServiceException at com.sun.xml.internal.ws.model.RuntimeModel.createJAXBContext(RuntimeModel.java:201) at com.sun.xml.internal.ws.model.RuntimeModel.postProcess(RuntimeModel.java:79) at com.sun.xml.internal.ws.modeler.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:255) at com.sun.xml.internal.ws.server.RuntimeEndpointInfo.createSEIModel(RuntimeEndpointInfo.java:170) at com.sun.xml.internal.ws.server.RuntimeEndpointInfo.init(RuntimeEndpointInfo.java:317) at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:298) at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:263) ... 24 more Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions hello.Greeting is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at hello.Greeting
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:361) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:217)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
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 com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:76)
at com.sun.xml.internal.ws.model.RuntimeModel$1.run(RuntimeModel.java:196)
at java.security.AccessController.doPrivileged(Native Method)
at
com.sun.xml.internal.ws.model.RuntimeModel.createJAXBContext(RuntimeModel.java:193)
... 30 more
Environment
Operating System: Windows XP Platform: All
Affected Versions
[2.1.2]
Source: https://github.com/javaee/metro-jax-ws/issues/383 Author: glassfishrobot