[jboss-svn-commits] JBL Code SVN: r7331 - labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/actions/routing
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Nov 2 10:39:49 EST 2006
Author: jokum
Date: 2006-11-02 10:39:47 -0500 (Thu, 02 Nov 2006)
New Revision: 7331
Added:
labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/actions/routing/HttpRouter.java
Log:
HttpRouter implementation
Added: labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/actions/routing/HttpRouter.java
===================================================================
--- labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/actions/routing/HttpRouter.java 2006-11-02 15:31:00 UTC (rev 7330)
+++ labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/actions/routing/HttpRouter.java 2006-11-02 15:39:47 UTC (rev 7331)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions.routing;
+
+import java.io.Serializable;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+
+/**
+ * HttpRouter Action Processor. This ActionProcessor will forward the message to an url for further processing.
+ * If the routeUrl property is not set a default url will be used.
+ *
+ * <p/> Sample Action Configuration:
+ *
+ * <pre>
+ * <Action class="org.jboss.soa.esb.actions.routing.HttpRouter">
+ * <property name="routeUrl" value="http://localhost:8888"</property>
+ * </Action>
+ * </pre>
+ *
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ */
+public class HttpRouter implements ActionProcessor {
+
+ /* The logger for this class */
+ private static Logger logger = Logger.getLogger(HttpRouter.class);
+
+ /* The configuration for this ActionProcessor */
+ private ConfigTree configTree = null;
+
+ /* The url to route the message to */
+ private String urlToRouteTo = null;
+
+ /*
+ * The url to route the message to if the url was not set in the
+ * configuration
+ */
+ private static final String DEFAULT_URL_TO_ROUTE_TO = "http://localhost:5400";
+
+ /**
+ * Constructing a HttpRouter instance
+ *
+ * @param configTree
+ * the configuration to use in this HttpRouter instance
+ */
+ public HttpRouter(ConfigTree configTree) {
+ this.configTree = configTree;
+ this.urlToRouteTo = this
+ .obtainAttribute(ListenerTagNames.HTTP_ROUTER_ROUTE_URL,
+ DEFAULT_URL_TO_ROUTE_TO);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public org.jboss.soa.esb.message.Message process(
+ org.jboss.soa.esb.message.Message message)
+ throws ActionProcessingException {
+
+ Object oCurr = ActionUtils.getTaskObject(message);
+
+ if (logger.isInfoEnabled()) {
+ logger
+ .info("HttpRouter currently routing message " + message
+ + " with payload <<" + oCurr + ">> to "
+ + this.urlToRouteTo);
+ }
+
+ try {
+ InvokerLocator locator = new InvokerLocator(this.urlToRouteTo);
+
+ Client remotingClient = new Client(locator);
+ remotingClient.connect();
+
+ remotingClient.invoke(oCurr, null);
+ return message;
+ } catch (Throwable e) {
+ String errorMessage = "Exception while sending message [" + oCurr
+ + "] to destination [" + this.urlToRouteTo + "].";
+ logger.error(errorMessage, e);
+ throw new ActionProcessingException(errorMessage, e);
+ }
+ }
+
+ /**
+ * Method obtaining an attribute from the configuration tree
+ *
+ * @param tree
+ * the configuration to use
+ * @param p_sAtt
+ * the name of the attribute to get
+ * @param p_sDefault
+ * the default value for the attribute if not set
+ * @return the value of the attribute or the default one is not set in
+ * configuration tree
+ */
+ private String obtainAttribute(String p_sAtt, String p_sDefault) {
+ String sVal = this.configTree.getAttribute(p_sAtt);
+ return (null != sVal) ? sVal : p_sDefault;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(
+ org.jboss.soa.esb.message.Message message) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(
+ org.jboss.soa.esb.message.Message message) {
+ return null;
+ }
+
+}
More information about the jboss-svn-commits
mailing list