1

保险丝 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

我该如何解决这个问题?

4

1 回答 1

0

javax.ws.rs.NotFoundException - 错误的原因是,CXF 找不到给定请求的匹配资源。

为遵守最佳实践,请勿在“地址属性”中使用完全限定的 url。以下是工作示例,请在您的代码中尝试相同的操作。它会工作

骆驼DSL:

<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 ;

    }
  }

访问这个剩余资源的路径将是“ http://localhost:xxxx/controlcservice/save

于 2015-08-25T11:18:38.543 回答