[jboss-svn-commits] JBL Code SVN: r6626 - labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 5 17:29:39 EDT 2006


Author: jokum
Date: 2006-10-05 17:29:38 -0400 (Thu, 05 Oct 2006)
New Revision: 6626

Added:
   labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/HttpListener.java
Log:
Implementation HttpListener

Added: labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/HttpListener.java
===================================================================
--- labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/HttpListener.java	2006-10-05 21:28:32 UTC (rev 6625)
+++ labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/HttpListener.java	2006-10-05 21:29:38 UTC (rev 6626)
@@ -0,0 +1,211 @@
+package org.jboss.soa.esb.listeners;
+
+import java.util.concurrent.Future;
+
+import javax.management.MBeanServer;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.DomElement;
+
+/**
+ * Http listener implementation using the JBoss Remoting channel.
+ * 
+ * The listener will listen to messages on the configured listenHttpUrl. If this is not set, the default
+ * http://localhost:5400 will be used.
+ * 
+ *  Sample listener Configuration:
+ *  
+ *  <HttpListenerTest listenerClass="org.jboss.soa.esb.listeners.HttpInvocationListener" actions="HttpInvocationToFile"/>
+
+ * <pre>
+ * &lt;HttpListener listenerClass="org.jboss.soa.esb.listeners.HttpInvocationListener" actions="ObjectToFile" listenHttpUrl="http://localhost:8800"&gt; *     
+ * &lt;/HttpListener&gt;
+ * </pre>
+ * 
+ * <pre>
+ * &lt;HttpListener listenerClass="org.jboss.soa.esb.listeners.HttpInvocationListener" actions="ObjectToFile"&gt; *     
+ * &lt;/HttpListener&gt;
+ * </pre>
+ * 
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ *
+ */
+public class HttpListener extends AbstractListener implements
+		ServerInvocationHandler {
+
+	/* The logger for this class */
+	protected Logger logger = Logger.getLogger(HttpListener.class);
+
+	/* Boolean indicating whether the info logging level is enabled */
+	protected boolean info = this.logger.isInfoEnabled();
+
+	/* The url this listener will listen on */
+	private static final String LISTEN_HTTP_URL = "listenHttpUrl";
+
+	/* The url to listen on */
+	public String listenHttpUrl = null;
+
+	/* The default transport this listener will listen on */
+	private static final String transport = "http";
+
+	/* The default hostname this listener will listen on */
+	private static final String host = "localhost";
+
+	/* The default port this listener will listen on */
+	private static final int port = 5400;
+
+	/**
+	 * Constructor initialising this HttpListener
+	 * 
+	 * @param commandListener
+	 * @param listenerConfig
+	 * @param actionDefinitionFactory
+	 * @throws Exception
+	 */
+	public HttpListener(GpListener commandListener,
+			DomElement listenerConfig,
+			ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+		super(commandListener, listenerConfig, actionDefinitionFactory);		
+		this.checkParams();
+		this.initServer();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jboss.remoting.ServerInvocationHandler#invoke(org.jboss.remoting.InvocationRequest)
+	 */
+	@SuppressWarnings("unchecked")
+	public Object invoke(InvocationRequest invocationRequest) throws Throwable {
+		//Retrieving the real payload of this invocationRequest
+		Object payload = invocationRequest.getRequestPayload();
+		if (this.logger.isInfoEnabled()){
+			this.logger.info("HttpInvocationListener is invoked...The given payload is : " + payload);
+		}
+		
+		//Eventually delay the action pipeline execution if no thread is available
+		ActionProcessingPipeline pipelineRunner = new ActionProcessingPipeline(payload);
+		Future submit = this.pipelineExecutorPool.submit(pipelineRunner);		
+		return submit.get();
+	}
+
+	/**
+	 * Adds a callback handler that will listen for callbacks from the server
+	 * invoker handler.
+	 * 
+	 * @param callbackHandler
+	 */
+	public void addListener(InvokerCallbackHandler callbackHandler) {
+		// NO OP as do not handling callback listeners in this example
+	}
+
+	/**
+	 * Removes the callback handler that was listening for callbacks from the
+	 * server invoker handler.
+	 * 
+	 * @param callbackHandler
+	 */
+	public void removeListener(InvokerCallbackHandler callbackHandler) {
+		// NO OP as do not handling callback listeners in this example
+	}
+
+	/**
+	 * set the mbean server that the handler can reference
+	 * 
+	 * @param server
+	 */
+	public void setMBeanServer(MBeanServer server) {
+		// NO OP as do not need reference to MBeanServer for this handler
+	}
+
+	/**
+	 * set the invoker that owns this handler
+	 * 
+	 * @param invoker
+	 */
+	public void setInvoker(ServerInvoker invoker) {
+		// NO OP as do not need reference back to the server invoker
+	}	
+
+	/**
+	 * Method getting the url this HttpListener instance is listening on
+	 * @return the current listenHttpUrl
+	 */
+	public String getListenHttpUrl() {
+		return listenHttpUrl;
+	}
+
+	/**
+	 * Method setting the listenHttpUrl property to listen on
+	 * @param listenHttpUrl the listenHttpUrl to be used by this HttpListener instance
+	 */
+	public void setListenHttpUrl(String listenHttpUrl) {
+		this.listenHttpUrl = listenHttpUrl;
+	}
+
+	@Override
+	protected void processingError(Object initialMessage,
+			ActionProcessor processor, Throwable error) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	protected void processingComplete(Object initialMessage) {
+	}
+
+	/**
+	 * Check for mandatory and optional attributes in parameter tree
+	 */
+	private void checkParams() throws Exception {
+		// listener url
+		this.listenHttpUrl = GpListener.obtainAtt(this.listenerConfig,
+				LISTEN_HTTP_URL, this.getDefaultListenHttpUrl());
+	}
+
+	/**
+	 * Method returning the default listenHttpUrl for this HttpListener instance
+	 * 
+	 * @return the default listen url
+	 */
+	private String getDefaultListenHttpUrl() {
+		return HttpListener.transport + "://"
+				+ HttpListener.host + ":"
+				+ HttpListener.port;
+	}
+
+	/**
+	 * Method initialising the remoting deamon
+	 * 
+	 * @throws Exception
+	 *             when something goes wrong during remoting deamon startup
+	 */
+	private void initServer() throws Exception {
+		InvokerLocator locator = new InvokerLocator(this.listenHttpUrl);
+		if (this.logger.isInfoEnabled()) {
+			this.logger.info("Starting remoting server with locator uri of: "
+					+ this.listenHttpUrl);
+		}
+		Connector connector = new Connector(locator);
+		connector.create();
+
+		connector.addInvocationHandler("HttpInvocationHandler", this);
+
+		// Starting the server deamon
+		connector.start();
+
+		if (this.logger.isInfoEnabled()) {
+			this.logger.info("HttpListener deamon started successfully!");
+		}
+
+	}
+
+}




More information about the jboss-svn-commits mailing list