如何覆盖CXF AbstractInvoker?

时间:2014-04-03 19:35:18

标签: java cxf cxfrs

我已经要求在我的输入请求中我获取需要屏蔽的密码参数因为我将日志级别保持为调试,所以输入的xml将被记录为密码字段。我通过重写LogginginInterceptors和LoggingOutInterceptor修复了这个问题。

然而,在进一步分析中,发现Abstract invoker是调用的打印方法以及被调用方法的参数。因此密码字段再次被打印。我可以覆盖打印参数的方法。但是我需要在哪里以及如何注册我的自定义abstractmethod调用者。

2014-04-03 20:16:54,827 [http-8443-1] DEBUG o.a.c.s.invoker.AbstractInvoker - Invoking method public com.kp.schema.CredResObject com.kp.CredentialsImpl.updateCredentials(com.kp.schema.CredReqObject) throws com.kp.FaultResponse on object com.kp.CredentialsImpl@2ee4e8 with params [CredReqObject [clientID=kpid, host=asda, userName=u1, passWord=sssss]].

自定义调用者

public class NMSCustomInvoker extends AbstractInvoker {

    static final ResourceBundle BUNDLE = BundleUtils
            .getBundle(FactoryInvoker.class);

    private Factory factory;

    public NMSCustomInvoker(Factory factory) {
        this.factory = factory;
    }

    public NMSCustomInvoker() {
    }

    public void setFactory(Factory f) {
        this.factory = f;
    }

    @Override
    public Object getServiceObject(Exchange ex) {
        try {
            return factory.create(ex);
        } catch (Fault e) {
            throw e;
        } catch (Throwable e) {
            throw new Fault(new Message("CREATE_SERVICE_OBJECT_EXC", BUNDLE), e);
        }
    }

    public void releaseServiceObject(final Exchange ex, Object obj) {
        factory.release(ex, obj);
    }

    @Override
    protected Object performInvocation(Exchange exchange,
            final Object serviceObject, Method m, Object[] paramArray)
            throws Exception {
        paramArray = insertExchange(m, paramArray, exchange);
        return m.invoke(serviceObject, paramArray);
    }

}

由于工厂对象为空,我得到了空指针错误。

更新了StackTrace

org.apache.cxf.interceptor.Fault: Could not instantiate service object.
    at mypackage.NMSCustomInvoker.getServiceObject(NMSCustomInvoker.java:45) ~[NMSCustomInvoker.class:na]
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:50) ~[cxf-api-2.7.8.jar:2.7.8]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) ~[cxf-api-2.7.8.jar:2.7.8]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) ~[cxf-api-2.7.8.jar:2.7.8]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) ~[cxf-api-2.7.8.jar:2.7.8]
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-api-2.7.8.jar:2.7.8]
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239) [cxf-rt-transports-http-2.7.8.jar:2.7.8]
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) [cxf-rt-transports-http-2.7.8.jar:2.7.8]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) [cxf-rt-transports-http-2.7.8.jar:2.7.8]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) [cxf-rt-transports-http-2.7.8.jar:2.7.8]
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:167) [cxf-rt-transports-http-2.7.8.jar:2.7.8]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286) [cxf-rt-transports-http-2.7.8.jar:2.7.8]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:211) [cxf-rt-transports-http-2.7.8.jar:2.7.8]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [servlet-api-3.0-alpha-1.jar:3.0-alpha-1]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262) [cxf-rt-transports-http-2.7.8.jar:2.7.8]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:6.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.37]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.37]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:6.0.37]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.37]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:6.0.37]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.37]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) [catalina.jar:6.0.37]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) [tomcat-coyote.jar:6.0.37]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) [tomcat-coyote.jar:6.0.37]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) [tomcat-coyote.jar:6.0.37]
    at java.lang.Thread.run(Thread.java:662) [na:1.6.0_32]
Caused by: java.lang.NullPointerException: null
    at mypackage.NMSCustomInvoker.getServiceObject(NMSCustomInvoker.java:41) ~[NMSCustomInvoker.class:na]
    ... 26 common frames omitted

1 个答案:

答案 0 :(得分:1)

如果您使用cxf-jaxws或cxf-jaxrs前端API,您可以自己设置调用者,就像这样

ServerFactoryBean.setInvoker(new MyInvoker());

如果您使用弹簧配置,则可以像这样设置自定义调用程序

<jaxws:endpoint id="simpleWithBinding"
    implementor="#greeter" 
        address="http://localhost:8080/simpleWithAddress">
    <jaxws:invoker>
       <bean id="myInvoker" class="com.example.MyInvoker"/>
    </jaxws:invoker>
  </jaxws:endpoint>