简体   繁体   English

JAX-WS-将WebServiceContext注入仅具有@Oneway方法的@WebService中

[英]JAX-WS - inject WebServiceContext into @WebService that only has @Oneway methods

I'm on SAP NetWeaver 7.3 EHP 1 (JEE5 certified) and I've genereated a Web Service skeleton for an existing WSDL. 我使用的是SAP NetWeaver 7.3 EHP 1(已通过JEE5认证),并且已经为现有WSDL生成了Web服务框架。 All methods in this Webservice are non-blocking and thus annotated with @Oneway . 此Webservice中的所有方法都是非阻塞的,因此使用@Oneway注释。 The service itself works just fine. 该服务本身工作正常。

I also need to access an injected WebServiceContext though, and this is where the trouble starts. 我还需要访问注入的WebServiceContext ,这是麻烦开始的地方。 I can inject the context just fine, but every call to it just ends up in server-specific NPEs or ISEs. 我可以很好地注入上下文,但是对它的每次调用都只能在特定于服务器的NPE或ISE中结束。 I somewhat can understand that since the non-blocking call is executed asynchronously by SAP's JAX-WS implementation. 我有点理解,因为非阻塞调用是由SAP的JAX-WS实现异步执行的。 However, I tried to validate this behaviour by looking at the JAX-WS specification. 但是,我尝试通过查看JAX-WS规范来验证此行为。 Now I'm either blind or the specification doesn't specifically say that a WebServiceContext must not be used in non-blocking web methods. 现在我要么是盲人,要么规范中没有明确指出WebServiceContext不能在非阻塞Web方法中使用。 In fact, in the whole of chapter 5.3 of the latest version of the spec, @Oneway is not mentioned once. 实际上,在该规范最新版本的第5.3章中,没有一次提到@Oneway The main description is 主要描述是

The javax.xml.ws.WebServiceContext interface makes it possible for an endpoint implementation object and potentially any other objects that share its execution context to access information pertaining to the request being served. javax.xml.ws.WebServiceContext接口使端点实现对象以及可能共享其执行上下文的任何其他对象可以访问与正在服务的请求有关的信息。 The result of invoking any methods on the WebServiceContext of a component outside the invocation of one of its web service methods is undefined. 在调用其Web服务方法之一之外的组件的WebServiceContext上调用任何方法的结果是不确定的。 An implementation SHOULD throw a java.lang- .IllegalStateException if it detects such a usage. 如果实现检测到这种用法,则应抛出java.lang- .IllegalStateException。

I guess the point is the definition of "request being served". 我想重点是“正在处理的请求”的定义。 At the time of the asynchronous handling of the SOAP operation, the HTTP request has already finished. 在SOAP操作的异步处理时,HTTP请求已经完成。 But then again, I'm not accessing the context "outside of the invocation of one if its web service methods". 但是话又说回来,我没有访问上下文“如果调用它的Web服务方法之外”。 I'm confused... 我糊涂了...

Does any of you guys know if I should be allowed to access the WebServiceContext in a non-blocking web method? 你们是否有人知道是否应允许我以非阻塞的Web方法访问WebServiceContext Thanks! 谢谢!

You're right: the spec says nothing about this limitation - it's only vaguely implied. 您是对的:规范对此限制一无所知-只是隐含地暗示。

From the JAX-WS spec (2.2 Rev A): 从JAX-WS规范(2.2 Rev A):

The WebServiceContext is treated as an injectable resource that can be set at the time an endpoint is initialized. WebServiceContext被视为可注入的资源,可以在初始化端点时进行设置。 The WebServiceContext object will then use thread-local information to return the correct information regardless of how many threads are concurrently being used to serve requests addressed to the same endpoint object. 然后,WebServiceContext对象将使用线程本地信息返回正确的信息,而不管同时使用多少个线程来服务寻址到同一终结点对象的请求。

Should be operational over the existence of the endpoint, but only if used in the same thread that setup and stored the request contextual information into thread-local memory storage. 应该在存在端点的情况下才可操作,但仅当在与建立请求上下文信息并将其存储到线程本地内存存储的同一线程中使用时才可使用。 Given that WebServiceContext is primarily MessageContext information, which is HTTP Request / Servlet Request / WSDL Operation settings, the thread-local contextual information would probably need to be populated by the thread that initially marshalls the SOAP/HTTP request, meaning that the later async processing thread does not have this info available. 假定WebServiceContext主要是MessageContext信息,它是HTTP请求/ Servlet请求/ WSDL操作设置,则线程本地上下文信息可能需要由最初编组SOAP / HTTP请求的线程填充,这意味着以后的异步处理线程没有此信息可用。 Just based on reading - haven't tested this combination. 仅基于阅读-尚未测试此组合。

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

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