activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve.V." <stephen.vinc...@sas.com>
Subject Re: No correlation ID in HTTP header when using RESTful interface
Date Mon, 24 Sep 2012 14:33:39 GMT
I modified the test program I included in my last post, so that it prints the
headers.  I believe this test illustrates that the correlation ID is not
coming back in an HTTP header.  When I run the test below, here is an
example of what it prints:
----------------
    Set-Cookie: JSESSIONID=b27ojdkduucinp4h2icpuu0a;Path=/demo
    Content-Type: text/xml;charset=UTF-8
    id: ID:d22275-3589-1348496728952-1:1:1:1:1
    Server: Jetty(7.6.1.v20120215)
    HTTP/1.1 200 OK
    Hello
---------------

Here is the test:
------------------------------
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class CorrelId
{
  public static void main( String[] args ) throws Exception
  {
    ActiveMQConnectionFactory conFac;
    Connection          connection;
    Session             session;
    Destination         destination;
    MessageProducer     producer;
    DefaultHttpClient   httpClient;

    try
    {
        conFac = new ActiveMQConnectionFactory(
                                "tcp://localhost:61616" );
        connection = conFac.createConnection();
        connection.start();
        session = connection.createSession( false,
                                            Session.AUTO_ACKNOWLEDGE );
        destination = session.createQueue( "myqueue" );
        producer = session.createProducer( destination );
        producer.setDeliveryMode( DeliveryMode.NON_PERSISTENT );
        producer.setTimeToLive(60000);
        String text = "Hello";
        TextMessage message = session.createTextMessage( text );
        String correlId = "Resty 123";
        message.setStringProperty( "correlationId", correlId );
        message.setJMSCorrelationID( correlId );
        producer.send( message );

        httpClient = new DefaultHttpClient();
        HttpGet httpget = new
HttpGet("http://localhost:8161/demo/message/myqueue?readTimeout=1000&type=queue&clientId=test"
);
        HttpResponse response = httpClient.execute(httpget);
        Header[] headers = response.getAllHeaders();
        for ( int i = 0; i < headers.length; i++ )
            System.out.println( headers[i++] );
        
        // Examine the response status
        System.out.println(response.getStatusLine());

        // Get hold of the response entity
        HttpEntity entity = response.getEntity();

        if ( entity != null )
        {
            InputStream instream = entity.getContent();
            try
            {
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(instream));
                // do something useful with the response
                System.out.println(reader.readLine());
            }
            catch ( IOException ex )
            {
                // In case of an IOException the connection will be released
                // back to the connection manager automatically
                throw ex;
            } catch (RuntimeException ex) {

                // In case of an unexpected exception you may want to abort
                // the HTTP request in order to shut down the underlying
                // connection and release it back to the connection manager.
                httpget.abort();
                throw ex;
            }
            finally
            {
                // Closing the input stream will trigger connection release
                instream.close();
            }

            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpClient.getConnectionManager().shutdown();
        }
    }
    catch( Exception e )
    {
        System.out.println( e.getMessage() );
    }
  }
}
---------------



-----
Stephen Vincent
--
View this message in context: http://activemq.2283324.n4.nabble.com/No-correlation-ID-in-HTTP-header-when-using-RESTful-interface-tp4656327p4656853.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message