servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsny...@apache.org
Subject svn commit: r514012 - in /incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src: main/java/org/apache/servicemix/http/endpoints/SerializedMarshaler.java test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java
Date Fri, 02 Mar 2007 23:31:56 GMT
Author: bsnyder
Date: Fri Mar  2 15:31:53 2007
New Revision: 514012

URL: http://svn.apache.org/viewvc?view=rev&rev=514012
Log:
Added improved comments.

Modified:
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/SerializedMarshaler.java
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/SerializedMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/SerializedMarshaler.java?view=diff&rev=514012&r1=514011&r2=514012
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/SerializedMarshaler.java
(original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/SerializedMarshaler.java
Fri Mar  2 15:31:53 2007
@@ -16,6 +16,8 @@
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 
@@ -23,12 +25,29 @@
 import com.thoughtworks.xstream.io.xml.DomDriver;
 
 /**
+ * A marshaler that handles Java serialized content from the InputStream of the
+ * HttpServletRequest object and to the OutputStream of the HttpServletResponse 
+ * object. This class is intended to handle requests initiated by the Spring 
+ * <a href="http://www.springframework.org/docs/api/org/springframework/remoting/httpinvoker/package-summary.html">httpinvoker
package</a> 
+ * so the marshaled/unmarshaled XML invocation will be Spring 
+ * <a href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocation.html">RemoteInvocation</a>/
+ * <a href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocationResult.html">RemoteInvocationResult</a>

+ * objects respectively. 
  * 
- * @author bsnyder
+ * <p>
+ * This class makes no assumptions about how XML should be marshaled/unmarshaled. 
+ * I.e., there is currently no way to customize the marshaled XML invocation. So  
+ * this marshaler will need to pass the XML to a component that can transform it 
+ * into some custom XML. The servicemix-saxon component can handle this very 
+ * easily via XLST. 
+ * 
+ * @author bsnyder, aco
  * @org.apache.xbean.XBean element="serializedMarshaler"
  */
 public class SerializedMarshaler extends DefaultHttpConsumerMarshaler {
 	
+	private static Log log = LogFactory.getLog(SerializedMarshaler.class);
+	
 	public MessageExchange createExchange(HttpServletRequest request, ComponentContext context)
throws Exception {
 		MessageExchange me =
         	context.getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep());
@@ -45,7 +64,24 @@
     }
 
     /**
-     * Marshal the byte content of the input stream to an xml source
+     * Marshal the byte content of the input stream to an XML source. This method
+     * is marshaling the contents of the Spring <a href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocation.html">RemoteInvocation</a>
+     * object. Below is an example of what this method emits: 
+     * 
+     * <pre>
+     * <?xml version="1.0" encoding="UTF-8"?><org.springframework.remoting.support.RemoteInvocation>
+     *   <methodName>login</methodName>
+     *     <parameterTypes>
+     *       <java-class>java.lang.String</java-class>
+     *       <java-class>java.lang.String</java-class>
+     *     </parameterTypes>
+     *     <arguments>
+     *       <string>foo</string>
+     *       <string>bar</string>
+     *     </arguments>
+     *   </org.springframework.remoting.support.RemoteInvocation>
+     * </pre>
+     * 
      * @param is - input stream to read the object from
      * @return xml source
      * @throws IOException
@@ -56,21 +92,46 @@
 		Writer w = new StringWriter();
 		XStream xstream = new XStream(new DomDriver());
 		xstream.toXML(obj, w);
-		return new StringSource(w.toString());
+		String request = w.toString();
+		
+		if (log.isDebugEnabled()) {
+			log.debug("Remote invocation request: " + request);
+		}
+		
+		return new StringSource(request);
 	}
 
     /**
-     * Unmarshal the xml content to the specified output stream
+     * Unmarshal the XML content to the specified output stream. This method is 
+     * unmarshaling XML into the Spring <a href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocationResult.html">RemoteInvocationResult</a>

+     * object. Below is an example of the XML expected by this method: 
+     * 
+     * <pre>
+     * <?xml version="1.0" encoding="UTF-8"?>
+     * <org.springframework.remoting.support.RemoteInvocationResult>
+     *   <value class="com.example.foo.bar.Baz">
+     *     <firstName>myfirstname</firstName>
+     *     <lastName>mylastname</lastName>
+     *     <phone>12312312</phone>
+     *   </value>
+     * </org.springframework.remoting.support.RemoteInvocationResult>
+     * </pre> 
+     * 
      * @param os - output stream to unmarshal to
-     * @param content - xml source
+     * @param content - XML source
      * @throws TransformerException
      * @throws IOException
      */
     private void unmarshal(OutputStream os, Source content) throws TransformerException,
IOException {
         SourceTransformer transform = new SourceTransformer();
         XStream xstream = new XStream(new DomDriver());
-
-        Object obj = xstream.fromXML(transform.toString(content));
+        String result = transform.toString(content);
+		
+		if (log.isDebugEnabled()) {
+			log.debug("Remote invocation result: " + result);
+		}
+		
+        Object obj = xstream.fromXML(result);
         ObjectOutputStream oos = new ObjectOutputStream(os);
         oos.writeObject(obj);
     }

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java?view=diff&rev=514012&r1=514011&r2=514012
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java
(original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java
Fri Mar  2 15:31:53 2007
@@ -47,20 +47,24 @@
     public void testUsingSpringHttpRemoting() throws Exception {
         final Person person = new PersonImpl("Hunter", "Thompson", 67);
 
+        // Create a consumer endpoint 
         HttpConsumerEndpoint ep = new HttpConsumerEndpoint();
         ep.setService(new QName("urn:HttpConsumer", "HttpConsumer"));
         ep.setEndpoint("HttpConsumer");
         ep.setLocationURI("http://localhost:8192/service/");
         ep.setTargetService(new QName("urn:HttpInvoker", "Endpoint"));
 
+        // Configure the SerializedMarshaler and specifiy it on the endpoint 
         SerializedMarshaler marshaler = new SerializedMarshaler();
         marshaler.setDefaultMep(MessageExchangeSupport.IN_OUT);
         ep.setMarshaler(marshaler);
 
+        // Add the endpoint to the component and activate it
         HttpComponent component = new HttpComponent();
         component.setEndpoints(new HttpEndpointType[] { ep });
         container.activateComponent(component, "HttpConsumer");
 
+        // Dummy up a component as a receiver and route it to urn:HttpInvoker/Endpoint
         TransformComponentSupport rmiComponent = new TransformComponentSupport() {
             protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage
out) throws MessagingException {
                 try {
@@ -84,16 +88,19 @@
         };
         ActivationSpec asReceiver = new ActivationSpec("rmiComponent", rmiComponent);
         asReceiver.setService(new QName("urn:HttpInvoker", "Endpoint"));
-
         container.activateComponent(asReceiver);
+        
+        // Start the JBI container
         container.start();
 
+        // Set up the Spring bean to call into the URL specified for the consumer endpoint
         HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
         pfb.setServiceInterface(Person.class);
         pfb.setServiceUrl("http://localhost:8192/service/");
         pfb.setHttpInvokerRequestExecutor(new SimpleHttpInvokerRequestExecutor());
         pfb.afterPropertiesSet();
 
+        // Grab the object via the proxy factory bean 
         Person test = (Person)pfb.getObject();
 
         // Test getters



Mime
View raw message