You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/02/16 22:20:06 UTC

svn commit: r508584 - in /incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http: ./ endpoints/

Author: gnodet
Date: Fri Feb 16 13:20:05 2007
New Revision: 508584

URL: http://svn.apache.org/viewvc?view=rev&rev=508584
Log:
SM-537, SM-724: split consumer / provider endpoints, and support pluggable marshalers

Added:
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpointType.java   (with props)
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java   (with props)
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java   (with props)
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java   (with props)
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerMarshaler.java   (with props)
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java   (with props)
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java   (with props)
Modified:
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java?view=diff&rev=508584&r1=508583&r2=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java Fri Feb 16 13:20:05 2007
@@ -32,6 +32,8 @@
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.ServiceUnit;
 import org.apache.servicemix.common.xbean.BaseXBeanDeployer;
+import org.apache.servicemix.http.endpoints.HttpConsumerEndpoint;
+import org.apache.servicemix.http.endpoints.HttpProviderEndpoint;
 import org.apache.servicemix.http.jetty.JCLLogger;
 import org.apache.servicemix.http.jetty.JettyContextManager;
 import org.apache.servicemix.jbi.security.auth.AuthenticationService;
@@ -58,7 +60,7 @@
     protected HttpClient client;
     protected MultiThreadedHttpConnectionManager connectionManager;
     protected HttpConfiguration configuration = new HttpConfiguration();
-    protected HttpEndpoint[] endpoints;
+    protected HttpEndpointType[] endpoints;
     
     protected String protocol;
     protected String host;
@@ -124,14 +126,14 @@
     /**
      * @return the endpoints
      */
-    public HttpEndpoint[] getEndpoints() {
+    public HttpEndpointType[] getEndpoints() {
         return endpoints;
     }
 
     /**
      * @param endpoints the endpoints to set
      */
-    public void setEndpoints(HttpEndpoint[] endpoints) {
+    public void setEndpoints(HttpEndpointType[] endpoints) {
         this.endpoints = endpoints;
     }
 
@@ -316,7 +318,7 @@
     }
 
     protected Class[] getEndpointClasses() {
-        return new Class[] { HttpEndpoint.class };
+        return new Class[] { HttpEndpoint.class, HttpConsumerEndpoint.class, HttpProviderEndpoint.class };
     }
-    
+
 }

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?view=diff&rev=508584&r1=508583&r2=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java Fri Feb 16 13:20:05 2007
@@ -50,7 +50,7 @@
  *                  description="An http endpoint"
  * 
  */
