如果没有 Spring 或 AOP,如何处理 JAX-WS 中的横切问题?处理程序?
然而,我确实有一些更具体的想法:
每个 Web 服务方法都需要用一些锅炉位置代码包装(横切问题,是的,Spring AOP 在这里会很好用,但它要么不起作用,要么未经政府批准)建筑组)。一个简单的服务调用如下:(
@WebMethod...
public Foo performFoo(...) {
Object result = null;
Object something = blah;
try {
soil(something);
result = handlePerformFoo(...);
} catch(Exception e) {
throw translateException(e);
} finally {
wash(something);
}
return result;
}
protected abstract Foo handlePerformFoo(...);
我希望这是足够的上下文)。基本上,我想要一个钩子(在同一个线程中 - 就像方法调用拦截器),它可以有一个 before() 和 after() ,可以在每个方法调用周围弄脏(某事)和清洗(某事)该死的WebMethod。
无法使用 Spring AOP,因为我的 Web 服务不是 Spring 管理的 bean :(
帮助!!!!! 提供建议!请不要让我复制粘贴该样板 10 亿次(正如我被指示做的那样) )。
问候, 莱斯
I do have something more specific in mind, however:
Each web service method needs to be wrapped with some boiler place code (cross cutting concern, yes, spring AOP would work great here but it either doesn't work or unapproved by gov't architecture group). A simple service call is as follows:
@WebMethod...
public Foo performFoo(...) {
Object result = null;
Object something = blah;
try {
soil(something);
result = handlePerformFoo(...);
} catch(Exception e) {
throw translateException(e);
} finally {
wash(something);
}
return result;
}
protected abstract Foo handlePerformFoo(...);
(I hope that's enough context). Basically, I would like a hook (that was in the same thread - like a method invocation interceptor) that could have a before() and after() that could could soil(something) and wash(something) around the method call for every freaking WebMethod.
Can't use Spring AOP because my web services are not Spring managed beans :(
HELP!!!!! Give advice! Please don't let me copy-paste that boiler plate 1 billion times (as I've been instructed to do).
Regards,
LES
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Spring 退出后,AspectJ 是一个选择吗?
或者,您可以使用反射,然后重新设计您的应用程序以使用此概念吗?
有关反射的评论,您可以查看这篇文章:
http://onjava.com/ pub/a/onjava/2007/03/15/reflections-on-java-reflection.html
或者重新设计你的类以使用抽象类,所以performFoo将在抽象类中,所以你不需要这样做复制并粘贴。在你的例子中你已经差不多了。
Is AspectJ an option since Spring is out?
Or, can you use Reflection, and just redesign your application to work with this concept?
For a review on reflection you can look at this article:
http://onjava.com/pub/a/onjava/2007/03/15/reflections-on-java-reflection.html
Or redesign your class to use an abstract class, so performFoo would be in the abstract class, so you don't do copy and paste. You are almost there in your example.
我最终使用了 JAX-WS Commons Spring Extension 并制作了我的网站service impl 是一个 spring 管理的 bean,并在建议周围使用,以在一个地方处理所有样板。
如果我想保持没有 AOP 的原始约束,我想我可以创建一个接口和一个辅助方法,如下所示:
最后,业务方法将编码如下:
基本上,每个业务方法都将使用 doOperation 辅助方法它的主体和一个匿名类包含需要在 doOperation 方法创建的上下文中执行的代码。我确信这种模式有一个名称(让我想起贷款模式)。
I ended up using the JAX-WS Commons Spring Extention and made my web service impl a spring managed bean and used around advice to handle all that boiler plate in one place.
If I wanted to maintain the original constraint of no AOP, I suppose I could have created an interface and a helper method as follows:
Finally, the business methods would be coded as follows:
Basically, each business method would use the doOperation helper method in it's body and an anonymous class containing the code that needs to execute within the context created by the doOperation method. I'm sure there's a name for this pattern (reminds me of the Loan Pattern).
最好的方法是使用处理程序,但您必须使用
@HandlerChain
注释来注释所有服务:文件 handlers.xml 将定义您的处理程序:
最后,像这样实现您的 Handler 类:
更多详细信息此处。
The best way would be to use Handlers, but you would have to annotate all your services with the
@HandlerChain
annotation:The file handlers.xml would define your handlers:
Finally, implement your Handler class like this:
More details here.