尝试创建简单的REST服务并通过blueprint.xml文件应用路由。我想在没有Spring的情况下做到这一点...... - 只有蓝图
我的尝试都以以下例外结束:
.navi.uk-active .uk-panel-box {
padding:0;
}
感到沮丧,因为我没有足够的“参考框架”来检测是否缺少关键组件,或版本问题等......
感谢任何帮助,找出错误/缺失等等。
以下是我正在使用的简单应用:
patterns for context mapping in the context of DDD (domain-driven design)
RestPostService.java
"java.lang.IllegalStateException: Cannot find RestConsumerFactory in Registry or as a Component to use"
ThePojo.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();
}
}
blueprint.xml
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 + '}';
}
}
的pom.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>
环境:
<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>
FWIW - 试图从位于以下位置的现有示例中获取此POC:
但是,显然,这个例子已经3年多了......: - (
答案 0 :(得分:0)
您不能将CXF与rest-dsl一起使用,您需要使用其中一个受支持的组件:http://camel.apache.org/rest-dsl
然后您需要通过以下方式从ServiceMix shell安装:<{1}}等。
请参阅Apache Camel的一些REST示例:https://github.com/apache/camel/tree/master/examples#examples