Commit in servicemix/base/src/main/java/org/servicemix on MAIN
components/util/MockServiceComponent.java+111added 1.1
               /EchoComponent.java+2-21.3 -> 1.4
jbi/jaxp/ResourceSource.java+57added 1.1
components/http/HttpMarshaler.java+2-31.4 -> 1.5
+172-5
2 added + 2 modified, total 4 files
added a MockServiceComponent which is capable of stubbing out any componet or service with a simple static response, either via a Source POJO, a String or a separate Resource

servicemix/base/src/main/java/org/servicemix/components/util
MockServiceComponent.java added at 1.1
diff -N MockServiceComponent.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MockServiceComponent.java	22 Sep 2005 11:06:33 -0000	1.1
@@ -0,0 +1,111 @@
+/**
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+package org.servicemix.components.util;
+
+import org.servicemix.MessageExchangeListener;
+import org.servicemix.jbi.jaxp.ResourceSource;
+import org.servicemix.jbi.jaxp.StringSource;
+import org.springframework.core.io.Resource;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * A simple mock service component which is hard coded with a response to give
+ * which can be very useful for mocking out a web service call with some static
+ * response. For more complex requirements consider using a Script component or
+ * maybe a Jelly based component etc.
+ * 
+ * @version $Revision$
+ */
+public class MockServiceComponent extends TransformComponentSupport implements MessageExchangeListener {
+    private Source responseContent;
+    private String responseXml;
+    private Resource responseResource;
+    private Map responseProperties;
+
+    public Source getResponseContent() {
+        if (responseContent == null) {
+            if (responseXml != null) {
+                responseContent = new StringSource(responseXml);
+            }
+            else if (responseResource != null) {
+                return new ResourceSource(responseResource);
+            }
+        }
+        return responseContent;
+    }
+
+    public void setResponseContent(Source responseContent) {
+        this.responseContent = responseContent;
+    }
+
+    public Map getResponseProperties() {
+        return responseProperties;
+    }
+
+    public void setResponseProperties(Map responseProperties) {
+        this.responseProperties = responseProperties;
+    }
+
+    public String getResponseXml() {
+        return responseXml;
+    }
+
+    public void setResponseXml(String responseXml) {
+        this.responseXml = responseXml;
+    }
+
+    public Resource getResponseResource() {
+        return responseResource;
+    }
+
+    public void setResponseResource(Resource responseResource) {
+        this.responseResource = responseResource;
+    }
+
+    // Implementation methods
+    // -------------------------------------------------------------------------
+    protected void init() throws JBIException {
+        super.init();
+        if (getResponseContent() == null) {
+            throw new IllegalArgumentException("You must specify the 'responseContent', 'responseXml' or 'responseResource' properties");
+        }
+    }
+
+    protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+        getMessageTransformer().transform(exchange, in, out);
+        out.setContent(getResponseContent());
+        Map map = getResponseProperties();
+        if (map != null) {
+            for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
+                Map.Entry entry = (Map.Entry) iter.next();
+                String name = (String) entry.getKey();
+                Object value = entry.getValue();
+                out.setProperty(name, value);
+            }
+        }
+        return true;
+    }
+}

servicemix/base/src/main/java/org/servicemix/components/util
EchoComponent.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- EchoComponent.java	30 Aug 2005 11:29:52 -0000	1.3
+++ EchoComponent.java	22 Sep 2005 11:06:33 -0000	1.4
@@ -27,11 +27,11 @@
 /**
  * A simple, yet useful component for testing synchronous flows. Echos back Exchanges
  * 
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  */
 public class EchoComponent extends TransformComponentSupport implements MessageExchangeListener {
     private static final Log log = LogFactory.getLog(EchoComponent.class);
-
+    
     protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
         getMessageTransformer().transform(exchange, in, out);
         log.info("Echoed back message: " + out);

servicemix/base/src/main/java/org/servicemix/jbi/jaxp
ResourceSource.java added at 1.1
diff -N ResourceSource.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ResourceSource.java	22 Sep 2005 11:06:33 -0000	1.1
@@ -0,0 +1,57 @@
+/**
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+package org.servicemix.jbi.jaxp;
+
+import org.springframework.core.io.Resource;
+
+import javax.xml.transform.stream.StreamSource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+/**
+ * A JAXP [EMAIL PROTECTED] StreamSource} which uses a Spring [EMAIL PROTECTED] Resource} as the source of the input stream.
+ * This implementation is re-entrant and can be used as many times as required to parse XML.
+ * 
+ * @version $Revision$
+ */
+public class ResourceSource extends StreamSource {
+
+    private final Resource resource;
+
+    public ResourceSource(Resource resource) {
+        this.resource = resource;
+    }
+
+    public InputStream getInputStream() {
+        try {
+            return resource.getInputStream();
+        }
+        catch (IOException e) {
+            throw new RuntimeException("Failed to open resouce: " + resource + ". Reason: " + e, e); 
+        }
+    }
+
+    public Reader getReader() {
+        return new InputStreamReader(getInputStream());
+    }
+
+    
+}

servicemix/base/src/main/java/org/servicemix/components/http
HttpMarshaler.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- HttpMarshaler.java	20 Sep 2005 14:39:29 -0000	1.4
+++ HttpMarshaler.java	22 Sep 2005 11:06:33 -0000	1.5
@@ -37,14 +37,13 @@
 /**
  * A class which marshalls a HTTP request to a NMS message
  * 
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
  */
 public class HttpMarshaler extends MarshalerSupport {
 
     protected static final Source EMPTY_CONTENT = new StringSource("<payload/>");
 
-    // could be "application/soap+xml"
-    private String contentType = "application/xml";
+    private String contentType = "text/xml";
 
     public void toNMS(MessageExchange exchange, NormalizedMessage inMessage, HttpServletRequest request) throws IOException, MessagingException {
         addNmsProperties(inMessage, request);
CVSspam 0.2.8



Reply via email to