2017-07-18 38 views
2

尝试创建简单的REST服务并通过blueprint.xml文件应用路由。我想这样做没有春天? - 只有蓝图无法创建简单的REST服务并通过blueprint.xml文件应用路由。我想在没有Spring的情况下执行此操作... - 仅蓝图

我尝试全部结束与以下异常:

"java.lang.IllegalStateException: Cannot find RestConsumerFactory in Registry or as a Component to use" 

沮丧,因为我没有足够的“参照系”,以检测是否有是一个关键部件丢失,或版本问题,等等

感谢所有帮助确定什么是错误/丢失等

下面是简单的应用程序,我有工作:

project structure

RestPostService.java

package aaa.bbb.ccc; 

import javax.ws.rs.Path; 
import javax.ws.rs.GET; 
import javax.ws.rs.POST; 
import javax.ws.rs.core.Response; 
import javax.ws.rs.Produces; 
import javax.ws.rs.Consumes; 
import javax.ws.rs.core.MediaType; 
import org.apache.logging.log4j.LogManager; 
import org.apache.logging.log4j.Logger; 

@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) 
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) 
@Path("/service") 
public class RestPostService { 

    private static final Logger LOG = LogManager.getLogger("WebServiceSB"); 
    public RestPostService() { 
    } 

    @Path("/get1")  
    @GET 
    public ThePojo get1() { 
    ThePojo tp = new ThePojo("aaa", "bbb"); 
    return tp; 
    }  

    @Path("/post1")   
    @POST 
    @Produces(MediaType.TEXT_HTML)  
    public Response post1(ThePojo tp) { 
    return Response.status(200).build(); 
    } 
} 

ThePojo.java

package aaa.bbb.ccc; 

public class ThePojo { 

    public ThePojo() { 
    }  

    private String field1; 
    private String field2; 

    public String getField1() { 
    return field1; 
    } 
    public void setField1(String field1) { 
    this.field1 = field1; 
    } 

    public String getField2() { 
    return field2; 
    } 
    public void setField2(String field2) { 
    this.field2 = field2; 
    } 

    public ThePojo(String field1, String field2) { 
    this.field1 = field1; 
    this.field2 = field2; 
    } 

    @Override 
    public String toString() { 
    return "ThePojo{" + "field1=" + field1 + ", field2=" + field2 + '}'; 
    } 
} 

blueprint.xml

<?xml version="1.0" encoding="UTF-8"?> 
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf" 
     xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" 
     xsi:schemaLocation=" 
     http://www.osgi.org/xmlns/blueprint/v1.0.0 
     http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd 
     http://camel.apache.org/schema/blueprint 
     http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> 
    <cxf:rsServer id="rsServer" address="http://localhost:8989/restPostService" 
      serviceClass="aaa.bbb.ccc.RestPostService" 
      loggingFeatureEnabled="true" loggingSizeLimit="20"/>  

    <camelContext xmlns="http://camel.apache.org/schema/blueprint"> 
    <rest> 
     <get uri="/service/get1"> 
     <to uri="direct:get1"/> 
     </get> 
     <post uri="/service/post1" consumes="application/json"> 
     <to uri="direct:post1"/> 
     </post> 
    </rest> 
    <route> 
     <from uri="direct:post1"/> 
     <to uri="activemq:queue:queueA"/> 
    </route> 
    </camelContext> 
</blueprint> 

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>aaa.bbb.ccc</groupId> 
    <artifactId>restPost</artifactId> 
    <version>1</version> 
    <packaging>jar</packaging> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <maven.compiler.source>1.8</maven.compiler.source> 
    <maven.compiler.target>1.8</maven.compiler.target> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-rt-frontend-jaxrs</artifactId> 
     <version>3.1.11</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-rt-transports-http</artifactId> 
     <version>3.1.11</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-bundle-jaxrs</artifactId> 
     <version>2.7.18</version> 
    </dependency>   
    <dependency> 
     <groupId>org.apache.logging.log4j</groupId> 
     <artifactId>log4j-api</artifactId> 
     <version>2.6.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.logging.log4j</groupId> 
     <artifactId>log4j-core</artifactId> 
     <version>2.6.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-cxf</artifactId> 
     <version>2.19.1</version> 
    </dependency>    
    <dependency> 
     <groupId>com.fasterxml.jackson.jaxrs</groupId> 
     <artifactId>jackson-jaxrs-json-provider</artifactId> 
     <version>2.8.9</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-api</artifactId> 
     <version>7.0</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.aries.blueprint</groupId> 
     <artifactId>org.apache.aries.blueprint</artifactId> 
     <version>1.1.0</version> 
    </dependency> 
    </dependencies> 

    <build> 
    <!-- use for snapshot versioning <finalName>${project.artifactId}-${project.version}-${maven.build.timestamp}</finalName> --> 
    <finalName>${project.artifactId}-${project.version}</finalName> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.1</version> 
     <configuration> 
      <source>1.8</source> 
      <target>1.8</target> 
      <showDeprecation>true</showDeprecation> 
     </configuration> 
     </plugin>  
    </plugins> 
    </build>  
</project> 

环境:

Java 8 
apache-servicemix 7.0.1 

FWIW - 试图获得从现有例如这个POC位于:

camel-cxf-rest

但是,很显然,这个例子是3+岁...: - (

enter image description here

回答

0

你不能休息,DSL使用CXF,需要使用支持的组件之一:http://camel.apache.org/rest-dsl

然后你需要通过安装从ServiceMix的外壳:feature:install camel-servlet

看到一些来自阿帕奇骆驼的REST例子:https://github.com/apache/camel/tree/master/examples#examples

+0

嗨克劳斯 - 对不起这么晚回到这个。我对你的回应感到困惑,因为我看到这样的例子(https://github.com/apache/servicemix/tree/master/examples/camel/camel-cxf-rest)。之后我试图对这个简单的POC(上图)进行建模。究竟是什么错误? – sairn

+0

您不能在Apache CXF或camel-cxf组件中使用''(又名rest-dsl)。你指出的那个例子是3岁,并且不使用''。如果你喜欢那个没有''的例子,那么你可以这样做。 –

+0

啊,thx!...我试图快速掌握Servicemix/Camel/routing的实际知识时遇到的一个问题....对于我来说,识别/汇总最新的示例有点困难/完成并使用“最佳实践”。但是,我会通过这个!:-)让我试着删除“”的东西:-) – sairn

相关问题