2015-04-03 57 views
0

我是Apache駱駝的新手,我很難得到這個。 我已經通過互聯網看了一遍,找不到任何有價值的東西。 我也有「駱駝在行動」,所以如果有人知道本書可能有幫助的部分,請告訴我。阿帕奇駱駝路線返回網頁

這就是我要做的:

(1)用戶訪問一個Web服務

(2)作爲響應Web服務返回的網頁

我知道我必須使用HTTP和Jetty組件是我最好的選擇。

這是我的路線類:

public class MyRoute extends RouteBuilder { 

@Override 
public void configure() throws Exception { 

    /* 
    * Basic Route 
    */ 
      from("jetty://http://localhost:8080/ExchangeSendPage") 
      //.setHeader("webPageFileName", constant("index.html")) 
      .process(new myProcessor()); 
      .to() 


    } 

}); 

}

這是我的處理器類別:

public class myProcessor implements Processor { 

public void theprocess (Exchange exchange) throw Exception { 

    return ("ExchangeSendPage.html"); 
} 

我完全丟失,可以在使用一些指導以下幾點: (1 )如何設置我的本地主機,當用戶使用自己的機器時,他們只需點擊.html文件?我會用xpath嗎?現在我沒有.html文件去任何地方。我相信它甚至沒有連接到本地主機。 (2)如何將我的html頁面附加到我的處理器上?或者,這甚至是正確的方式去做呢? (3).to應該去到它將要訪問的服務器的URL嗎?這將被視爲終點?

請讓我知道是否有任何混淆。

回答

1

This博客文章詳細描述瞭如何使用駱駝和碼頭組件服務動態網頁。總之,你必須在交換填寫體:

public void process(Exchange exchange) throws Exception { 
    exchange.getOut().setBody("<html><body>Hello world</body></html>"); 
} 

編輯:

我敢肯定,博客示例工作。使用請複製以下回購:

git clone https://github.com/mjabali/Jetty-Sample 

而且使用

mvn camel:run 

請你實現比較這跑,尤其是駱駝上下文文件https://github.com/mjabali/Jetty-Sample/blob/master/src/main/resources/META-INF/spring/camel-context.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> 
    <camelContext xmlns="http://camel.apache.org/schema/spring"> 
    <package>com.fusesource.fusebyexample</package> 
    <route id="Jetty_Sample"> 
     <from uri="jetty:http://localhost:8888/myBookService"/> 
     <log logName="HTTP LOG" loggingLevel="INFO" message="HTTP REQUEST: ${in.header.bookid}"/> 
     <process ref="myBookService"/> 
    </route> 
</camelContext> 

<bean class="com.fusesource.fusebyexample.myBookService" id="myBookService"/> 

</beans> 
+0

我跟着職位,但我繼續收到「此服務器上沒有匹配或處理此請求的上下文」。任何想法可能會造成這種情況?我修改了我的端口#,所以我不確定。 – mprithibi 2015-04-06 20:29:39

+0

請看我最後的編輯 – cslysy 2015-04-07 06:09:19