簡體   English   中英

帶有Cxf和路由的駱駝

[英]Camel With Cxf and Routing

我正在對Camel-CXf集成進行一些研究,並對以下情況感到困惑。

所以我實現了一個休息端點

@Path("/authenticate")
public interface Sample {
@GET
@Path("/handshake")
@Produces(MediaType.TEXT_PLAIN)
public Response handshake();

@POST
@Path("/login")
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Produces(MediaType.APPLICATION_JSON)
public Response login(LoginRequest request) throws JsonGenerationException, JsonMappingException, IOException;
}

並實現如下

public class SampleImpl implements Sample{

@Context
private HttpHeaders headers;

@Autowired
CamelContext context;

public Response handshake()
{
    System.out.println("HandShake Executed Successfully");
    return Response.status(Status.OK).entity("This is a Message after Routing").build();
}

public Response login(LoginRequest request) throws JsonGenerationException, JsonMappingException, IOException {
    System.out.println("The Rquest objecr is Received "+request);
    return Response.status(Status.OK).entity(mapper.writeValueAsString(request)).build();
}

}

路線

<camel:from uri="cxfrs:bean:SampleRestEndPoint?bindingStyle=SimpleConsumer"></camel:from>

將其路由到實現中。 但是由於實現返回響應對象,因此如何構建路由變得很困惑。

  1. 一旦調用進入實現,我如何執行其他路由並發送回響應?在這種情況下,實現返回一個自定義對象。
  2. 其他路由如何附加到CXF路由?
  3. 我的CXF Implemenation是否應始終返回void類型? 如我所見,要訪問Exchange對象駱駝,需要返回類型為void
  4. 我是否完全忽略該實現,並執行“至”步驟並在交換正文中對其進行修改以獲取所需的響應?

任何指針將不勝感激。

杜德,看看這個-http://bushorn.com/camel-cxf-geocoder-example/

上面的示例雖然不是REST,但是將CXF與Camel路由一起使用是相同的。

我將執行以下強制性步驟:

  1. 避免使用bean /自定義類-嘗試使用駱駝框架功能。

  2. 使用XML-Spring / Blueprint DSL

請看下面的線程。

Apache Camel和Web服務

我已經使用駱駝和Apache CXF成功實現了Web服務使用。 如果您有任何疑問,我可以為您提供幫助。

謝謝Gautham

@GauthamHonnavara-這是一個帶有關聯處理器的JS Web服務的實現,但是它沒有關聯到端點的任何直接路由。我的問題還專門針對無法從wsdl生成服務類的JAX-RS。

假設這個用例是,您需要客戶調用端點,然后執行另外5個步驟,聯系另一個Web服務,等等,然后將響應發送回去。 上面的實現將響應發送回webservice實現bean本身。

因此,為避免這種情況,請與生產者使用者等創建一個簡單的接口,就像在我的問題中一樣,然后如果要注入Exchange(如果需要)並使用以下配置,則使每個方法都無效。

<!-- Created the CXF End Point For the  Calls to Come IN -->
<cxf:rsServer id="RestEndPoint" address="/rest"
    serviceClass="com.poc.camel.cxf.service.incoming.xxx"
    loggingFeatureEnabled="true" loggingSizeLimit="20">
    <cxf:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" >
            <!-- <constructor-arg ref="customObjectMapper" type="org.codehaus.jackson.map.ObjectMapper"/> -->
        </bean>
    </cxf:providers>
</cxf:rsServer>

技巧是使用服務類標記。 如果在那里提供了接口,則它不需要CXF的具體實現。

希望這可以幫助。 讓我知道

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM