Apache Camel 返回soap消息

c90pui9n  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(309)

我通过camel创建soapweb服务。现在我尝试处理错误。问题是我的wsdl没有fault元素,所以我需要返回消息来代替fault。我明白了:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>The exception org.apache.camel.CamelExchangeException needs to have an WebFault annotation with name and targetNamespace</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

但我需要这个

<ns2:Envelope xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://mbtc.ru/xws/StopList" xmlns:ns4="http://uralfd.hostco.ru/messages/credit/v01">
   <ns2:Body>
      <ns4:SF_A_StopList_INTType ns4:MessageID="?">
         <ns4:Error>
            <ns4:ErrorCode>99</ns4:ErrorCode>
            <ns4:ErrorText>Error message</ns4:ErrorText>
         </ns4:Error>
      </ns4:SF_A_StopList_INTType>
   </ns2:Body>
</ns2:Envelope>

如你所见,我得到了一个例外:
java.lang.runtimeexception:异常org.apache.camel.cameleExchangeException需要有一个带有name和targetnamespace的webfault注解
蓝图

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
           xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
           xsi:schemaLocation="
           http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
">
    <cm:property-placeholder id="properties.SF2CRE_StopListBP" persistent-id="SF2CRE_StopListBP"
                             placeholder-prefix="{{"
                             placeholder-suffix="}}">
        <cm:default-properties>
            <cm:property name="common.cfg.path" value="src/test/resources/"/>
        </cm:default-properties>
    </cm:property-placeholder>

    <cxf:cxfEndpoint id="incomingEndpoint"
                     address="{{incoming.url}}"
                     serviceClass="ru.hostco.uralfd.messages.credit.v02.StopListInterface">
        <cxf:properties>
            <entry key="dataFormat" value="RAW"/>
        </cxf:properties>
    </cxf:cxfEndpoint>

    <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
        <property name="location" value="blueprint:properties.SF2CRE_StopListBP"/>
    </bean>

    <bean id="shutdown" class="org.apache.camel.impl.DefaultShutdownStrategy">
        <property name="timeout" value="10" />
    </bean>

    <bean class="ru.uralfd.operation.Operation" id="Operation">
        <argument ref="properties"/>
    </bean>

    <bean class="ru.uralfd.operation.SF2CRE_StopListBPAggregationStrategy" id="aggregatorStrategy"/>

    <reference filter="(osgi.jndi.service.name=creCompanyDataSource)" id="dataSource" interface="javax.sql.DataSource" />

    <bean class="org.apache.camel.component.sql.SqlComponent" id="sql">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/blueprint" useMDCLogging="true" handleFault="true">
        <route id="routeRequest">
            <from uri="incomingEndpoint"/>
            <convertBodyTo type="String"/>
            <log message="SF2CRE_StopListBP breadcrumbId: ${headers.breadcrumbId} body: ${body}"/>
            <doTry>
            <unmarshal>
                <soapjaxb contextPath="ru.hostco.uralfd.messages.credit.v01"/>
            </unmarshal>
            <bean ref="Operation" method="checkType"/>

            <log message="SF2CRE_StopListBP Service1 after checkType ${headers}"/>

            <multicast strategyRef="aggregatorStrategy" stopOnException="true" strategyMethodAllowNull="true">
                <pipeline id="requestPerson">
                    <choice>
                        <when>
                            <simple>${headers.ReqPerson}</simple>
                            <bean ref="Operation" method="stopListPerson"/>
                        </when>
                    </choice>
                </pipeline>
                <pipeline id="requestDocument">
                    <choice>
                        <when>
                            <simple>${headers.ReqDocument} and ${headers.NoResponse}</simple>
                            <bean ref="Operation" method="stopListDocument"/>
                        </when>
                    </choice>
                </pipeline>
                <pipeline id="requestFull">
                    <choice>
                        <when>
                            <simple>${headers.ReqFull}</simple>
                            <bean ref="Operation" method="stopListFull"/>
                        </when>
                    </choice>
                </pipeline>
                <pipeline id="requestCompany">
                    <choice>
                        <when>
                            <simple>${headers.ReqCompany}</simple>
                            <to uri="sql:SELECT * FROM getStopListMLF2(:#RequestINNs, :#RequestDate)?outputClass=ru.uralfd.database.StopListMLF"/>
                            <bean ref="Operation" method="processCompanyResponse"/>
                        </when>
                    </choice>
                </pipeline>
            </multicast>
                <doCatch>
                    <exception>java.lang.Exception</exception>
                    <handled>
                        <constant>true</constant>
                    </handled>
                    <log loggingLevel="ERROR" message="SF2CRE_StopListBP breadcrumbId: ${headers.breadcrumbId} ERROR in ${routeId}.\n Exception.message: ${exception.message}.\n Exception_stacktrace: ${exception.stacktrace}." />
                    <bean ref="Operation" method="processException"/>
                </doCatch>
            </doTry>
            <to uri="direct:answer"/>
        </route>
        <route id="routeResponse">
            <from uri="direct:answer"/>
            <marshal>
                <soapjaxb contextPath="ru.hostco.uralfd.messages.credit.v01" encoding="UTF-8"/>
            </marshal>
            <convertBodyTo type="String"/>
            <log message="SF2CRE_StopListBP finish breadcrumbId: ${headers.breadcrumbId} body: ${body}"/>
        </route>
    </camelContext>
