![](/img/trans.png)
[英]Are there any standard interface for converting Object to String in Java?
[英]Converting Complex Component Interface to Standard Web Service [Java]
我的组件与接受非原始数据或简单POJO的操作具有复杂的接口。
将此组件接口转换为标准的Web服务接口(可由Java和非Java客户端使用)的最佳实践(方法/方法)是什么,以便服务使用者可以使用WSDL毫无问题地生成类。
可以原样使用吗? 如果没有,有没有办法在不影响操作行为的情况下将更改最小化?
组件接口具有以下操作:
/** This is asynchronous method that needs to callback the ResultHandler
interface which has to be implemented by the component user to handle
operationOne result **/
public void operationOne(int id, ResultHandler handler);
/** I think there is no problem with the following operation for Web Services,
when using data contracts. Correct me if I’m wrong! **/
public String operationTwo(int id, MyObject obj);
ResultHandler接口:
/** Note that this handler interface contains InputStream
and Exception as parameters for the handling methods **/
interface ResultHandler {
void onComplete(InputStream is);
void onFailure(IOException ioEx);
}
您可以在网络方法中使用对象,因为它们会转换为复杂的WSDL类型,但是请记住,这只能在一定程度上完成。 您应该具有简单的POJO来传输数据结构,以便获得WSDL /代码生成的好处,而不是要用于执行业务职责的复杂类型。 同样,建议不要使用SOAP Web Services上的REST / JSON。
更新:
有效测试Web服务的唯一方法是为您在Web服务上进行的每个呼叫创建一个Moke。
您需要制作一个可以使用提供的参数来调用组件并返回完整响应的方法。 为了获得最佳结果,该方法不应有副作用。
然后向其添加@WebService和@WebMethod批注,并使用Endpoint.publish(...)创建一个发布该Web服务的小型独立应用程序。 Java 6中的JAX-WS堆栈可以由此自动生成WSDL。
有关执行此操作的完整教程,请参见http://java.dzone.com/articles/jax-ws-hello-world 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.