servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r406601 - in /incubator/servicemix/trunk/servicemix-components/src: main/java/org/apache/servicemix/components/http/ test/java/org/apache/servicemix/components/http/
Date Mon, 15 May 2006 10:18:03 GMT
Author: gnodet
Date: Mon May 15 03:17:56 2006
New Revision: 406601

URL: http://svn.apache.org/viewcvs?rev=406601&view=rev
Log:
Put cgi headers in a map instead of directly on the exchange.
All http headers are on messages, not exchanges.

Modified:
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpClientMarshaler.java
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInvoker.java
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpMarshaler.java
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapClientMarshaler.java
    incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpClientMarshaler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpClientMarshaler.java?rev=406601&r1=406600&r2=406601&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpClientMarshaler.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpClientMarshaler.java
Mon May 15 03:17:56 2006
@@ -40,7 +40,8 @@
 
     protected SourceTransformer sourceTransformer;
     private boolean streaming;
-    
+    private String contentType = "text/xml";
+
     public HttpClientMarshaler() {
         this(false);
     }
@@ -50,6 +51,34 @@
         this.streaming = streaming;
     }
 
+    /**
+     * @return the streaming
+     */
+    public boolean isStreaming() {
+        return streaming;
+    }
+
+    /**
+     * @param streaming the streaming to set
+     */
+    public void setStreaming(boolean streaming) {
+        this.streaming = streaming;
+    }
+
+    /**
+     * @return the contentType
+     */
+    public String getContentType() {
+        return contentType;
+    }
+
+    /**
+     * @param contentType the contentType to set
+     */
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
+    }
+
     public void toNMS(NormalizedMessage normalizedMessage, HttpMethod method) throws Exception
{
         addNmsProperties(normalizedMessage, method);
         if (streaming) {
@@ -60,7 +89,10 @@
     }
 
     public void fromNMS(PostMethod method, MessageExchange exchange, NormalizedMessage normalizedMessage)
throws Exception, TransformerException {
-        addHttpHeaders(method, exchange);
+        addHttpHeaders(method, normalizedMessage);
+        if (method.getRequestHeader("Content-Type") == null) {
+            method.setRequestHeader("Content-Type", contentType);
+        }
         if (streaming) {
             method.setContentChunked(true);
             Source src = normalizedMessage.getContent();
@@ -78,11 +110,11 @@
         }
     }
 
-    protected void addHttpHeaders(HttpMethod method, MessageExchange exchange) {
-        for (Iterator iter = exchange.getPropertyNames().iterator(); iter.hasNext();) {
+    protected void addHttpHeaders(HttpMethod method, NormalizedMessage message) {
+        for (Iterator iter = message.getPropertyNames().iterator(); iter.hasNext();) {
             String name = (String) iter.next();
-            Object value = exchange.getProperty(name);
-            if (shouldIncludeHeader(exchange, name, value)) {
+            Object value = message.getProperty(name);
+            if (shouldIncludeHeader(message, name, value)) {
                 method.addRequestHeader(name, value.toString());
             }
         }
@@ -98,22 +130,14 @@
         }
     }
 
-
     /**
      * Decides whether or not the given header should be included in the JMS message.
      * By default this includes all suitable typed values
      */
-    protected boolean shouldIncludeHeader(MessageExchange exchange, String name, Object value)
{
+    protected boolean shouldIncludeHeader(NormalizedMessage normalizedMessage, String name,
Object value) {
         return value instanceof String && 
                 !"Content-Length".equalsIgnoreCase(name) &&
                 !"Content-Type".equalsIgnoreCase(name);
     }
 
-    public boolean isStreaming() {
-        return streaming;
-    }
-
-    public void setStreaming(boolean streaming) {
-        this.streaming = streaming;
-    }
 }

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInvoker.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInvoker.java?rev=406601&r1=406600&r2=406601&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInvoker.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInvoker.java
Mon May 15 03:17:56 2006
@@ -52,9 +52,6 @@
         PostMethod method = new PostMethod(url);
         try {
             marshaler.fromNMS(method, exchange, in);
-            if (method.getRequestHeader("Content-Type") == null) {
-                method.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
-            }
             if (url != null) {
                 hostConfiguration.setHost(new URI(url, false));
             }

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpMarshaler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpMarshaler.java?rev=406601&r1=406600&r2=406601&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpMarshaler.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpMarshaler.java
Mon May 15 03:17:56 2006
@@ -15,8 +15,11 @@
  */
 package org.apache.servicemix.components.http;
 
-import org.apache.servicemix.components.util.MarshalerSupport;
-import org.apache.servicemix.jbi.jaxp.StringSource;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.MessageExchange;
@@ -29,9 +32,8 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Iterator;
+import org.apache.servicemix.components.util.MarshalerSupport;
+import org.apache.servicemix.jbi.jaxp.StringSource;
 
 /**
  * A class which marshalls a HTTP request to a NMS message
@@ -40,6 +42,8 @@
  */
 public class HttpMarshaler extends MarshalerSupport {
 
+    public static final String CGI_HEADERS = "cgi.headers";
+    
     public static final String AUTH_TYPE = "AUTH_TYPE";
     public static final String CONTENT_LENGTH = "CONTENT_LENGTH";
     public static final String CONTENT_TYPE = "CONTENT_TYPE";
@@ -62,9 +66,33 @@
     private String contentType = "text/xml";
 
     public void toNMS(MessageExchange exchange, NormalizedMessage inMessage, HttpServletRequest
request) throws IOException, MessagingException {
-        addNmsProperties(exchange, request);
+        addNmsProperties(inMessage, request);
         String method = request.getMethod();
         if (method != null && method.equalsIgnoreCase("POST")) {
+            /*
+            Source src = null;
+            try {
+                if (request.getContentType() != null) {
+                    String charset = new MimeType(request.getContentType()).getParameter("charset");
+                    if (charset != null) {
+                        XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(request.getInputStream(),
charset);
+                        src = new StaxSource(xr);
+                    }
+                }
+                if (src == null) {
+                    XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(request.getInputStream());
+                    src = new StaxSource(xr);
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            try {
+                src = getTransformer().toDOMSource(src);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            inMessage.setContent(src);
+            */
             inMessage.setContent(new StreamSource(request.getInputStream()));
         }
         else {
@@ -99,29 +127,31 @@
 
     // Implementation methods
     // -------------------------------------------------------------------------
-    protected void addNmsProperties(MessageExchange exchange, HttpServletRequest request)
{
+    protected void addNmsProperties(NormalizedMessage message, HttpServletRequest request)
{
         Enumeration enumeration = request.getHeaderNames();
         while (enumeration.hasMoreElements()) {
             String name = (String) enumeration.nextElement();
             String value = request.getHeader(name);
-            exchange.setProperty(name, value);
+            message.setProperty(name, value);  
         }
-        exchange.setProperty(AUTH_TYPE, request.getAuthType());
-        exchange.setProperty(CONTENT_LENGTH, String.valueOf(request.getContentLength()));
-        exchange.setProperty(CONTENT_TYPE, request.getContentType());
-        exchange.setProperty(DOCUMENT_ROOT, request.getRealPath("/"));
-        exchange.setProperty(PATH_INFO, request.getPathInfo());
-        exchange.setProperty(PATH_TRANSLATED, request.getPathTranslated());
-        exchange.setProperty(QUERY_STRING, request.getQueryString());
-        exchange.setProperty(REMOTE_ADDRESS, request.getRemoteAddr());
-        exchange.setProperty(REMOTE_HOST, request.getRemoteHost());
-        exchange.setProperty(REMOTE_USER, request.getRemoteUser());
-        exchange.setProperty(REQUEST_METHOD, request.getMethod());
-        exchange.setProperty(REQUEST_URI, request.getRequestURL());
-        exchange.setProperty(SCRIPT_NAME, request.getServletPath());
-        exchange.setProperty(SERVER_NAME, request.getServerName());
-        exchange.setProperty(SERVER_PORT, String.valueOf(request.getServerPort()));
-        exchange.setProperty(SERVER_PROTOCOL, request.getProtocol());
+        Map cgi = new HashMap();
+        cgi.put(AUTH_TYPE, request.getAuthType());
+        cgi.put(CONTENT_LENGTH, String.valueOf(request.getContentLength()));
+        cgi.put(CONTENT_TYPE, request.getContentType());
+        cgi.put(DOCUMENT_ROOT, request.getRealPath("/"));
+        cgi.put(PATH_INFO, request.getPathInfo());
+        cgi.put(PATH_TRANSLATED, request.getPathTranslated());
+        cgi.put(QUERY_STRING, request.getQueryString());
+        cgi.put(REMOTE_ADDRESS, request.getRemoteAddr());
+        cgi.put(REMOTE_HOST, request.getRemoteHost());
+        cgi.put(REMOTE_USER, request.getRemoteUser());
+        cgi.put(REQUEST_METHOD, request.getMethod());
+        cgi.put(REQUEST_URI, request.getRequestURL());
+        cgi.put(SCRIPT_NAME, request.getServletPath());
+        cgi.put(SERVER_NAME, request.getServerName());
+        cgi.put(SERVER_PORT, String.valueOf(request.getServerPort()));
+        cgi.put(SERVER_PROTOCOL, request.getProtocol());
+        message.setProperty(CGI_HEADERS, cgi);
     }
     
     protected void addHttpHeaders(HttpServletResponse response, NormalizedMessage normalizedMessage)
{

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapClientMarshaler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapClientMarshaler.java?rev=406601&r1=406600&r2=406601&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapClientMarshaler.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapClientMarshaler.java
Mon May 15 03:17:56 2006
@@ -80,7 +80,7 @@
     }
 
     public void fromNMS(PostMethod method, MessageExchange exchange, NormalizedMessage normalizedMessage)
throws Exception {
-        addHttpHeaders(method, exchange);
+        addHttpHeaders(method, normalizedMessage);
         Node node = sourceTransformer.toDOMNode(normalizedMessage.getContent());
         Element elem;
         if (node instanceof Document) {

Modified: incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java?rev=406601&r1=406600&r2=406601&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
Mon May 15 03:17:56 2006
@@ -18,6 +18,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 
@@ -48,8 +49,10 @@
 
 public class HttpSoapAndSaajTest extends TestCase {
     
-    private static final int PORT = 7012;
-    private static final int PORT_WS = 7013;
+    private static final int PORT_1 = 7012;
+    private static final int PORT_2 = 7012;
+    private static final int PORT_WS_1 = 7014;
+    private static final int PORT_WS_2 = 7014;
 
     protected JBIContainer container;
 	protected BrokerService broker;
@@ -82,20 +85,20 @@
         ActivationSpec as = new ActivationSpec();
         as.setId("saaj");
         SaajBinding saaj = new SaajBinding();
-        saaj.setSoapEndpoint(new URLEndpoint("http://localhost:" + PORT_WS)); 
+        saaj.setSoapEndpoint(new URLEndpoint("http://localhost:" + PORT_WS_1)); 
         as.setComponent(saaj);
         as.setService(new QName("saaj"));
         container.activateComponent(as);
         
         as = new ActivationSpec();
         as.setId("xfireBinding");
-        as.setComponent(new HttpSoapConnector(null, PORT, true));
+        as.setComponent(new HttpSoapConnector(null, PORT_2, true));
         as.setDestinationService(new QName("saaj"));
         container.activateComponent(as);
         
         as = new ActivationSpec();
         as.setId("webservice");
-        as.setComponent(new HttpConnector(null, PORT_WS));
+        as.setComponent(new HttpConnector(null, PORT_WS_2));
         as.setDestinationService(new QName("mock"));
         container.activateComponent(as);
         
@@ -107,9 +110,10 @@
         as.setService(new QName("mock"));
         container.activateComponent(as);
 
-        URLConnection connection = new URL("http://localhost:" + PORT).openConnection();
+        URLConnection connection = new URL("http://localhost:" + PORT_1).openConnection();
         connection.setDoOutput(true);
         connection.setDoInput(true);
+        ((HttpURLConnection) connection).setRequestProperty("Content-Type", "text/xml; charset=utf-8;");
         OutputStream os = connection.getOutputStream();
         // Post the request file.
         InputStream fis = getClass().getResourceAsStream("soap-request.xml");



Mime
View raw message