Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4085

jersey rest web Service with Activemq middleware integration

$
0
0

I have a Restful service API developed with JAX-RS and jersey. I have deployed the same in TOMCAT 7. Now I would like to implement Activemq so that I would keep all request in a queue and process the request resource. How to do this and integrate with tomcat7. How to integrate ActiveMq with Tomcat7 or my rest service webapp. How to call the service.

Important :- Inside the Rest Api, I am using FilterChaining concept for security concern and after verification of the calling party, I am simply forwarding the request to the resource. For this I have added in web.xml.

Thanks

Here is my class :-

    public class LimitFilter implements Filter {        public void doFilter(ServletRequest request, ServletResponse response,                FilterChain chain) throws IOException, ServletException {//some authentication                if (true) {                    // let the request through and process as usual                    chain.doFilter(request, response);                } else {                    // handle limit case, e.g. return status code 429 (Too Many                    // Requests)                    // see http://tools.ietf.org/html/rfc6585#page-3                    ((HttpServletResponse) response).sendError(429);                }            }             }        }

Here is my sample class for activemq:-

public class Qservlet extends HttpServlet {    /**     *      */    private static final long serialVersionUID = 1L;    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws IOException, ServletException {            String body = "";        try {            // Create a ConnectionFactory            ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "admin", ActiveMQConnection.DEFAULT_BROKER_URL);            // Create a Connection            Connection connection = connectionFactory.createConnection();            Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);            Destination destination = session.createQueue("testQ");             TextMessage message = session.createTextMessage();            message.setText( "My text message was send and received");//            message.setJMSRedelivered(true);            message.setJMSCorrelationID(request.getSession().getId());            connection.start();            MessageProducer producer = session.createProducer(destination);            producer.setDeliveryMode(DeliveryMode.PERSISTENT);            producer.send(message);            message = null;            MessageConsumer consumer = session.createConsumer(destination);            message = (TextMessage) consumer.receive(1000);            if (message != null) {                body = message.getText();            }            producer.close();            consumer.close();            session.close();            connection.close();        } catch (Exception e) {            System.out.println(e.toString());        }    }}

Now if any request is coming in Limit Filter class, I am forwarding directly to the resources after some authentication mecanisam. Thats why I am using filter concept for catching all request.

Second class is example class when i am running ; messaging is enquing and dequeueing; I can see in console for ActiveMq.

In the first class I am simply writing "chain.doFilter(request, response)" to forward all http request to the respective resource. Now How to do here. Where to put the HTTP request. I need to handle each request asynchronously. REST is synchronous.

Please suggest some way. and explain your answer.

Thanks/RegardsKumar Shorav


Viewing all articles
Browse latest Browse all 4085

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>