【问题标题】:camel http component 500骆驼http组件500
【发布时间】:2012-02-07 14:29:31
【问题描述】:

我正在创建 cxf/camel 网络服务,我已经为这样的测试代码创建了:

@GET
@Path("/user")
@ProduceMime({ "application/json" })
public String user(@FormParam("token") String token) throws Exception {

        CamelContext context = new DefaultCamelContext();

        context.addRoutes(new RouteBuilder() {
            public void configure(){
                from("direct:start").to("http://google.com");
            }
        });

        context.start();

        return token;

    }

}

然后我编译并复制了 FUSE ESB 部署文件夹。我的网络服务已安装,但是当我用我的网络服务打开 URL 时,我得到 500 响应:

  org.apache.cxf.interceptor.Fault: Failed to create route route17 at: >>> To[http://google.com] <<< in route: Route[[From[direct:start]] -> [To[http://google.com]]] because of Failed to resolve endpoint: http://google.com due to: No component found with scheme: http
Caused by:

java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Failed to create route route17 at: >>> To[http://google.com] <<< in route: Route[[From[direct:start]] -> [To[http://google.com]]] because of Failed to resolve endpoint: http://google.com due to: No component found with scheme: http
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:108)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:323)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:209)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:152)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:114)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:112)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:163)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:70)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:480)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:116)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:72)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
    at org.eclipse.jetty.server.Server.handle(Server.java:346)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:438)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:905)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:561)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:43)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:538)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:43)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
    at java.lang.Thread.run(Thread.java:680)

另外我已经导入了:

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.component.http.*;
import org.apache.camel.component.http.helper.*;

在 ESB 上我打开了 camel-http

怎么了?

--------------

所以我写的是错误的,下面的代码应该可以正常工作吗?

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

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />

    <bean id="cxfSSO" class="com.esb.cxf.SSO" />
    <jaxrs:server id="sso" address="/ssocamel2">
        <jaxrs:serviceBeans>
            <ref bean="cxfSSO" />
        </jaxrs:serviceBeans>
    </jaxrs:server>

      <camelContext xmlns="http://camel.apache.org/schema/spring">

        <endpoint id="endpointURL" uri="http://localhost:8080/SSO/?token=test"/>

        <route>
          <from uri="direct:start"/>
          <to uri="callRealWebService"/>
        </route>

      </camelContext>



</beans>

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    您需要安装 camel-http 功能。在 Fuse ESB 控制台中,您可以键入:

    features:install camel-http
    

    然后你可以安装/启动你的包。

    正如 Ben 所说,你在 rest 服务中所做的事情是完全错误的。您应该设置一次骆驼路线。如果要使用 Camel 从 Java 代码调用 http 端点,则不需要路由,但可以使用 ProducerTemplate。有关详细信息,请参阅 Camel 文档。

    【讨论】:

    • 好的,所以我会尝试在 xml 中做所有事情 - 我在----------- 下面添加的代码是正确的吗?因为我运行这个应用程序,但我看不到它的工作原理...... :(
    • @Clauslbsen 我有同样的问题take a look at my question here,你能建议我如何解决这个问题。
    【解决方案2】:

    有几件事,“没有找到带有方案的组件:http”意味着您在捆绑包中缺少骆驼-http 依赖项

    接下来,您应该设置一次 Camel 上下文/路由……而不是像这样的方法调用。

    【讨论】:

    • 我会检查捆绑包,但我记得我的捆绑包中有camel-http - 我会检查的。大约第二个 - 如 Apache Camel 网站所示,我可以使用from("direct:start") .setHeader(Exchange.HTTP_URI, simple("http://myserver/orders/${header.orderId}")) .to("http://dummyhost");。如果我可以使用这样的东西,为什么我不能以任何方式使用它?
    • 从一个方法中,你可以调用一个路由(template.send("direct:start", message)等),不定义路由本身...见camel.apache.org/producertemplate.html
    猜你喜欢
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多