</blueprint>

进程异常

public SFAStopListINTType processException(Exchange exchange) throws Exception {
        String messageId = exchange.getIn().getHeader("RequestMessageID", String.class);
        Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
        return createEmptyResponse(messageId, "SF2CRE_StopList: "+e.getMessage(), ErrList.ERR_99.code());
    }

日志消息

2020-08-18T16:27:36,450 | ERROR | qtp240236697-529 | routeRequest                     | 53 - org.apache.camel.camel-core - 2.25.1 | SF2CRE_StopListBP breadcrumbId: ID-ws-00-705-1597731451094-21-15 ERROR in routeRequest.
 Exception.message: Sequential processing failed for number 3. Exchange[ID-ws-00-705-1597731451094-21-26]. Caused by: [org.springframework.jdbc.BadSqlGrammarException - PreparedStatementCallback; bad SQL grammar []; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'getStopListMLF2'.].
 Exception_stacktrace: org.apache.camel.CamelExchangeException: Sequential processing failed for number 3. Exchange[ID-ws-00-705-1597731451094-21-26]. Caused by: [org.springframework.jdbc.BadSqlGrammarException - PreparedStatementCallback; bad SQL grammar []; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'getStopListMLF2'.]
    at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:658)
    at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:248)
...
2020-08-18T16:27:36,451 | INFO  | qtp240236697-529 | routeRequest                     | 53 - org.apache.camel.camel-core - 2.25.1 | SF2CRE_StopListBP breadcrumbId: ID-ws-00-705-1597731451094-21-15 after exception body: ru.hostco.uralfd.messages.credit.v01.SFAStopListINTType@20b99c1b[messageID=ECCB37C6-8D94-49E3-B604-5E2FAEA1CF8B,error=ru.hostco.uralfd.messages.credit.v01.ErrorResultType@2ed5fc38[errorCode=99,errorText=SF2CRE_StopList: Sequential processing failed for number 3. Exchange[ID-ws-00-705-1597731451094-21-26]. Caused by: [org.springframework.jdbc.BadSqlGrammarException - PreparedStatementCallback; bad SQL grammar []; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'getStopListMLF2'.]],result=<null>]
 head: {accept-encoding=gzip,deflate, breadcrumbId=ID-ws-00-705-1597731451094-21-15, CamelCxfMessage={http.base.path=http://localhost:9080/SF2CRE_StopListBPWeb/sca, HTTP.REQUEST=Request(POST //localhost:9080/SF2CRE_StopListBPWeb/sca/StopList_Int_WS)@6ec89547, org.apache.cxf.transport.Destination=org.apache.cxf.transport.http_jetty.JettyHTTPDestination@49ce593, HTTP.CONFIG=null, org.apache.cxf.binding.soap.SoapVersion=org.apache.cxf.binding.soap.Soap11@4986b73b, org.apache.cxf.message.Message.QUERY_STRING=null, org.apache.cxf.message.Message.ENCODING=UTF-8, HTTP.CONTEXT=ServletContext@o.e.j.s.h.ContextHandler@235ee7ba{/SF2CRE_StopListBPWeb/sca,null,AVAILABLE}, Content-Type=text/xml;charset=UTF-8, org.apache.cxf.security.SecurityContext=org.apache.cxf.transport.http.AbstractHTTPDestination$2@600f66ee, org.apache.cxf.continuations.ContinuationProvider=org.apache.cxf.transport.http.Servlet3ContinuationProvider@6430fe37, org.apache.cxf.message.Message.PROTOCOL_HEADERS={accept-encoding=[gzip,deflate], connection=[keep-alive], Content-Length=[1105], content-type=[text/xml;charset=UTF-8], Host=[localhost:9080], SOAPAction=["getStopList"], User-Agent=[Apache-HttpClient/4.1.1 (java 1.5)]}, org.apache.cxf.request.url=http://localhost:9080/SF2CRE_StopListBPWeb/sca/StopList_Int_WS, Accept=null, org.apache.cxf.request.uri=/SF2CRE_StopListBPWeb/sca/StopList_Int_WS, org.apache.cxf.message.Message.PATH_INFO=/SF2CRE_StopListBPWeb/sca/StopList_Int_WS, org.apache.cxf.transport.https.CertConstraints=null, HTTP.RESPONSE=HTTP/1.1 200 
Date: Tue, 18 Aug 2020 11:27:36 GMT, org.apache.cxf.request.method=POST, org.apache.cxf.async.post.response.dispatch=true, org.apache.cxf.message.Message.IN_INTERCEPTORS=[org.apache.cxf.transport.https.CertConstraintsInterceptor@6bd0dcdb], HTTP_CONTEXT_MATCH_STRATEGY=stem, http.service.redirection=null, org.apache.cxf.message.Message.BASE_PATH=/SF2CRE_StopListBPWeb/sca/StopList_Int_WS, org.apache.cxf.configuration.security.AuthorizationPolicy=null, org.apache.cxf.message.Message.FIXED_PARAMETER_ORDER=false}, CamelHttpCharacterEncoding=UTF-8, CamelHttpMethod=POST, CamelHttpPath=, CamelHttpUri=/SF2CRE_StopListBPWeb/sca/StopList_Int_WS, connection=keep-alive, Content-Type=text/xml;charset=UTF-8, Host=localhost:9080, MulticastStep=false, NoResponse=true, org.apache.camel.dataformat.soap.UNMARSHALLED_HEADER_LIST=[], ReqCompany=true, ReqDocument=false, ReqFull=true, ReqPerson=false, RequestDate=Tue Jul 28 15:00:00 YEKT 2020, RequestINNs=5911063879,5911013211, RequestMessageID=ECCB37C6-8D94-49E3-B604-5E2FAEA1CF8B, SOAPAction="getStopList", User-Agent=Apache-HttpClient/4.1.1 (java 1.5)}
2020-08-18T16:27:36,452 | ERROR | qtp240236697-529 | DefaultErrorHandler              | 53 - org.apache.camel.camel-core - 2.25.1 | Failed delivery for (MessageId: ID-ws-00-705-1597731451094-21-28 on ExchangeId: ID-ws-00-705-1597731451094-21-15). Exhausted after delivery attempt: 1 caught: java.lang.RuntimeException: The exception org.apache.camel.CamelExchangeException needs to have an WebFault annotation with name and targetNamespace

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[routeRequest      ] [routeRequest      ] [http://localhost:9080/SF2CRE_StopListBPWeb/sca/StopList_Int_WS                ] [       217]
[routeRequest      ] [convertBodyTo38   ] [convertBodyTo[String]                                                         ] [         0]
[routeRequest      ] [log288            ] [log                                                                           ] [         3]
[routeRequest      ] [doTry21           ] [doTry                                                                         ] [       213]
[routeRequest      ] [unmarshal22       ] [unmarshal[org.apache.camel.model.dataformat.SoapJaxbDataFormat@616dfea7]      ] [         1]
[routeRequest      ] [bean125           ] [bean[ref:Operation method:checkType]                                          ] [         2]
[routeRequest      ] [log289            ] [log                                                                           ] [         2]
[routeRequest      ] [multicast22       ] [multicast                                                                     ] [       206]
[routeRequest      ] [log299            ] [log                                                                           ] [         1]
[routeRequest      ] [bean130           ] [bean[ref:Operation method:processException]                                   ] [         0]
[routeRequest      ] [log300            ] [log                                                                           ] [         1]
[routeRequest      ] [to42              ] [direct:answer                                                                 ] [         0]
[routeResponse     ] [marshal12         ] [marshal[org.apache.camel.model.dataformat.SoapJaxbDataFormat@5919bb62]        ] [         1]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
java.lang.RuntimeException: The exception org.apache.camel.CamelExchangeException needs to have an WebFault annotation with name and targetNamespace
    at org.apache.camel.dataformat.soap.Soap11DataFormatAdapter.createFaultFromException(Soap11DataFormatAdapter.java:119) ~[?:?]
    at org.apache.camel.dataformat.soap.Soap11DataFormatAdapter.doMarshal(Soap11DataFormatAdapter.java:81) ~[?:?]
    at org.apache.camel.dataformat.soap.SoapJaxbDataFormat.marshal(SoapJaxbDataFormat.java:147) ~[?:?]
    at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:69) ~[?:?]
    at org.apache.camel.processor.interceptor.HandleFaultInterceptor.process(HandleFaultInterceptor.java:42) ~[?:?]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:110) ~[?:?]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[?:?]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[?:?]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) ~[?:?]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) ~[?:?]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[?:?]
    at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:76) ~[?:?]
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) ~[?:?]
    at org.apache.camel.processor.interceptor.HandleFaultInterceptor.process(HandleFaultInterceptor.java:42) ~[?:?]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:110) ~[?:?]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[?:?]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[?:?]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) ~[?:?]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) ~[?:?]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[?:?]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.asyncInvoke(CxfConsumer.java:185) ~[!/:2.25.1]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.invoke(CxfConsumer.java:161) ~[!/:2.25.1]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) ~[!/:3.3.6]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_121]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_121]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$2.run(ServiceInvokerInterceptor.java:126) ~[!/:3.3.6]
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) ~[!/:3.3.6]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:131) ~[!/:3.3.6]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[!/:3.3.6]
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[!/:3.3.6]
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267) ~[!/:3.3.6]
    at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:247) ~[!/:3.3.6]
    at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:79) ~[!/:3.3.6]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1363) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:190) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1278) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.Server.handle(Server.java:500) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) ~[!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547) [!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) [!/:9.4.28.v20200408]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273) [!/:9.4.28.v20200408]
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [!/:9.4.28.v20200408]
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [!/:9.4.28.v20200408]
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [!/:9.4.28.v20200408]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) [!/:9.4.28.v20200408]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) [!/:9.4.28.v20200408]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]

我是否可以禁用在camel响应时创建错误消息?也许我需要另一种方式?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题