svn commit: r550760 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ components/camel-cxf/src/main/java/org/apache/camel/component/cxf/ components/camel-http/src/main/java/org/apache...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r550760 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ components/camel-cxf/src/main/java/org/apache/camel/component/cxf/ components/camel-http/src/main/java/org/apache...

jstrachan-2
Author: jstrachan
Date: Tue Jun 26 03:02:56 2007
New Revision: 550760

URL: http://svn.apache.org/viewvc?view=rev&rev=550760
Log:
made it easy to avoid auto-creating an Out message via a new getOut(false) method. Also added a real basic HttpProducer using commons-httpclient

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java
    activemq/camel/trunk/components/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiExchange.java
    activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
    activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailExchange.java
    activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppExchange.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Tue Jun 26 03:02:56 2007
@@ -82,10 +82,19 @@
     Message getIn();
 
     /**
-     * Returns the aresponse message
+     * Returns the outbound message, lazily creating one if one has not already been associated with this exchange.
+     * If you want to inspect this property but not force lazy creation then invoke the {@link #getOut(boolean)} method
+     * passing in null
+     *
      * @return the response
      */
     Message getOut();
+
+    /**
+     * Returns the outbound message; optionally lazily creating one if one has not been associated with this exchange
+     * @return the response
+     */
+    Message getOut(boolean lazyCreate);
 
     /**
      * Returns the fault message

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java Tue Jun 26 03:02:56 2007
@@ -126,7 +126,11 @@
     }
 
     public Message getOut() {
-        if (out == null) {
+        return getOut(true);
+    }
+
+    public Message getOut(boolean lazyCreate) {
+        if (out == null && lazyCreate) {
             out = createOutMessage();
             configureMessage(out);
         }

Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java Tue Jun 26 03:02:56 2007
@@ -73,6 +73,11 @@
     }
 
     @Override
+    public CxfMessage getOut(boolean lazyCreate) {
+        return (CxfMessage) super.getOut(lazyCreate);
+    }
+
+    @Override
     public CxfMessage getFault() {
         return (CxfMessage) super.getFault();
     }

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java Tue Jun 26 03:02:56 2007
@@ -46,8 +46,8 @@
  this.httpUri = new URI(uri);
     }
 
-    public Producer<HttpExchange> createProducer() throws Exception {
-     throw new RuntimeCamelException("Not implemented.");
+    public HttpProducer createProducer() throws Exception {
+     return new HttpProducer(this);
     }
 
     public Consumer<HttpExchange> createConsumer(Processor processor) throws Exception {

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Tue Jun 26 03:02:56 2007
@@ -17,8 +17,49 @@
  */
 package org.apache.camel.component.http;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+import java.io.InputStream;
+
 /**
  * @version $Revision: 1.1 $
  */
-public class HttpProducer {
+public class HttpProducer extends DefaultProducer<HttpExchange> implements Producer<HttpExchange> {
+    private HttpClient httpClient = new HttpClient();
+
+    public HttpProducer(HttpEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        String uri = getEndpoint().getEndpointUri();
+        HttpMethod method = createMethod(uri);
+        int responseCode = httpClient.executeMethod(method);
+
+        // lets store the result in the output message.
+        InputStream in = method.getResponseBodyAsStream();
+        Message out = exchange.getOut(true);
+        out.setBody(in);
+
+        // lets set the headers
+        Header[] headers = method.getResponseHeaders();
+        for (Header header : headers) {
+            String name = header.getName();
+            String value = header.getValue();
+            out.setHeader(name, value);
+        }
+
+        out.setHeader("http.responseCode", responseCode);
+    }
+
+    protected PostMethod createMethod(String uri) {
+        return new PostMethod(uri);
+    }
 }

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java (original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java Tue Jun 26 03:02:56 2007
@@ -52,6 +52,11 @@
     }
 
     @Override
+    public IrcMessage getOut(boolean lazyCreate) {
+        return (IrcMessage) super.getOut(lazyCreate);
+    }
+
+    @Override
     public IrcMessage getFault() {
         return (IrcMessage) super.getFault();
     }

Modified: activemq/camel/trunk/components/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiExchange.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/components/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiExchange.java (original)
+++ activemq/camel/trunk/components/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiExchange.java Tue Jun 26 03:02:56 2007
@@ -61,6 +61,11 @@
     }
 
     @Override
+    public JbiMessage getOut(boolean lazyCreate) {
+        return (JbiMessage) super.getOut(lazyCreate);
+    }
+
+    @Override
     public JbiMessage getFault() {
         return (JbiMessage) super.getFault();
     }

Modified: activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java (original)
+++ activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java Tue Jun 26 03:02:56 2007
@@ -52,6 +52,11 @@
     }
 
     @Override
+    public JmsMessage getOut(boolean lazyCreate) {
+        return (JmsMessage) super.getOut(lazyCreate);
+    }
+
+    @Override
     public JmsMessage getFault() {
         return (JmsMessage) super.getFault();
     }

Modified: activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailExchange.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailExchange.java (original)
+++ activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailExchange.java Tue Jun 26 03:02:56 2007
@@ -52,6 +52,11 @@
     }
 
     @Override
+    public MailMessage getOut(boolean lazyCreate) {
+        return (MailMessage) super.getOut(lazyCreate);
+    }
+
+    @Override
     public MailMessage getFault() {
         return (MailMessage) super.getFault();
     }

Modified: activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppExchange.java?view=diff&rev=550760&r1=550759&r2=550760
==============================================================================
--- activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppExchange.java (original)
+++ activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppExchange.java Tue Jun 26 03:02:56 2007
@@ -51,6 +51,11 @@
     }
 
     @Override
+    public XmppMessage getOut(boolean lazyCreate) {
+        return (XmppMessage) super.getOut(lazyCreate);
+    }
+
+    @Override
     public XmppMessage getFault() {
         return (XmppMessage) super.getFault();
     }