2017-11-25 249 views
1

我想使用camel-jetty組件發送https使用者請求,並且該地址以JSON格式返回一些響應,下面我提到我的DSL代碼。如何爲https請求定義camel jetty路由並將參數傳遞給某個api進行認證?

from("jetty:https://someSiteAddress.com/api/control/authorizeUser?username=__&password=__").to("stream:out"); 

I am getting this warning: 
[WARNING] 
java.net.SocketException: Permission denied 
at sun.nio.ch.Net.bind0 (Native Method) 
at sun.nio.ch.Net.bind (Net.java:433) 
at sun.nio.ch.Net.bind (Net.java:425) 
at sun.nio.ch.ServerSocketChannelImpl.bind 

但是,無論何時我在瀏覽器中點擊此HTTP URL,它都將與身份驗證一起完美執行。
如果有人知道該怎麼做才能在apache駱駝中執行這個動作,請幫助我,這對我和其他人來說會非常開心。

我怎麼能知道哪個方法駱駝使用發送請求像POST或GET。
謝謝

+0

嗨!如果我理解正確,您想要使用此端點:「https://someSiteAddress.com/api/control/authorizeUser?username = __&password = __',正確嗎?如果我是對的,你應該在'to'中使用'camel-http'組件。您的代碼被描述的方式,您**暴露**的URL,而不是消耗它。如果您遇到問題,請告訴我,我已將其解答。 –

+0

@RicardoZanini謝謝你的幫助,讓我明確指出在這裏我想擊中端點:從(「提及上面」)返回一些token_Id和這些token_Id的我在控制檯上打印到(「stream:out」)。但我越來越錯誤,我認爲這個錯誤是因爲** jetty **。 –

+0

嗨!請,看我的答案。你使用jetty的方式是在這個地址公開一個端點:'https:// someSiteAddress.com'不會從它消耗。要使用url來使用,你必須使用'to()'指定它。 –

回答

1

你可以試試這個嗎?我會評論每一行以幫助理解您的問題。

// endpoint to start your route. could be a http endpoint you expose via jetty, jms, vm, seda or any other option. Here I'm using the simplest one. 
from("direct:start") 
    // logs on 
    .to("log:DEBUG?showBody=true&showHeaders=true") 
    // consume the endpoint 
    .to("https://someSiteAddress.com/api/control/authorizeUser?username=__&password=__"") 
    // log the body to the console so you could process the response later knowing what to do (the token you are mentioning should be in here. 
    .to("log:DEBUG?showBody=true&showHeaders=true") 
    .to("stream:out") //or whatever you want to 

不要忘了camel-http依賴這個例子的工作:

<dependency> 
    <groupId>org.apache.camel</groupId> 
    <artifactId>camel-http</artifactId> 
</dependency> 

乾杯!

+0

你好@RicardoZanini我很喜歡清理我的概念,代碼是*** Build Success ***,但我仍然沒有得到迴應(以令牌和id的形式)。以防萬一,如果你對我的*** URL響應有疑問,***它在瀏覽器中工作正常。 –

+0

@RajatTemaniya請發佈您在瀏覽器中查看的回覆。響應機構應該在您的回覆中。 –

+0

你好@RicardoZanini這是我正在尋找*** {「organizationPartyId」:「MY_COMPANY」,「sessionId」:「somerandomid.jvm1」,「_ LOGIN_PASSED _」:「TRUE」,「authorizeUserResult」:{「userLoginId」:「 myuser「,」responseMessage「:」success「,」partyId「:」myparty「,」token「:」mytoken ==「}} *** 我試圖得到交換,但沒有迴應。 –

0

這也工作正常。

from("direct:in") 
.to("https://www.someAddress.com/api/control /authorizeUser?username=__ &password=__") 
.to("stream:out"); 

感謝@RicardoZanini

相關問題