融合esb。组件: CXFRs webservice
我的网络服务出了点问题。
这是POM.xml:
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- Testing & Camel Plugin -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-blueprint</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<!-- CXF -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-all</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.7.0.redhat-610379</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>2.12.0.redhat-610379</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb</artifactId>
<version>2.12.0.redhat-610379</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>2.7.0.redhat-610379</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http4</artifactId>
<version>2.12.0.redhat-610379</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m10</version>
</dependency>
</dependencies>这是路由:
<?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"
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">
<bean id="helloBean" class="com.mycompany.camel.blueprint.HelloBean">
<property name="say" value="Hi from Camel"/>
</bean>
<cxf:rsServer id="rsServer" address="http://localhost:9090/route"
serviceClass="com.mycompany.camel.blueprint.Testws"/>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="cxfrs:beanId:rsServer"/>
<log message="test"/>
<marshal>
<json library="Jackson"/>
</marshal>
</route>
</camelContext>
</blueprint>这是函数:
package com.mycompany.camel.blueprint;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/")
public class Testws {
@GET
@Path("/test/{id}/{id2}")
@Produces(MediaType.APPLICATION_JSON)
public String getAssets(@PathParam("id") String id,
@PathParam("id2") String id2){
return null;
}
}下面是错误消息:
Caused by: javax.ws.rs.NotFoundException
at org.apache.cxf.jaxrs.*
AbstractJAXRSFactoryBean.checkResources
(AbstractJAXRSFactor yBean.java:322)
at 2)
... 55 more我如何解决这个问题?
发布于 2015-08-25 19:18:39
javax.ws.rs.NotFoundException -错误的原因是,CXF找不到与给定请求匹配的资源。
为了符合最佳实践,不要在“地址属性”中使用完全限定的url。下面是工作示例,请在您的代码中尝试相同的代码。看起来不错
驼峰数字用户线:
<cxf:rsServer id="rsServer" address="/"
serviceClass="com.guru.service.ControlService"
loggingFeatureEnabled="true" loggingSizeLimit="20">
<cxf:providers>
<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"/>
</cxf:providers>
</cxf:rsServer>
<route id="esbRoute">
<from uri="cxfrs:bean:rsServerr"/>
<to uri="mock:test" />
</route>Java代码
@Path("/controlcservice")
public class ControlService {
@POST
@Path("/save")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ResponseDetail save(ControlEntity entity) {
System.out.println("Hi Im inside rest api");
return null ;
}
}访问这个rest资源的路径将是"http://localhost:xxxx/controlcservice/save“
https://stackoverflow.com/questions/32199778
复制相似问题