简体   繁体   English

将复杂组件接口转换为标准Web服务[Java]

[英]Converting Complex Component Interface to Standard Web Service [Java]

I have component that has complex interface with operations accepting non-primitive data or simple POJO. 我的组件与接受非原始数据或简单POJO的操作具有复杂的接口。

What is the best practice (ways/methodologies) to convert this component interface to be standard Web Service interface that can be consumed by java and non-java clients, so that the service consumer can generate classes without problem using WSDL. 将此组件接口转换为标准的Web服务接口(可由Java和非Java客户端使用)的最佳实践(方法/方法)是什么,以便服务使用者可以使用WSDL毫无问题地生成类。

Can be used as it's? 可以原样使用吗? if not, is there a way to minimal change it without affecting operations' behavior? 如果没有,有没有办法在不影响操作行为的情况下将更改最小化?

The component interface has operations like: 组件接口具有以下操作:

/** 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);

The ResultHandler interface: 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); 
}

You can use your objects in the webmethods, as they are converted to complex WSDL types, but keep in mind that this can only be done to a degree. 您可以在网络方法中使用对象,因为它们会转换为复杂的WSDL类型,但是请记住,这只能在一定程度上完成。 You should have simple POJO's to transmit the data structures so that you get the benefit of the WSDL/code generation not the complex types you will be using to perform your business duties. 您应该具有简单的POJO来传输数据结构,以便获得WSDL /代码生成的好处,而不是要用于执行业务职责的复杂类型。 Also a peace of advice, should REST/JSON over SOAP Web Services. 同样,建议不要使用SOAP Web Services上的REST / JSON。

UPDATE: 更新:

The only way to effectively test your web services is by creating a moke for every call you have on your web service. 有效测试Web服务的唯一方法是为您在Web服务上进行的每个呼叫创建一个Moke。

Moq - How to mock web service call? Moq-如何模拟Web服务调用?

You need to make a method that can invoke the component with the provided arguments and return a complete response. 您需要制作一个可以使用提供的参数来调用组件并返回完整响应的方法。 For best results that method should not have side-effects. 为了获得最佳结果,该方法不应有副作用。

Then add @WebService and @WebMethod annotations to it, and use Endpoint.publish(...) to create a small stand alone application publishing that web service. 然后向其添加@WebService和@WebMethod批注,并使用Endpoint.publish(...)创建一个发布该Web服务的小型独立应用程序。 The JAX-WS stack in Java 6 can autogenerate the WSDL from this. Java 6中的JAX-WS堆栈可以由此自动生成WSDL。

See http://java.dzone.com/articles/jax-ws-hello-world for a full tutorial for doing this. 有关执行此操作的完整教程,请参见http://java.dzone.com/articles/jax-ws-hello-world

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM