Note that there are some explanatory texts on larger screens.

plurals
  1. PODefine WebFault in a different namespace / package than the service one (using cxf / jax-ws)
    text
    copied!<p>I'm using jax-ws with cxf implementation to implement web services.<br> I have several services annotated with the @WebService annotation.<br> In a different package I defined the exceptions (which inherit from RuntimeException) and annotated them with @WebFault with a unique namespace. Each exception class holds a single bean with the exception data (faultInfo) which resides in the same namespace and package as the fault and is annotated with @XMlType.<br> Example:<br> Fault Class: </p> <pre><code>@WebFault(name = "GeneralRemoteFault", targetNamespace = WebServices.MyNamespace) public class GeneralRemoteFault extends RuntimeException { private GeneralRemoteFaultException faultInfo; public GeneralRemoteFault(String message, GeneralRemoteFaultException faultInfo) { super(message); this.faultInfo = faultInfo; } public GeneralRemoteFault(String message, GeneralRemoteFaultException faultInfo, Throwable cause) { super(message, cause); this.faultInfo = faultInfo; } public GeneralRemoteFaultException getFaultInfo() { return faultInfo; } } </code></pre> <p>Fault Bean: (With package-info which puts it in WebServices.MyNamespace namespace) </p> <pre><code>@XmlType(name = "GeneralRemoteFaultException ") public class GeneralRemoteFaultException { private String objId; public GeneralRemoteFaultException () {} public GeneralRemoteFaultException (String objId) { this.objId = objId; } public String getObjId() { return objId; } public void setObjId(String objId) { this.objId = objId; } } </code></pre> <p>The service method:</p> <pre><code>List&lt;ValidationErrors&gt; validateObject( @WebParam(name = "object") ValidationObject object, @WebParam(name = "groups") String[] groups) throws GeneralRemoteFault; </code></pre> <p>When I run the server CXF complain with the following error:</p> <pre><code>ERROR org.apache.cxf.service.factory.ReflectionServiceFactoryBean.fillInSchemaCrossreferences:305 [main] - Schema element {http://www.example.com/schema}ValidationRemoteFault references undefined type {http://www.example.com/schema}ValidationRemoteFaultException for service {http://web_services.example.com/}ValidationService </code></pre> <p>After debugging the code which run the service I've noticed that the schema collection (XmlSchemaCollection.schemas) doesn't include the namespace of the fault bean and that is why it fails (it contains only the service one's and the fault one's). It seems that CXF doesn't take into account the option that the fault bean will be defined in a separate namespace than the others and doesn't loads the fault bean schema into the schema collection. Even if I put the fault bean together in the same namespace with the fault (as defined above), the schema (XmlSchema) for the namespace won't include the JAXB types only the faults.</p> <p>Any insight about solving the error will be appreciated.</p> <p>This is the stack of where the message pops from:</p> <pre><code>at org.apache.ws.commons.schema.XmlSchemaCollection.getTypeByQName(XmlSchemaCollection.java:229) at org.apache.cxf.common.xmlschema.SchemaCollection.getTypeByQName(SchemaCollection.java:109) at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.fillInSchemaCrossreferences(ReflectionServiceFactoryBean.java:301) at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:269) - locked &lt;0x1670&gt; (a org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:205) at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101) at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159) at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:207) at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:442) - locked &lt;0x1678&gt; (a org.apache.cxf.jaxws22.EndpointImpl) at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:329) at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:246) </code></pre> <p>Thanks,<br> Avner</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload