2017-11-25 250 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

相关问题