简体   繁体   English

如何创建Web服务代理? 我们可以生成@Endpoints吗?

[英]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). 我正在使用审核进行Web服务代理(后来进行缓存=创建自己的响应),并且我需要生成@Endpoints(这样就可以转发,即调用远程Web服务或虚拟Atleast)。 Marshaling/unmarshaling seems neccessary for the proxy will add "something" to the request... 似乎需要进行编组/拆组,因为代理将在请求中添加“内容”。

We are to use spring-ws and JAXB. 我们将使用spring-ws和JAXB。 Got all XSDs and static WSDLs of the proxied web service. 获得了代理Web服务的所有XSD和静态WSDL。

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: 使用Spring WS和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. 借助Spring WS,您可以为远程WS创建一个代理类,并围绕org.springframework.ws.client.core.WebServiceTemplate与WS进行对话-该WS具有用于将请求编组为xml和解编为XML的API。响应。

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: 使用Spring Integration,您可以使用出站Webservices网关 ,但是您需要在消息传递网关的前面添加该消息传递网关,该网关将充当您的代理,其方式如下:

<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. 但是,我建议您使用WebserviceTemplate的第一种方法,因为这里您不需要非常复杂的集成。

Today I can tell how we proceeded without spring-integration. 今天,我可以说说如何在不进行弹簧整合的情况下进行。 We found two different ways how to generate @Endpoint class. 我们发现了两种不同的方法来生成@Endpoint类。

1) Using XSLT and Freemarker we generated the endpoint class source in pre-compile phase. 1)使用XSLTFreemarker,我们在预编译阶段生成了端点类源。 XSLT transformation walked thru all WSDL files to create one summary file which was then used to generate the source. XSLT转换遍历所有WSDL文件,以创建一个摘要文件,然后该摘要文件用于生成源。

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 . 2)我们使用Javassist复制了模板类,然后生成了有关JAXB2Marshaller实例的内容的方法,最后使用FactoryBean实例化了对象,所有这些都在服务器启动时进行

Problem here we met was set of XSD files written in form that caused the root objects were generated without @XmlRootAnnotation. 我们遇到的问题是,一组XSD文件以某种形式编写,这些文件导致生成的根对象没有@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. 我们内部使用的Javassist版本与Java 1.4兼容(没有泛型),因此我们对XJC使用了全局自定义文件,并对根对象使用了强制@XmlRootAnnotation。

Both solutions have their pros and cons but both are simpler then using ESB. 两种解决方案都有其优点和缺点,但是与使用ESB相比,它们都更简单。

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

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