programing

Camel을 사용하여 로컬 서비스에서 원격 서비스로 Rest 요청을 라우팅하는 방법

nasanasas 2020. 12. 2. 21:26
반응형

Camel을 사용하여 로컬 서비스에서 원격 서비스로 Rest 요청을 라우팅하는 방법


cxf 나머지 서비스에서 다른 서비스로 나머지 요청을 라우팅하려고합니다. 프로세스의 일부를 이해하는 데 도움이되는 http://camel.apache.org/cxfrs.html살펴 보았습니다 . remoteService 호출 수준에서 classCastException이 있습니다.

내가 도대체 ​​뭘 잘못하고있는 겁니까 ?

<cxf:rsServer id="exposedService" address="/exposed/"
serviceClass="com.example.project.ExposedService" />

<!-- using different classes since we are not just proxying -->
<cxf:rsClient id="remoteService" address="http://remote.com/service"
serviceClass="com.example.project.RemoteService" />

<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
   <package>com.example.project</package>
</camel:camelContext>

서비스 등급 :

@Path("/myservice")
public class ExposedService {

    @POST
        @Consumes("application/xml")
    public void postResource(javax.xml.transform.Source resource) {
            // source : not using jaxb just plain xml
        // only serves to configure the endpoint (?)    
    }               
}


public class RemoteService {

    @POST
        @Consumes("application/xml")
    public void postResource(javax.xml.transform.Source resource) {
            // source : not using jaxb just plain xml
        // only serves to configure the endpoint (?)    
    }               
}

RouteBuilder :

public class MyRouteBuilder extends RouteBuilder {

public void configure() { 
    from("cxfrs://bean://exposedService")
    .process(...) // a few System.out.println's
    .to("cxfrs://bean://remoteService")
    ;   
}
}

Stacktrace :

