gpt4 book ai didi

java - 如何重写CXF AbstractInvoker?

转载 作者:行者123 更新时间:2023-12-01 13:11:17 25 4
gpt4 key购买 nike

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

然而,经过进一步分析,发现抽象调用者正在打印调用的方法以及调用的方法的参数。因此密码字段再次被打印。我可以重写打印参数的方法。但是我需要在哪里以及如何注册我的自定义抽象方法调用程序。

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

最佳答案

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

ServerFactoryBean.setInvoker(new MyInvoker());

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

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

关于java - 如何重写CXF AbstractInvoker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22847286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com