简体   繁体   中英

How to create a web service proxy? Can we generate @Endpoints?

I'm working on a web-service-proxy with auditing (later on with caching = creating own responses) and I need to generate @Endpoints (such that will just forward ie call a remote web service or dummy atleast). Marshaling/unmarshaling seems neccessary for the proxy will add "something" to the request...

We are to use spring-ws and JAXB. Got all XSDs and static WSDLs of the proxied web service.

Any hints around? Anyone doing something similar? How are you doing it?

Is there a simple way how to achieve this using spring or spring-integration?

Thanks in advance..

This should be possible using both Spring WS and Spring Integration:

With Spring WS, you can create a proxy class for your remote WS, wrapping around a org.springframework.ws.client.core.WebServiceTemplate to talk to the WS - which has API's to take care of marshalling the request to xml and unmarshalling the response.

With Spring Integration, you can use an outbound Webservices gateway , but you will need to front it with a messaging gateway, which will act as your proxy, along these lines:

<int:gateway id="wsproxy"  service-interface="..ProxyInterface" default-request-channel="requestChannel" default-reply-channel="replyChannel"/>

<int-ws:outbound-gateway id="wsGateway" request-channel="requestChannel" uri="http://serviceURL" marshaller="someMarshaller" unmarshaller="someUnmarshaller"/>

However, I would recommend the first approach of using the WebserviceTemplate, as you do not have a very complex integration need here.

Today I can tell how we proceeded without spring-integration. We found two different ways how to generate @Endpoint class.

1) Using XSLT and Freemarker we generated the endpoint class source in pre-compile phase. XSLT transformation walked thru all WSDL files to create one summary file which was then used to generate the source.

2) Using Javassist we copied the template class, then generated methods regarding content of JAXB2Marshaller instance and finally instantiated object using FactoryBean , all at server start-up .

Problem here we met was set of XSD files written in form that caused the root objects were generated without @XmlRootAnnotation. Javassist version we had internally works with Java 1.4 (no generics) so we used global customization file for XJC and forced @XmlRootAnnotation on root objects.

Both solutions have their pros and cons but both are simpler then using ESB.

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