1

我正在尝试处理 CXF 休息服务中的错误。我想要获得的是当用户尝试发送请求并且他选择了错误的路径时的情况。我想处理这种情况。默认响应是:

2014-05-15 14:07:14 INFO  [qtp811959489-40] LoggingOutInterceptor:234 - Outbound Message
---------------------------
ID: 1
Response-Code: 405
Content-Type: 
Headers: {Allow=[POST, GET, OPTIONS, HEAD], Date=[Thu, 15 May 2014 12:07:14 GMT], Content-Length=[0]}

我的资源类:

@Path("payment/v1/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class OneApiResource {

    @GET
    @Path("/{endUserId}/transactions")
    public PaymentTransactionListWrapper listTransactions(@PathParam("endUserId") String endUserId) {
        return null;
    }
}

端点:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://camel.apache.org/schema/cxf"
       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
    ">

    <bean id="jsonProviderFactory" class="model.oneApi.JsonProviderFactory"/>
    <bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
    <cxf:rsServer id="bieService"
                  address="http://{{endpoint.jetty.app.oneApi.host}}:{{endpoint.jetty.app.oneApi.service.port}}/{{endpoint.jetty.app.oneApi.service.ctx}}/"
                  loggingFeatureEnabled="true"
                  serviceClass="model.oneApi.OneApiResource"
                  loggingSizeLimit="-1"
                  skipFaultLogging="false">
        <cxf:providers>
            <bean factory-bean="jsonProviderFactory" factory-method="create"/>
        </cxf:providers>
        <cxf:inFaultInterceptors>
            <ref bean="logOutbound"/>
        </cxf:inFaultInterceptors>
        <cxf:outFaultInterceptors>
            <ref bean="logOutbound"/>
        </cxf:outFaultInterceptors>
    </cxf:rsServer>

</beans>

有什么办法可以处理吗?

4

0 回答 0