Apache Cxf拦截器

时间:2017-03-12 18:04:21

标签: java web-services exception-handling cxf

我正在使用AbstractPhaseInterceptor(注册为InInterceptor),我在解组前验证传入的SOAP请求。如果验证失败,我将生成故障代码和Falult信息作为响应。我能够获取故障信息,但在抛出异常时,我收到以下警告消息。可以避免吗?

我的拦截器

package de.jonashackt.tutorial;

import java.util.logging.Logger;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;

public class SoapInter extends AbstractPhaseInterceptor<Message> {

    private static final Logger LOG = Logger.getLogger(SoapInter.class.getName());

    public SoapInter() {
        super(Phase.RECEIVE);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void handleMessage(Message arg0) throws Fault {
            //throw new Fault(new NumberFormatException("error"));
        throw new Fault("Error", LOG);
    }

public void handleFault(Message arg0) {

super.handleFault(message);
XMLStreamWriter writer = (XMLStreamWriter)message.get("ORIGINAL_XML_WRITER");
if (writer != null)
{
message.setContent(XMLStreamWriter.class, writer);
}

}

}

这是我的配置文件

package de.jonashackt.tutorial;

import java.util.Arrays;

import org.apache.cxf.Bus;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class WebServiceConfig {

    @Autowired
    private Bus bus;

    @Bean
    public Server  endpoint() {
        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
        factory.setAddress("/Hello");
        factory.setBus(bus);
        factory.setServiceBean(Arrays.<Object>asList(new HelloPortImpl()));
        factory.getInInterceptors().add(soap());
        return  factory.create();
    }

    @Bean
    public AbstractPhaseInterceptor<SoapMessage> soap() {
        return new SoapInter();
    }
}
  

o.a.cxf.phase.PhaseInterceptorChain:Interceptor for   {http://util.java/} ArrayListService抛出异常,展开   现在

     

org.apache.cxf.interceptor.Fault:错误在   de.jonashackt.tutorial.SoapInter.handleMessage(SoapInter.java:22)   〜[classes /:na] at   org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)   〜[cxf-core-3.1.10.jar:3.1.10] at   org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)   [cxf-core-3.1.10.jar:3.1.10] at   org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:262)   [cxf-rt-transports-http-3.1.10.jar:3.1.10] at   org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)   [cxf-rt-transports-http-3.1.10.jar:3.1.10] at   org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)   [cxf-rt-transports-http-3.1.10.jar:3.1.10] at   org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)   [cxf-rt-transports-http-3.1.10.jar:3.1.10] at   org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)   [cxf-rt-transports-http-3.1.10.jar:3.1.10] at   org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299)   [cxf-rt-transports-http-3.1.10.jar:3.1.10] at   org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:223)   [cxf-rt-transports-http-3.1.10.jar:3.1.10] at   javax.servlet.http.HttpServlet.service(HttpServlet.java:622)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:274)   [cxf-rt-transports-http-3.1.10.jar:3.1.10] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)   [tomcat-embed-websocket-8.0.32.jar:8.0.32] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)   [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] at   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)   [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)   [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] at   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)   [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)   [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] at   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)   [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)   [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] at   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)   [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:672)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1500)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1456)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)   [na:1.8.0_65] at   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)   [na:1.8.0_65] at   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)   [tomcat-embed-core-8.0.32.jar:8.0.32] at   java.lang.Thread.run(Thread.java:745)[na:1.8.0_65]

问题是什么?可以避免吗?

1 个答案:

答案 0 :(得分:0)

默认情况下,CXF使用java.util.logging您需要在logging.properties中配置日志记录级别,以便不显示消息WARNING消息,或禁用控制台。见CXF logging documentation

例如,使用此内容定义logging.properties文件

.level = SEVERE
java.util.logging.ConsoleHandler.level = SEVERE

以下系统属性

-Djava.util.logging.config.file="path/to/your/logging.properties"