I'd like to do the following and I'm not quite sure if I'm not wasting my time: I'm trying to run ActiveMQ embedded broker inside a weblogic servlet. The idea is, that the clients will be able to connect to JMS via http and the embedded broker would serve the requests. I know that this is a crazy idea, but it's a legacy application and a lot of the client code depends on JMS. The idea is just to switch the connection string and add libraries to clients. It works fine when I create the tcp connection, but I have no idea how to map a servlet to the internal broker
The restrictions are these:
- No changes in weblogic configuration(like datasources, bridges, JMS etc)
- No Spring
- HTTP only
This is the servlet definition from web.xml:
<servlet>
<servlet-name>ActiveMQServlet</servlet-name>
<servlet-class>com.mycompany.ActiveMQServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ActiveMQ</servlet-name>
<url-pattern>/servlet/ActiveMQServlet</url-pattern>
</servlet-mapping>
Important parts of the servlet:
public class ActiveMQServlet extends HttpServlet {
private BrokerService broker;
private static final Log log = LogFactory.getLog(new Object() {
}.getClass().getEnclosingClass());
@Override
public void init() throws ServletException {
log.info("Load activeMQ");
// configure the broker
try {
TransportConnector connector = new TransportConnector();
connector.setUri(new URI(ACTIVE_MQ_URL));
broker = new BrokerService();
broker.addConnector(connector);
broker.start();
log.info("ActiveMQ loaded succesfully");
} catch (Exception e) {
log.error("Unable to load ActiveMQ!", e);
}
}
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("Received call.... ");
log.info("Request: "+request);
//todo
}
The problem is I have no idea how to do a request/response mapping between the service method of the servlet and internal ActiveMQ broker. Another thing is, that I'm trying to solve some classpath clashes caused by slf4j which is used by ActiveMQ broker and already spent some hours on it. But maybe I'm just doing something which is impossible/really stupid.
When I'm trying to connect via simple client, I'm getting this exception
javax.jms.JMSException: Could not connect to broker URL: http://localhost:8888/myapp/servlet/ActiveMQServlet. Reason: java.io.IOException: Failed to perform GET on: http://localhost:8888/myapp/servlet/ActiveMQServlet as response was: Not Found
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:293)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:191)
...
Caused by: java.io.IOException: Failed to perform GET on: http://localhost:8888/myapp/servlet/ActiveMQServlet as response was: Not Found
at org.apache.activemq.transport.http.HttpClientTransport.doStart(HttpClientTransport.java:275)
at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:55)
While doing this, the code in the servlet is not executed. The servlet path is fine. If I open it in the browser, I got empty page and log message.
I'm using ActiveMQ 5.8.0 and Weblogic 10.3.6
staticto work at all. Anyway, AFAIK Weblogic contains a "real" JMS. Sorry, I consider this to be a hack. - Beryllium