| 오류 | qtp-2045010446-1 | DefaultErrorHandler | 68-org.apache.camel.camel-core-2.6.0 | exchangeId에 대한 배달 실패 : ID-Lab-local-52879-1305561896560-7-2. 배달 시도 후 소진 됨 : 1 개 발견 : java.lang.ClassCastException
java.lang.ClassCastException
        java.lang.Class.cast (Class.java:2990) [: 1.6.0_24]
        org.apache.cxf.jaxrs.client.WebClient.invoke (WebClient.java:329) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeHttpClient (CxfRsProducer.java:147) [118 : org.apache.camel.camel-cxf : 2.6.0]
        org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process (CxfRsProducer.java:77) [118 : org.apache.camel.camel-cxf : 2.6.0]
        org.apache.camel.impl.converter.AsyncProcessorTypeConverter $ ProcessorToAsyncProcessorBridge.process (AsyncProcessorTypeConverter.java:50) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.util.AsyncProcessorHelper.process (AsyncProcessorHelper.java:70) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.SendProcessor $ 2.doInAsyncProducer (SendProcessor.java:104) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.impl.ProducerCache.doInAsyncProducer (ProducerCache.java:272) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.SendProcessor.process (SendProcessor.java:98) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.util.AsyncProcessorHelper.process (AsyncProcessorHelper.java:70) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.DelegateAsyncProcessor.processNext (DelegateAsyncProcessor.java:98) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.DelegateAsyncProcessor.process (DelegateAsyncProcessor.java:89) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.management.InstrumentationProcessor.process (InstrumentationProcessor.java:68) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.util.AsyncProcessorHelper.process (AsyncProcessorHelper.java:70) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.DelegateAsyncProcessor.processNext (DelegateAsyncProcessor.java:98) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.DelegateAsyncProcessor.process (DelegateAsyncProcessor.java:89) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.interceptor.TraceInterceptor.process (TraceInterceptor.java:174) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.util.AsyncProcessorHelper.process (AsyncProcessorHelper.java:70) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler (RedeliveryErrorHandler.java:299) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.RedeliveryErrorHandler.process (RedeliveryErrorHandler.java:208) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.DefaultChannel.process (DefaultChannel.java:269) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.util.AsyncProcessorHelper.process (AsyncProcessorHelper.java:70) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.Pipeline.process (Pipeline.java:125) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.Pipeline.process (Pipeline.java:80) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.UnitOfWorkProcessor.process (UnitOfWorkProcessor.java:102) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.util.AsyncProcessorHelper.process (AsyncProcessorHelper.java:70) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.DelegateAsyncProcessor.processNext (DelegateAsyncProcessor.java:98) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.DelegateAsyncProcessor.process (DelegateAsyncProcessor.java:89) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.management.InstrumentationProcessor.process (InstrumentationProcessor.java:68) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.util.AsyncProcessorHelper.process (AsyncProcessorHelper.java:91) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.processor.DelegateAsyncProcessor.process (DelegateAsyncProcessor.java:85) [68 : org.apache.camel.camel-core : 2.6.0]
        org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.syncInvoke (CxfRsInvoker.java:134) [118 : org.apache.camel.camel-cxf : 2.6.0]
        org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation (CxfRsInvoker.java:68) [118 : org.apache.camel.camel-cxf : 2.6.0]
        org.apache.cxf.service.invoker.AbstractInvoker.invoke (AbstractInvoker.java:89) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.jaxrs.JAXRSInvoker.invoke (JAXRSInvoker.java:153) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.jaxrs.JAXRSInvoker.invoke (JAXRSInvoker.java:87) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.interceptor.ServiceInvokerInterceptor $ 1.run (ServiceInvokerInterceptor.java:58) [116 : org.apache.cxf.bundle : 2.3.2]
        java.util.concurrent.Executors $ RunnableAdapter.call (Executors.java:441) [: 1.6.0_24]
        java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java:303) [: 1.6.0_24]
        java.util.concurrent.FutureTask.run (FutureTask.java:138) [: 1.6.0_24]
        org.apache.cxf.workqueue.SynchronousExecutor.execute (SynchronousExecutor.java:37) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage (ServiceInvokerInterceptor.java:106) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.phase.PhaseInterceptorChain.doIntercept (PhaseInterceptorChain.java:255) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.transport.ChainInitiationObserver.onMessage (ChainInitiationObserver.java:113) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.transport.http_osgi.OsgiDestination.doMessage (OsgiDestination.java:79) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.transport.http_osgi.OsgiServletController.invokeDestination (OsgiServletController.java:336) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.transport.http_osgi.OsgiServletController.invoke (OsgiServletController.java:108) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.transport.http_osgi.OsgiServlet.invoke (OsgiServlet.java:53) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.transport.http_osgi.SpringOsgiServlet.invoke (SpringOsgiServlet.java:48) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest (AbstractHTTPServlet.java:179) [116 : org.apache.cxf.bundle : 2.3.2]
        org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost (AbstractHTTPServlet.java:103) [116 : org.apache.cxf.bundle : 2.3.2]
        javax.servlet.http.HttpServlet.service (HttpServlet.java:595) [93 : org.apache.geronimo.specs.geronimo-servlet_3.0_spec : 1.0]에서
        org.apache.cxf.transport.servlet.AbstractHTTPServlet.service (AbstractHTTPServlet.java:159) [116 : org.apache.cxf.bundle : 2.3.2]
        org.mortbay.jetty.servlet.ServletHolder.handle (ServletHolder.java:511) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.jetty.servlet.ServletHandler.handle (ServletHandler.java:390) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.handle (HttpServiceServletHandler.java:64) [133 : org.ops4j.pax.web.pax-web-jetty : 0.7.4]
        org.mortbay.jetty.servlet.SessionHandler.handle (SessionHandler.java:182) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.jetty.handler.ContextHandler.handle (ContextHandler.java:765) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]에서
        org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.handle (HttpServiceContext.java:111) [133 : org.ops4j.pax.web.pax-web-jetty : 0.7.4]
        org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle (JettyServerHandlerCollection.java:68) [133 : org.ops4j.pax.web.pax-web-jetty : 0.7.4]
        org.mortbay.jetty.handler.HandlerWrapper.handle (HandlerWrapper.java:152) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.jetty.Server.handle (Server.java:326) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.jetty.HttpConnection.handleRequest (HttpConnection.java:542) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.jetty.HttpConnection $ RequestHandler.content (HttpConnection.java:943) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.jetty.HttpParser.parseNext (HttpParser.java:756) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.jetty.HttpParser.parseAvailable (HttpParser.java:218) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.jetty.HttpConnection.handle (HttpConnection.java:404) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.io.nio.SelectChannelEndPoint.run (SelectChannelEndPoint.java:410) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]
        org.mortbay.thread.QueuedThreadPool $ PoolThread.run (QueuedThreadPool.java:582) [94 : org.apache.servicemix.bundles.jetty : 6.1.25.1]

여기에 거의 동일한 작업을 수행하는 작업 예제가 있습니다.

http://camel.apache.org/cxf-proxy-example.html

이것으로 시작한 다음 변경 사항을 하나씩 삭제하고 중단되는 부분을 확인하십시오 ...

참고URL : https://stackoverflow.com/questions/6009174/how-to-route-rest-request-from-a-local-service-to-a-remote-one-using-camel

반응형