简体   繁体   English

Java SOAP请求作为Web服务?

[英]Java SOAP Request as a Web Service?

So to give you some background, I am trying to create a client that will interact with a third-party via SOAP. 因此,为了给您一些背景知识,我正在尝试创建一个客户端,该客户端将通过SOAP与第三方进行交互。 Initially I started to roll this out using javax.xml.soap SAAJ but then realized there are no options for timeouts when creating a SOAPConnection. 最初,我开始使用javax.xml.soap SAAJ进行了部署,但是后来意识到创建SOAPConnection时没有超时选项。

I considered AXIS which does have timeouts but have been warned to try and avoid and it's not great performance wise. 我考虑了AXIS,它确实有超时,但是已被警告尝试避免,并且它不是很好的性能选择。 My higher-ups seems to be putting this as a last restort. 我的上流人士似乎把这当作最后的重犯。

Some have suggested that javax.xml.ws Web Service route works great as you can put in the context properties the time-out settings, only if it is a web service. 有人建议javax.xml.ws Web服务路由可以很好地工作,因为您可以在上下文属性中放入超时设置(仅当它是Web服务时)。

So here is the situation, the third-party I'm sending requests to doesn't really have a WSDL file or URL, the original idea was to build up the SOAP request and send it, would have worked great if SAAJ had timeout settings. 因此,在这种情况下,我向其发送请求的第三方实际上并没有WSDL文件或URL,最初的想法是建立并发送SOAP请求,如果SAAJ设置了超时设置,效果很好。

So I'm thinking and forgive me for my ignorance, is that could I model and implement the communication like a Web Service instead of the SAAJ javax.xml.soap method of building the request up? 因此,我在考虑并原谅我的无知,是否可以像构建Web Service那样建模和实现通信,而不是像SAAJ那样构建请求的javax.xml.soap方法? If so, can anyone really point me out? 如果是这样,有人能真正指出我吗? Most documents I find seem to rely on generating stubs and classes from a WSDL. 我发现大多数文档似乎都依赖于从WSDL生成存根和类。

This is all really for the sake of setting a time-out setting for connections to this third-party SOAP API. 实际上,所有这些都是为了为与该第三方SOAP API的连接设置超时设置。

Also note, I've seen some people suggest to try and treat it like a HttpConnection where you can set timeouts but the downside I found was it no longer returns a SOAPMessage type object. 还要注意,我看到有人建议尝试将其视为HttpConnection,您可以在其中设置超时,但是我发现的缺点是它不再返回SOAPMessage类型的对象。

So basically I'm trying to change this: 所以基本上我想改变这个:

    SOAPMessage soapMessage       = messageFactory.createMessage();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    SOAPPart soapPart         = soapMessage.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPHeader soapHeader     = soapEnvelope.getHeader();
    SOAPBody soapBody         = soapEnvelope.getBody();
    ....
    soapConnection.call(soapMessage, url);

Into something more like web service so I can do this: 进入更像Web服务的东西,所以我可以这样做:

requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 2000); 
requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 2000);

myService.callMyRemoteMethodWith(myParameter1, myparameter2);

I really am lacking knowledge about the javax.ws framework so please go lightly :) 我确实缺乏有关javax.ws框架的知识,所以请放轻松:)

The client jar files (stubs) can't be created without a WSDL. 没有WSDL,就无法创建客户端jar文件(存根)。 Simply put, and I think you'd know this, WSDL is the nucleus around any web service implementation. 简而言之,我想您会知道的,WSDL是任何Web服务实现的核心。

Creating a WSDL for the remote service would not be advisable until the remote service publishes it, simply because it may not be viable in the long run. 在远程服务发布WSDL之前,不建议为其创建WSDL,这仅仅是因为从长远来看它可能不可行。 Tomorrow if the parameters of this third party request change, would you be willing to spend effort and time for the corresponding changes in the WSDL? 明天如果此第三方请求的参数发生更改,您是否愿意为WSDL中的相应更改花费精力和时间? It would result in plenty of maintenance. 这将导致大量维护。

I think your basic need is that a SOAPMessage type object should be returned and I guess you should be looking at ways to implement the timeout keeping your current approach intact. 我认为您的基本需求是应该返回SOAPMessage类型的对象,并且我想您应该在寻找实现超时的方法以保持当前方法不变。

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

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