简体   繁体   中英

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.

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.

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:

/** 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. 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. Also a peace of advice, should REST/JSON over SOAP Web Services.

UPDATE:

The only way to effectively test your web services is by creating a moke for every call you have on your web service.

Moq - How to mock web service call?

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. The JAX-WS stack in Java 6 can autogenerate the WSDL from this.

See http://java.dzone.com/articles/jax-ws-hello-world for a full tutorial for doing this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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