Essayer de créer un service REST simple et appliquer le routage via le fichier blueprint.xml. Je veux le faire sans printemps ... - seulement planProblème lors de la création d'un service REST simple et de l'application du routage via le fichier blueprint.xml. Je veux faire cela sans Spring ... - seulement blueprint
Mes tentatives finissent tous à l'exception suivante:
"java.lang.IllegalStateException: Cannot find RestConsumerFactory in Registry or as a Component to use"
Frustré que je n'ai pas assez « cadre de référence » pour détecter s'il est un élément clé manquant ou question versioning, etc ...
apprécierais toute aide pour identifier ce qui est faux/manque, etc.
est inférieure à la simple application, je travaille avec:
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>
Environnement:
Java 8
apache-servicemix 7.0.1
FWIW - ont essayé de tirer ce POC de l'exemple existant situé à:
Mais, apparemment, cet exemple est vieux 3+ ans ...: - (
Salut Claus - désolé si tard pour y revenir. Je suis confus à votre réponse parce que je vois des exemples comme celui-ci (https://github.com/apache/servicemix/tree/master/examples/camel/camel-cxf-rest). J'ai essayé de modéliser ce POC simpliste (ci-dessus) après. Qu'est-ce qui ne va pas? – sairn
Vous ne pouvez pas utiliser '' (alias rest-dsl) avec Apache CXF ou le composant camel-cxf. Cet exemple que vous pointez est âgé de 3 ans et n'utilise pas ''. Si vous aimez cet exemple sans '' alors vous pouvez le faire comme ça. –
Ah, merci! ... L'un des problèmes que je rencontre en essayant de saisir rapidement une connaissance pratique de Servicemix/Camel/routage .... Il m'a été un peu difficile de reconnaître/arrondir des exemples actuels/compléter et utiliser les «meilleures pratiques». Mais, je vais passer cela!:-) Laissez-moi essayer de supprimer les choses "" :-) – sairn