Results 1 to 5 of 5

Thread: Sending requests to fetch information to https://URL

  1. #1
    Join Date
    Dec 2011
    Location
    Hyderabad, India
    Posts
    16

    Default Sending requests to fetch information to https://URL

    Hi All,

    I am new to using http adapters in SI. I am trying to sending a request to a URL that runs on only secured protocol i.e., 'https'. I have tried a lot a lot but not able to establish a connection to the URL.

    I have tried using a proxy even but the connection is not established to the URL. Looking for some help from the group members on how to establish connection to a URL using http adapters.

    Here is my configuration code:

    Code:
    <beans:bean id="httpDemo" class="blog.HTTPDemo" />
    
    <int:channel id="requestChannel" />
    
    <http:outbound-gateway request-channel="requestChannel" reply-channel="httpResponseChannel" auto-startup="true" url="https://login.salesforce.com/services/oauth2/token" />
    
    <int:channel id="httpResponseChannel" />
    	<!-- <int:queue capacity="10" />
    </int:channel> -->
    <int:service-activator input-channel="httpResponseChannel" ref="httpDemo" />
    Thanks in Advance!!!

    Regards,
    Avinash Munaga.

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,015

    Default

    You need to look at the logs and/or what's going on "on the wire"; https just "works" because it is handled by the JVM.

    For example, if you look at the basic/http sample here

    https://github.com/SpringSource/spri...ration-samples

    just change the URL to an https one and you'll see it just works.

    Code:
    <int-http:outbound-gateway request-channel="requestChannel" 
    				           url="https://jira.springframework.org/"
    				           http-method="GET"
    				           expected-response-type="java.lang.String"/>
    If you run a line monitor, like wireshark you can see all the SSL/TLS handshaking happening.

    If you can't figure it out from debug level logs, try running wireshark - you won't be able to read the data, but you should at least see the socket establishment.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Sep 2011
    Posts
    12

    Default

    Hi Avinash,

    are you sure that connection is not established? Do you see error in log? I tried your sample and response is 400: Bad request - which is OK since I don't know required POST/GET params for this URL. But fetching https://accounts.google.com works fine. Btw. how do you send messages to requestChannel?

  4. #4
    Join Date
    Dec 2011
    Location
    Hyderabad, India
    Posts
    16

    Default

    Hi,

    Thanks for the replies.

    I am trying to send request like this.

    ApplicationContext context = new ClassPathXmlApplicationContext("config-http.xml");
    JSONObject json = new JSONObject();
    //creating JSON
    Message<?> message = MessageBuilder.withPayload(json.toString()).build( );
    context.getBean("requestChannel", MessageChannel.class).send(message);
    But, it's not working. Even tried sending request to integration in a different way like this:

    ApplicationContext context = new ClassPathXmlApplicationContext("config-http.xml");
    JSONObject json = new JSONObject();
    //creating JSON
    Message<?> message = MessageBuilder.withPayload(json.toString()).build( );
    ChannelResolver resolver = new BeanFactoryChannelResolver(context);
    MessageChannel channel = resolver.resolveChannelName("requestChannel");
    channel.send(message);
    This is the error message while sending request in both the cases.

    WARNING: POST request for "https://login.salesforce.com/services/oauth2/token" resulted in 400 (Bad Request); invoking error handler
    Exception in thread "main" org.springframework.integration.MessageHandlingExc eption: HTTP request execution failed for URI [https://login.salesforce.com/services/oauth2/token]
    at org.springframework.integration.http.outbound.Http RequestExecutingMessageHandler.handleRequestMessag e(HttpRequestExecutingMessageHandler.java:284)
    at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:97)
    at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
    at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :114)
    at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:1 01)
    at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:61)
    at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:157)
    at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:128)
    at blog.HTTPDemo.main(HTTPDemo.java:59)
    Caused by: org.springframework.web.client.HttpClientErrorExce ption: 400 Bad Request
    at org.springframework.web.client.DefaultResponseErro rHandler.handleError(DefaultResponseErrorHandler.j ava:76)
    at org.springframework.web.client.RestTemplate.handle ResponseError(RestTemplate.java:486)
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:443)
    at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:409)
    at org.springframework.web.client.RestTemplate.exchan ge(RestTemplate.java:384)
    at org.springframework.integration.http.outbound.Http RequestExecutingMessageHandler.handleRequestMessag e(HttpRequestExecutingMessageHandler.java:258)
    ... 8 more

    How are you guys sending message to the request channel. Could you please share some sample code that work's.

    Thanks in Advance!!!
    Last edited by AvinashMunaga; Mar 8th, 2012 at 01:16 AM.

  5. #5
    Join Date
    Sep 2011
    Posts
    12

    Default

    This looks like rather problem during authentication, not connection problem of SI. You should check that all of required authentication parameters are set. Also, while I didn't work with OAuth, I think that you should use POST request:
    Code:
    <int-http:outbound-gateway http-method="POST"...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •