[jboss-svn-commits] JBL Code SVN: r6471 - in labs/jbossesb/trunk/product/core: listeners/src/org/jboss/soa/esb/actions listeners/tests/src/org/jboss/soa/esb/actions services/src/org/jboss/soa/esb/services services/src/org/jboss/soa/esb/services/transform
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Sep 29 12:53:12 EDT 2006
Author: tfennelly
Date: 2006-09-29 12:53:05 -0400 (Fri, 29 Sep 2006)
New Revision: 6471
Added:
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/TransformationException.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/TransformationService.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/package.html
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/SmooksTransformer.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java
Log:
Adding the Transformation Service types.
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/SmooksTransformer.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/SmooksTransformer.java 2006-09-29 14:57:48 UTC (rev 6470)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/SmooksTransformer.java 2006-09-29 16:53:05 UTC (rev 6471)
@@ -33,6 +33,8 @@
import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.services.transform.TransformationException;
+import org.jboss.soa.esb.services.transform.TransformationService;
import org.milyn.SmooksStandalone;
/**
@@ -58,7 +60,7 @@
* @since Version 4.0
*/
-public class SmooksTransformer implements ActionProcessor {
+public class SmooksTransformer implements TransformationService, ActionProcessor {
private static Logger logger = Logger.getLogger(SmooksTransformer.class);
private static final String SMOOKS_CDR_LST = "smooks-cdr.lst";
@@ -118,37 +120,52 @@
// TODO: Recurcively expand out the profiles supplied here using smooks.getContext().getProfileStore(). Do this inside SmooksStandalone
}
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.transform.TransformationService#transform(java.lang.Object)
+ */
+ public Object transform(Object message) throws TransformationException {
+ try {
+ return process(message);
+ } catch (ActionProcessingException e) {
+ throw new TransformationException(e);
+ }
+ }
+
/* (non-Javadoc)
* @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
*/
- public Object process(Object message) {
- if(message instanceof String) {
- byte[] messageBytes = null;
- String transformedMessage;
-
- try {
- messageBytes = ((String)message).getBytes(messageEnc);
- } catch (UnsupportedEncodingException e) {
- // Can't happen - encoding was already tested in the constructor.
- }
-
- // TODO: Cater for more message input types e.g. InputStream, DOM Document...
- // TODO: Cater for more message output types e.g. InputStream, DOM Document...
-
- long start = System.currentTimeMillis();
- transformedMessage = smooks.filterAndSerialize(messageUseragent, new ByteArrayInputStream(messageBytes));
- if(logger.isDebugEnabled()) {
- long timeTaken = System.currentTimeMillis() - start;
- logger.debug("Transformed message for useragent [" + messageUseragent + "]. Time taken: "
- + timeTaken + ". Message in:\n[" + message + "]. \nMessage out:\n[" + transformedMessage + "].");
- }
-
- return transformedMessage;
- } else {
- logger.warn("String message types only supported. Input message was ["
- + message.getClass().getName() + "]. Returning message untransformed.");
- return message;
- }
+ public Object process(Object message) throws ActionProcessingException {
+ try {
+ if(message instanceof String) {
+ byte[] messageBytes = null;
+ String transformedMessage;
+
+ try {
+ messageBytes = ((String)message).getBytes(messageEnc);
+ } catch (UnsupportedEncodingException e) {
+ // Can't happen - encoding was already tested in the constructor.
+ }
+
+ // TODO: Cater for more message input types e.g. InputStream, DOM Document...
+ // TODO: Cater for more message output types e.g. InputStream, DOM Document...
+
+ long start = System.currentTimeMillis();
+ transformedMessage = smooks.filterAndSerialize(messageUseragent, new ByteArrayInputStream(messageBytes));
+ if(logger.isDebugEnabled()) {
+ long timeTaken = System.currentTimeMillis() - start;
+ logger.debug("Transformed message for useragent [" + messageUseragent + "]. Time taken: "
+ + timeTaken + ". Message in:\n[" + message + "]. \nMessage out:\n[" + transformedMessage + "].");
+ }
+
+ return transformedMessage;
+ } else {
+ logger.warn("String message types only supported. Input message was ["
+ + message.getClass().getName() + "]. Returning message untransformed.");
+ return message;
+ }
+ } catch(Throwable thrown) {
+ throw new ActionProcessingException("Message transformation failed.", thrown);
+ }
}
/* (non-Javadoc)
Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java 2006-09-29 14:57:48 UTC (rev 6470)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java 2006-09-29 16:53:05 UTC (rev 6471)
@@ -58,7 +58,7 @@
assertConfigException(properties, "Failed to locate Smooks configuration list file [smooks-cdr.lst]. The folder containing this file must be located at");
}
- public void test_trans() throws ConfigurationException {
+ public void test_trans() throws ActionProcessingException, ConfigurationException {
String message;
String transRes;
@@ -77,7 +77,7 @@
assertEquals("<x><c>value</c></x>", transRes);
}
- private String transform(String message, String type, String from, String to) throws ConfigurationException {
+ private String transform(String message, String type, String from, String to) throws ActionProcessingException, ConfigurationException {
List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
// Set the message properties in order to trigger the appropriate transformations
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/TransformationException.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/TransformationException.java 2006-09-29 14:57:48 UTC (rev 6470)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/TransformationException.java 2006-09-29 16:53:05 UTC (rev 6471)
@@ -0,0 +1,60 @@
+/*
+ * 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.services.transform;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * Transformation Service Exception.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class TransformationException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Public constructor.
+ * @param message Exception message.
+ */
+ public TransformationException(String message) {
+ super(message);
+ }
+
+ /**
+ * Public constructor.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public TransformationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Public constructor.
+ * @param cause Exception cause.
+ */
+ public TransformationException(Throwable cause) {
+ super(cause);
+ }
+}
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/TransformationService.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/TransformationService.java 2006-09-29 14:57:48 UTC (rev 6470)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/TransformationService.java 2006-09-29 16:53:05 UTC (rev 6471)
@@ -0,0 +1,38 @@
+/*
+ * 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.services.transform;
+
+/**
+ * Transformation Service interface.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public interface TransformationService {
+
+ /**
+ * Transform the supplied message object and return the transformation result.
+ * @param message The message to be transformed.
+ * @return The transformed message.
+ * @throws TransformationException An Exception occured during the transformation process.
+ */
+ public Object transform(Object message) throws TransformationException;
+}
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/package.html
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/package.html 2006-09-29 14:57:48 UTC (rev 6470)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/transform/package.html 2006-09-29 16:53:05 UTC (rev 6471)
@@ -0,0 +1,8 @@
+<html>
+ <head></head>
+ <body>
+ Transformation Service.
+
+ <h2>Package Specification</h2>
+ </body>
+</html>
More information about the jboss-svn-commits
mailing list