-public class HttpEndpoint extends SoapEndpoint {
+public class HttpEndpoint extends SoapEndpoint implements HttpEndpointType {
 
     protected ExtensibilityElement binding;
     protected String locationURI;

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpointType.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpointType.java?view=auto&rev=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpointType.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpointType.java Fri Feb 16 13:20:05 2007
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.http;
+
+/**
+ * Marker interface for HTTP endpoints
+ * 
+ * @author gnodet
+ */
+public interface HttpEndpointType {
+
+}

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpointType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpointType.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpointType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java?view=auto&rev=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java Fri Feb 16 13:20:05 2007
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.http.endpoints;
+
+import java.net.URI;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.servicemix.jbi.FaultException;
+import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
+
+public class DefaultHttpConsumerMarshaler implements HttpConsumerMarshaler {
+    
+    private URI defaultMep = MessageExchangeSupport.IN_OUT;
+
+    public URI getDefaultMep() {
+        return defaultMep;
+    }
+
+    public void setDefaultMep(URI defaultMep) {
+        this.defaultMep = defaultMep;
+    }
+
+    public MessageExchange createExchange(HttpServletRequest request, ComponentContext context) throws Exception {
+        MessageExchange me;
+        me = context.getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep());
+        NormalizedMessage in = me.createMessage();
+        me.setMessage(in, "in");
+        return me;
+    }
+
+    public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
+    
+    public void sendFault(MessageExchange exchange, Fault fault, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        throw new FaultException("Fault occured", exchange, fault);
+    }
+
+    public void sendError(MessageExchange exchange, Exception error, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        throw error;
+    }
+    
+    public void sendAccepted(MessageExchange exchange, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        response.setStatus(HttpServletResponse.SC_ACCEPTED);
+    }
+
+}

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java?view=auto&rev=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java Fri Feb 16 13:20:05 2007
@@ -0,0 +1,71 @@
+package org.apache.servicemix.http.endpoints;
+
+import java.io.IOException;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodRetryHandler;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.servicemix.expression.Expression;
+
+public class DefaultHttpProviderMarshaler implements HttpProviderMarshaler {
+
+    private String locationUri;
+    private Expression locationUriExpression;
+    private int retryCount = 0;
+    
+    public int getRetryCount() {
+        return retryCount;
+    }
+
+    public void setRetryCount(int retryCount) {
+        this.retryCount = retryCount;
+    }
+
+    public String getLocationUri() {
+        return locationUri;
+    }
+
+    public void setLocationUri(String locationUri) {
+        this.locationUri = locationUri;
+    }
+
+    public Expression getLocationUriExpression() {
+        return locationUriExpression;
+    }
+
+    public void setLocationUriExpression(Expression locationUriExpression) {
+        this.locationUriExpression = locationUriExpression;
+    }
+
+    public String getDestinationUri(MessageExchange exchange, NormalizedMessage inMsg) throws Exception {
+        String uri = null;
+        if (locationUriExpression != null) {
+            Object o = locationUriExpression.evaluate(exchange, inMsg);
+            uri = (o != null) ? o.toString() : null;
+        }
+        if (uri == null) {
+            uri = locationUri;
+        }
+        return uri;
+    }
+    
+    public HttpMethod createMethod(MessageExchange exchange, NormalizedMessage inMsg) throws Exception {
+        PostMethod method = new PostMethod();
+        setRetryHandler(method);
+        return method;
+    }
+    
+    protected void setRetryHandler(HttpMethod method) {
+        HttpMethodRetryHandler retryHandler = new HttpMethodRetryHandler() {
+            public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
+                return executionCount < retryCount;
+            }
+        };
+        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
+    }
+
+}

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java?view=auto&rev=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java Fri Feb 16 13:20:05 2007
@@ -0,0 +1,351 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.http.endpoints;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.ExchangeProcessor;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.endpoints.ConsumerEndpoint;
+import org.apache.servicemix.http.ContextManager;
+import org.apache.servicemix.http.HttpComponent;
+import org.apache.servicemix.http.HttpEndpointType;
+import org.apache.servicemix.http.HttpProcessor;
+import org.apache.servicemix.http.SslParameters;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.mortbay.jetty.RetryRequest;
+import org.mortbay.util.ajax.Continuation;
+import org.mortbay.util.ajax.ContinuationSupport;
+import org.w3c.dom.Node;
+
+/**
+ * 
+ * @author gnodet
+ * @org.apache.xbean.XBean element="consumer"
+ */
+public class HttpConsumerEndpoint extends ConsumerEndpoint implements ExchangeProcessor, HttpProcessor, HttpEndpointType {
+
+    public static final String MAIN_WSDL = "main.wsdl";
+    
+    private String authMethod;
+    private SslParameters ssl;
+    private String locationUri;
+    private HttpConsumerMarshaler marshaler = new DefaultHttpConsumerMarshaler();
+    private long timeout = 0; // 0 => default to the timeout configured on component
+
+    private Map<String, Object> resources = new HashMap<String, Object>();
+    private Map<String, Continuation> locks = new ConcurrentHashMap<String, Continuation>();
+    private Map<String, MessageExchange> exchanges = new ConcurrentHashMap<String, MessageExchange>();
+    private Object httpContext;
+    
+    public HttpConsumerEndpoint() {
+        super();
+    }
+
+    public HttpConsumerEndpoint(DefaultComponent component, ServiceEndpoint endpoint) {
+        super(component, endpoint);
+    }
+
+    public HttpConsumerEndpoint(ServiceUnit serviceUnit, QName service, String endpoint) {
+        super(serviceUnit, service, endpoint);
+    }
+
+    /**
+     * @return the locationUri
+     */
+    public String getLocationURI() {
+        return locationUri;
+    }
+
+    /**
+     * @param locationUri the locationUri to set
+     */
+    public void setLocationURI(String locationUri) {
+        this.locationUri = locationUri;
+    }
+
+    /**
+     * @return the timeout
+     */
+    public long getTimeout() {
+        return timeout;
+    }
+
+    /**
+     * @param timeout the timeout to set
+     */
+    public void setTimeout(long timeout) {
+        this.timeout = timeout;
+    }
+
+    /**
+     * @return the marshaler
+     */
+    public HttpConsumerMarshaler getMarshaler() {
+        return marshaler;
+    }
+
+    /**
+     * @param marshaler the marshaler to set
+     */
+    public void setMarshaler(HttpConsumerMarshaler marshaler) {
+        this.marshaler = marshaler;
+    }
+
+    /**
+     * @return the authMethod
+     */
+    public String getAuthMethod() {
+        return authMethod;
+    }
+
+    /**
+     * @param authMethod the authMethod to set
+     */
+    public void setAuthMethod(String authMethod) {
+        this.authMethod = authMethod;
+    }
+
+    /**
+     * @return the sslParameters
+     */
+    public SslParameters getSsl() {
+        return ssl;
+    }
+
+    /**
+     * @param ssl the sslParameters to set
+     */
+    public void setSsl(SslParameters ssl) {
+        this.ssl = ssl;
+    }
+
+    public void start() throws Exception {
+        super.start();
+        loadStaticResources();
+        httpContext = getServerManager().createContext(locationUri, this);
+    }
+
+    public void stop() throws Exception {
+        getServerManager().remove(httpContext);
+        httpContext = null;
+        super.stop();
+    }
+
+    public void process(MessageExchange exchange) throws Exception {
+        Continuation cont = locks.remove(exchange.getExchangeId());
+        if (cont == null) {
+            throw new Exception("HTTP request has timed out");
+        }
+        synchronized (cont) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Resuming continuation for exchange: " + exchange.getExchangeId());
+            }
+            exchanges.put(exchange.getExchangeId(), exchange);
+            cont.resume();
+        }
+    }
+
+    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Receiving HTTP request: " + request);
+        }
+        MessageExchange exchange = null;
+        try {
+            // Handle WSDLs, XSDs
+            if (handleStaticResource(request, response)) {
+                return;
+            }
+            // Not giving a specific mutex will synchronize on the contination itself
+            Continuation cont = ContinuationSupport.getContinuation(request, null);
+            // If the continuation is not a retry
+            if (!cont.isPending()) {
+                exchange = createExchange(request);
+                locks.put(exchange.getExchangeId(), cont);
+                request.setAttribute(MessageExchange.class.getName(), exchange.getExchangeId());
+                synchronized (cont) {
+                    send(exchange);
+                    if (exchanges.remove(exchange.getExchangeId()) == null) {
+                        if (logger.isDebugEnabled()) {
+                            logger.debug("Suspending continuation for exchange: " + exchange.getExchangeId());
+                        }
+                        long timeout = this.timeout;
+                        if (timeout == 0) {
+                            timeout = ((HttpComponent) getServiceUnit().getComponent()).getConfiguration().getConsumerProcessorSuspendTime();
+                        }
+                        boolean result = cont.suspend(timeout);
+                        if (!result) {
+                            locks.remove(exchange.getExchangeId());
+                            throw new Exception("Exchange timed out");
+                        }
+                    }
+                    request.removeAttribute(MessageExchange.class.getName());
+                }
+                return;
+            } else {
+                String id = (String) request.getAttribute(MessageExchange.class.getName());
+                locks.remove(id);
+                exchange = exchanges.remove(id);
+                request.removeAttribute(MessageExchange.class.getName());
+                boolean result = cont.suspend(0); 
+                // Check if this is a timeout
+                if (exchange == null) {
+                    throw new IllegalStateException("Exchange not found");
+                }
+                if (!result) {
+                    throw new Exception("Timeout");
+                }
+            }
+            if (exchange.getStatus() == ExchangeStatus.ERROR) {
+                Exception e = exchange.getError();
+                if (e == null) {
+                    e = new Exception("Unkown error (exchange aborted ?)");
+                }
+                throw e;
+            } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                try {
+                    Fault fault = exchange.getFault();
+                    if (fault != null) {
+                        sendFault(exchange, fault, request, response);
+                    } else {
+                        NormalizedMessage outMsg = exchange.getMessage("out");
+                        if (outMsg != null) {
+                            sendOut(exchange, outMsg, request, response);
+                        }
+                    }
+                    exchange.setStatus(ExchangeStatus.DONE);
+                    send(exchange);
+                } catch (Exception e) {
+                    exchange.setError(e);
+                    send(exchange);
+                }
+            } else if (exchange.getStatus() == ExchangeStatus.DONE) {
+                // This happens when there is no response to send back
+                sendAccepted(exchange, request, response);
+            }
+        } catch (RetryRequest e) {
+            throw e;
+        } catch (Exception e) {
+            sendError(exchange, e, request, response);
+        }
+    }
+
+    protected void loadStaticResources() {
+        // TODO: load wsdl
+    }
+    
+    /**
+     * Handle static resources
+     * 
+     * @param request the http request
+     * @param response the http response
+     * @return <code>true</code> if the request has been handled
+     * @throws IOException
+     * @throws ServletException
+     */
+    protected boolean handleStaticResource(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
+        if (!"GET".equals(request.getMethod())) {
+            return false;
+        }
+        String query = request.getQueryString();
+        if (query != null && query.trim().equalsIgnoreCase("wsdl") && getResource(MAIN_WSDL) != null) {
+            String uri = request.getRequestURI();
+            if (!uri.endsWith("/")) {
+                uri += "/";
+            }
+            uri += MAIN_WSDL;
+            response.sendRedirect(uri);
+            return true;
+        }
+        String path = request.getPathInfo();
+        if (path.lastIndexOf('/') >= 0) {
+            path = path.substring(path.lastIndexOf('/') + 1);
+        }
+        Object res = getResource(path);
+        if (res == null) {
+            return false;
+        }
+        if (res instanceof Node) {
+            response.setStatus(200);
+            response.setContentType("text/xml");
+            try {
+                new SourceTransformer().toResult(new DOMSource((Node) res), new StreamResult(response.getOutputStream()));
+            } catch (TransformerException e) {
+                throw new ServletException("Error while sending xml resource", e);
+            }
+        } else if (res != null) {
+            // TODO: handle other static resources ...
+            throw new ServletException("Unable to serialize resource");
+        } else {
+            return false;
+        }
+        return true;
+    }
+
+    protected Object getResource(String path) {
+        return resources.get(path);
+    }
+    
+    protected void addResource(String path, Object resource) {
+        resources.put(path, resource);
+    }
+
+    protected ContextManager getServerManager() {
+        HttpComponent comp =  (HttpComponent) getServiceUnit().getComponent();
+        return comp.getServer();
+    }
+
+    public MessageExchange createExchange(HttpServletRequest request) throws Exception {
+        MessageExchange me = marshaler.createExchange(request, getContext());
+        configureExchangeTarget(me);
+        return me;
+    }
+
+    public void sendAccepted(MessageExchange exchange, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        marshaler.sendAccepted(exchange, request, response);
+    }
+
+    public void sendError(MessageExchange exchange, Exception error, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        marshaler.sendError(exchange, error, request, response);
+    }
+
+    public void sendFault(MessageExchange exchange, Fault fault, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        marshaler.sendFault(exchange, fault, request, response);
+    }
+
+    public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        marshaler.sendOut(exchange, outMsg, request, response);
+    }
+    
+}

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerMarshaler.java?view=auto&rev=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerMarshaler.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerMarshaler.java Fri Feb 16 13:20:05 2007
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.http.endpoints;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public interface HttpConsumerMarshaler {
+
+    MessageExchange createExchange(HttpServletRequest request, 
+                                   ComponentContext context) throws Exception;
+
+    void sendOut(MessageExchange exchange, 
+                 NormalizedMessage outMsg, 
+                 HttpServletRequest request, 
+                 HttpServletResponse response) throws Exception;
+
+    void sendFault(MessageExchange exchange, 
+                   Fault fault, 
+                   HttpServletRequest request, 
+                   HttpServletResponse response) throws Exception;
+
+    void sendError(MessageExchange exchange, 
+                   Exception error, 
+                   HttpServletRequest request, 
+                   HttpServletResponse response) throws Exception;
+
+    void sendAccepted(MessageExchange exchange, 
+                      HttpServletRequest request, 
+                      HttpServletResponse response) throws Exception;
+
+}

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerMarshaler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerMarshaler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerMarshaler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java?view=auto&rev=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java Fri Feb 16 13:20:05 2007
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.http.endpoints;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOptionalOut;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpHost;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.apache.servicemix.JbiConstants;
+import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.ExchangeProcessor;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.endpoints.ProviderEndpoint;
+import org.apache.servicemix.http.BasicAuthCredentials;
+import org.apache.servicemix.http.HttpComponent;
+import org.apache.servicemix.http.HttpEndpointType;
+import org.apache.servicemix.http.SslParameters;
+import org.apache.servicemix.http.processors.CommonsHttpSSLSocketFactory;
+import org.apache.servicemix.http.processors.Constants;
+import org.apache.servicemix.soap.Context;
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.apache.servicemix.soap.marshalers.SoapReader;
+import org.apache.servicemix.soap.marshalers.SoapWriter;
+
+/**
+ * 
+ * @author gnodet
+ * @org.apache.xbean.XBean element="provider"
+ */
+public class HttpProviderEndpoint extends ProviderEndpoint implements ExchangeProcessor, HttpEndpointType {
+
+    private SslParameters ssl;
+    private BasicAuthCredentials basicAuthentication;
+    private Map<String, HttpMethod> methods = new ConcurrentHashMap<String, HttpMethod>();
+    private HttpProviderMarshaler marshaler = new DefaultHttpProviderMarshaler();
+    
+    public HttpProviderEndpoint() {
+        super();
+    }
+
+    public HttpProviderEndpoint(DefaultComponent component, ServiceEndpoint endpoint) {
+        super(component, endpoint);
+    }
+
+    public HttpProviderEndpoint(ServiceUnit serviceUnit, QName service, String endpoint) {
+        super(serviceUnit, service, endpoint);
+    }
+
+    public BasicAuthCredentials getBasicAuthentication() {
+        return basicAuthentication;
+    }
+
+    public void setBasicAuthentication(BasicAuthCredentials basicAuthentication) {
+        this.basicAuthentication = basicAuthentication;
+    }
+    
+    public SslParameters getSsl() {
+        return ssl;
+    }
+    
+    public void setSsl(SslParameters ssl) {
+        this.ssl = ssl;
+    }
+
+    public void process(MessageExchange exchange) throws Exception {
+        if (exchange.getStatus() == ExchangeStatus.DONE || 
+            exchange.getStatus() == ExchangeStatus.ERROR) {
+                HttpMethod method = methods.remove(exchange.getExchangeId());
+                if (method != null) {
+                    method.releaseConnection();
+                }
+                return;
+            }
+            boolean txSync = exchange.isTransacted() && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC));
+            NormalizedMessage nm = exchange.getMessage("in");
+            if (nm == null) {
+                throw new IllegalStateException("Exchange has no input message");
+            }
+            String locationUri = marshaler.getDestinationUri(exchange, nm);
+            HttpMethod method = marshaler.createMethod(exchange, nm);
+            method.setURI(new URI(getRelUri(locationUri), false));
+            boolean close = true;
+            try {
+                /*
+                // Uncomment to avoid the http request being sent several times.
+                // Can be useful when debugging
+                //================================
+                //method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
+                //    public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
+                //        return false;
+                //    }
+                //});
+                if (getBasicAuthentication() != null) {
+                    getBasicAuthentication().applyCredentials( getClient() );
+                }
+                int response = getClient().executeMethod(getHostConfiguration(locationUri), method);
+                if (response != HttpStatus.SC_OK && response != HttpStatus.SC_ACCEPTED) {
+                    if (exchange instanceof InOnly == false) {
+                        SoapReader reader = soapHelper.getSoapMarshaler().createReader();
+                        Header contentType = method.getResponseHeader(Constants.HEADER_CONTENT_TYPE);
+                        soapMessage = reader.read(method.getResponseBodyAsStream(), 
+                                                  contentType != null ? contentType.getValue() : null);
+                        context.setFaultMessage(soapMessage);
+                        soapHelper.onAnswer(context);
+                        Fault fault = exchange.createFault();
+                        fault.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
+                        soapHelper.getJBIMarshaler().toNMS(fault, soapMessage);
+                        exchange.setFault(fault);
+                        if (txSync) {
+                            channel.sendSync(exchange);
+                        } else {
+                            methods.put(exchange.getExchangeId(), method);
+                            channel.send(exchange);
+                            close = false;
+                        }
+                        return;
+                    } else {
+                        throw new Exception("Invalid status response: " + response);
+                    }
+                }
+                if (exchange instanceof InOut) {
+                    NormalizedMessage msg = exchange.createMessage();
+                    SoapReader reader = soapHelper.getSoapMarshaler().createReader();
+                    Header contentType = method.getResponseHeader(Constants.HEADER_CONTENT_TYPE);
+                    soapMessage = reader.read(method.getResponseBodyAsStream(), 
+                                              contentType != null ? contentType.getValue() : null);
+                    context.setOutMessage(soapMessage);
+                    soapHelper.onAnswer(context);
+                    msg.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
+                    soapHelper.getJBIMarshaler().toNMS(msg, soapMessage);
+                    ((InOut) exchange).setOutMessage(msg);
+                    if (txSync) {
+                        channel.sendSync(exchange);
+                    } else {
+                        methods.put(exchange.getExchangeId(), method);
+                        channel.send(exchange);
+                        close = false;
+                    }
+                } else if (exchange instanceof InOptionalOut) {
+                    if (method.getResponseContentLength() == 0) {
+                        exchange.setStatus(ExchangeStatus.DONE);
+                        channel.send(exchange);
+                    } else {
+                        NormalizedMessage msg = exchange.createMessage();
+                        SoapReader reader = soapHelper.getSoapMarshaler().createReader();
+                        soapMessage = reader.read(method.getResponseBodyAsStream(), 
+                                                  method.getResponseHeader(Constants.HEADER_CONTENT_TYPE).getValue());
+                        context.setOutMessage(soapMessage);
+                        soapHelper.onAnswer(context);
+                        msg.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
+                        soapHelper.getJBIMarshaler().toNMS(msg, soapMessage);
+                        ((InOptionalOut) exchange).setOutMessage(msg);
+                        if (txSync) {
+                            channel.sendSync(exchange);
+                        } else {
+                            methods.put(exchange.getExchangeId(), method);
+                            channel.send(exchange);
+                            close = false;
+                        }
+                    }
+                } else {
+                    exchange.setStatus(ExchangeStatus.DONE);
+                    channel.send(exchange);
+                }
+                */
+            } finally {
+                if (close) {
+                    method.releaseConnection();
+                }
+            }
+    }
+
+    private String getRelUri(String locationUri) {
+        java.net.URI uri = java.net.URI.create(locationUri);
+        String relUri = uri.getPath();
+        if (!relUri.startsWith("/")) {
+            relUri = "/" + relUri;
+        }
+        if (uri.getQuery() != null) {
+            relUri += "?" + uri.getQuery();
+        }
+        if (uri.getFragment() != null) {
+            relUri += "#" + uri.getFragment();
+        }
+        return relUri;
+    }
+
+    /*
+    protected HttpClient getClient() {
+        HttpComponent comp =  (HttpComponent) getServiceUnit().getComponent();
+        return comp.getClient();
+    }
+
+    private HostConfiguration getHostConfiguration(String locationURI) throws Exception {
+        HostConfiguration host;
+        URI uri = new URI(locationURI, false);
+        if (uri.getScheme().equals("https")) {
+            ProtocolSocketFactory sf = new CommonsHttpSSLSocketFactory(
+                            getSsl(),
+                            getKeystoreManager());
+            Protocol protocol = new Protocol("https", sf, 443);
+            HttpHost httphost = new HttpHost(uri.getHost(), uri.getPort(), protocol);
+            host = new HostConfiguration();
+            host.setHost(httphost);
+        } else {
+            host = new HostConfiguration();
+            host.setHost(uri.getHost(), uri.getPort());
+        }
+
+        return host;
+    }
+    */
+
+}

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java?view=auto&rev=508584
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java Fri Feb 16 13:20:05 2007
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.http.endpoints;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.commons.httpclient.HttpMethod;
+
+public interface HttpProviderMarshaler {
+
+    String getDestinationUri(MessageExchange exchange,
+                             NormalizedMessage inMsg) throws Exception;
+    
+    HttpMethod createMethod(MessageExchange exchange,
+                            NormalizedMessage inMsg) throws Exception;
+
+}

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain