2013-09-25 33 views
2

我的Web服务的一些方法应该向客户端返回自定义例外。但是,在发布端点期间,jax-ws会忽略自定义异常的声明。服务和方法的
描述看起来像(实现此接口具有相同的注解):Jax-ws忽略自定义例外

@WebService(name = "ContainerProxy") 
@SOAPBinding(style = Style.RPC) 
public interface ContainerProxy { 

    @WebMethod 
    public Response processRequest(Request request) throws 
     BadRequestException, // Custom exception 
     ApplicationNotFoundException, // Custom exception 
     ClassNotFoundException, 
     NoSuchMethodException, 
     IllegalAccessException, 
     InvocationTargetException; 
} 

的WSDL生成此服务看起来像:

<?xml... 
    <portType name="ContainerProxyImpl"> 
     <operation name="processRequest"> 
      <input wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequestRequest" 
       message="tns:processRequest"></input> 
      <output wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequestResponse" 
       message="tns:processRequestResponse"></output> 
      <fault message="tns:ClassNotFoundException" name="ClassNotFoundException" 
       wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequest/Fault/ClassNotFoundException"></fault> 
      <fault message="tns:NoSuchMethodException" name="NoSuchMethodException" 
       wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequest/Fault/NoSuchMethodException"></fault> 
      <fault message="tns:IllegalAccessException" name="IllegalAccessException" 
       wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequest/Fault/IllegalAccessException"></fault> 
      <fault message="tns:InvocationTargetException" name="InvocationTargetException" 
       wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequest/Fault/InvocationTargetException"></fault> 
     </operation> 
     ... 
    </portType> 
    ... 
    <binding name="ContainerProxyImplPortBinding" type="tns:ContainerProxyImpl"> 
     <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding> 
     <operation name="processRequest"> 
      <soap:operation soapAction=""></soap:operation> 
      <input> 
       <soap:body use="literal"></soap:body> 
      </input> 
      <output> 
       <soap:body use="literal"></soap:body> 
      </output> 
      <fault name="ClassNotFoundException"> 
       <soap:fault name="ClassNotFoundException" use="literal"></soap:fault> 
      </fault> 
      <fault name="NoSuchMethodException"> 
       <soap:fault name="NoSuchMethodException" use="literal"></soap:fault> 
      </fault> 
      <fault name="IllegalAccessException"> 
       <soap:fault name="IllegalAccessException" use="literal"></soap:fault> 
      </fault> 
      <fault name="InvocationTargetException"> 
       <soap:fault name="InvocationTargetException" use="literal"></soap:fault> 
      </fault> 
     </operation> 
     ... 

所以,我怎么能返回自定义异常给客户?

回答

1

问题是由于自定义例外必须是类 Exception或其他延伸Exception的类的扩展。但我不知道它,我的自定义例外是Throwable的扩展。

0

你注释与Web服务类:

@WebService(serviceName = "CustomWsName") 
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT) 
public class WebServiceClass{ 

@WebMethod 
..method... 


} 

或与其他SOAPBinding?

+0

当然可以。我已经更新了这个问题。 –

+0

尝试在我的示例中使用SOAPBinding进行测试。通过这种方式,我可以看到发布的wsdl中包含的自定义异常。 – umanganiello

+0

感谢您的帮助。我已经找到了这个问题的解决方案。 –