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/08/08 13:11:11 UTC
svn commit: r563813 [1/2] - in /incubator/servicemix/trunk: ./
common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/interceptors/xml/
deployables/bindingcomponents/servicemix-http/
deployables/bindingcomponents/servicemix-http/src/main/java...
Author: gnodet
Date: Wed Aug 8 04:11:09 2007
New Revision: 563813
URL: http://svn.apache.org/viewvc?view=rev&rev=563813
Log:
SM-978: Provider side of new http endpoints
Added:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpoint.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/SmxHttpExchange.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/ProviderEndpointTest.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/person.wsdl
Modified:
incubator/servicemix/trunk/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/interceptors/xml/StaxInInterceptor.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/pom.xml
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
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasUserRealm.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/tools/PortTypeDecorator.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
incubator/servicemix/trunk/pom.xml
Modified: incubator/servicemix/trunk/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/interceptors/xml/StaxInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/interceptors/xml/StaxInInterceptor.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/interceptors/xml/StaxInInterceptor.java (original)
+++ incubator/servicemix/trunk/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/interceptors/xml/StaxInInterceptor.java Wed Aug 8 04:11:09 2007
@@ -36,6 +36,8 @@
*/
public class StaxInInterceptor extends AbstractInterceptor {
+ public static final String ENCODING = "Encoding";
+
public StaxInInterceptor() {
}
@@ -49,7 +51,7 @@
InputStream is = message.getContent(InputStream.class);
if (is != null) {
// TODO: where does encoding constant go?
- String encoding = (String) message.get("Encoding");
+ String encoding = (String) message.get(ENCODING);
reader = StaxUtil.createReader(is, encoding);
reader = new ExtendedXMLStreamReader(reader);
} else {
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/pom.xml?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/pom.xml (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/pom.xml Wed Aug 8 04:11:09 2007
@@ -83,6 +83,7 @@
</plugin>
</plugins>
</build>
+
<dependencies>
<dependency>
<groupId>org.apache.servicemix</groupId>
@@ -105,6 +106,7 @@
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
+ <version>${jetty-version}</version>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
@@ -115,6 +117,7 @@
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-management</artifactId>
+ <version>${jetty-version}</version>
<exclusions>
<exclusion>
<groupId>mx4j</groupId>
@@ -129,6 +132,11 @@
<artifactId>servlet-api-2.5</artifactId>
</exclusion>
</exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
+ <version>${jetty-version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
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=563813&r1=563812&r2=563813
==============================================================================
--- 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 Wed Aug 8 04:11:09 2007
@@ -58,6 +58,7 @@
protected ContextManager server;
protected HttpClient client;
protected MultiThreadedHttpConnectionManager connectionManager;
+ protected org.mortbay.jetty.client.HttpClient connectionPool;
protected HttpConfiguration configuration = new HttpConfiguration();
protected HttpEndpointType[] endpoints;
@@ -157,6 +158,14 @@
this.client = client;
}
+ public org.mortbay.jetty.client.HttpClient getConnectionPool() {
+ return connectionPool;
+ }
+
+ public void setConnectionPool(org.mortbay.jetty.client.HttpClient connectionPool) {
+ this.connectionPool = connectionPool;
+ }
+
/**
* @return Returns the configuration.
* @org.apache.xbean.Flat
@@ -212,6 +221,11 @@
connectionManager.setParams(params);
client = new HttpClient(connectionManager);
}
+ // Create connectionPool
+ if (connectionPool == null) {
+ connectionPool = new org.mortbay.jetty.client.HttpClient();
+ connectionPool.start();
+ }
// Create serverManager
if (configuration.isManaged()) {
server = new ManagedContextManager();
@@ -230,6 +244,10 @@
ContextManager s = server;
server = null;
s.shutDown();
+ }
+ if (connectionPool != null) {
+ connectionPool.stop();
+ connectionPool = null;
}
if (connectionManager != null) {
connectionManager.shutdown();
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=563813&r1=563812&r2=563813
==============================================================================
--- 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 Wed Aug 8 04:11:09 2007
@@ -58,6 +58,21 @@
protected String soapAction;
protected BasicAuthCredentials basicAuthentication;
protected ProxyParameters proxy;
+ protected boolean synchronous;
+
+ /**
+ * @return the synchronous
+ */
+ public boolean isSynchronous() {
+ return synchronous;
+ }
+
+ /**
+ * @param synchronous the synchronous to set
+ */
+ public void setSynchronous(boolean synchronous) {
+ this.synchronous = synchronous;
+ }
/**
* @return the soapAction
@@ -255,8 +270,14 @@
}
if (portType.getQName().getNamespaceURI().equals(service.getNamespaceURI())) {
if (isSoap()) {
- PortTypeDecorator.decorate(def, portType, location, endpoint + "Binding", service.getLocalPart(),
- endpoint);
+ PortTypeDecorator.decorate(
+ def,
+ portType,
+ location,
+ endpoint + "Binding",
+ service.getLocalPart(),
+ endpoint,
+ soapVersion);
definition = def;
} else {
Binding bnd = def.createBinding();
@@ -279,8 +300,14 @@
}
} else {
definition = PortTypeDecorator.createImportDef(def, service.getNamespaceURI(), "porttypedef.wsdl");
- PortTypeDecorator.decorate(definition, portType, location, endpoint + "Binding",
- service.getLocalPart(), endpoint);
+ PortTypeDecorator.decorate(
+ definition,
+ portType,
+ location,
+ endpoint + "Binding",
+ service.getLocalPart(),
+ endpoint,
+ soapVersion);
}
}
}
Modified: 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=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java Wed Aug 8 04:11:09 2007
@@ -16,6 +16,8 @@
*/
package org.apache.servicemix.http.endpoints;
+import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
@@ -62,10 +64,11 @@
}
public MessageExchange createExchange(HttpServletRequest request, ComponentContext context) throws Exception {
- MessageExchange me;
- me = context.getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep());
+ MessageExchange me = context.getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep());
NormalizedMessage in = me.createMessage();
- in.setContent(new StreamSource(request.getInputStream()));
+ InputStream is = request.getInputStream();
+ is = new BufferedInputStream(is);
+ in.setContent(new StreamSource(is));
me.setMessage(in, "in");
return me;
}
Modified: 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=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java Wed Aug 8 04:11:09 2007
@@ -16,72 +16,196 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.io.IOException;
-
+import java.io.ByteArrayOutputStream;
+import java.io.Reader;
+import java.util.Map;
+
+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.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
-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.commons.httpclient.HttpStatus;
import org.apache.servicemix.expression.Expression;
-
+import org.apache.servicemix.http.jetty.SmxHttpExchange;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StAXSourceTransformer;
+import org.mortbay.io.ByteArrayBuffer;
+import org.mortbay.jetty.HttpHeaders;
+import org.mortbay.jetty.HttpMethods;
+
+/**
+ * Default marshaler used for non-soap provider endpoints.
+ *
+ * @author gnodet
+ * @since 3.2
+ */
public class DefaultHttpProviderMarshaler implements HttpProviderMarshaler {
- private String locationUri;
- private Expression locationUriExpression;
- private int retryCount;
+ private SourceTransformer transformer = new StAXSourceTransformer();
+ private String locationURI;
+ private Expression locationURIExpression;
+ private String method;
+ private Expression methodExpression;
+ private String contentType = "text/xml";
+ private Expression contentTypeExpression;
+ private Map<String, String> headers;
+
+ 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 getMethod() {
+ return method;
+ }
+
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
+ public Expression getMethodExpression() {
+ return methodExpression;
+ }
+
+ public void setMethodExpression(Expression methodExpression) {
+ this.methodExpression = methodExpression;
+ }
- public int getRetryCount() {
- return retryCount;
+ public String getContentType() {
+ return contentType;
}
- public void setRetryCount(int retryCount) {
- this.retryCount = retryCount;
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
}
- public String getLocationUri() {
- return locationUri;
+ public Expression getContentTypeExpression() {
+ return contentTypeExpression;
}
- public void setLocationUri(String locationUri) {
- this.locationUri = locationUri;
+ public void setContentTypeExpression(Expression contentTypeExpression) {
+ this.contentTypeExpression = contentTypeExpression;
}
- public Expression getLocationUriExpression() {
- return locationUriExpression;
+ public Map<String, String> getHeaders() {
+ return headers;
}
- public void setLocationUriExpression(Expression locationUriExpression) {
- this.locationUriExpression = locationUriExpression;
+ public void setHeaders(Map<String, String> headers) {
+ this.headers = headers;
}
- public String getDestinationUri(MessageExchange exchange, NormalizedMessage inMsg) throws Exception {
+ protected String getLocationUri(MessageExchange exchange, NormalizedMessage inMsg) throws Exception {
String uri = null;
- if (locationUriExpression != null) {
- Object o = locationUriExpression.evaluate(exchange, inMsg);
+ if (locationURIExpression != null) {
+ Object o = locationURIExpression.evaluate(exchange, inMsg);
uri = (o != null) ? o.toString() : null;
}
if (uri == null) {
- uri = locationUri;
+ uri = locationURI;
+ }
+ if (uri == null) {
+ throw new IllegalStateException("Unable to find URI for exchange");
}
return uri;
}
- public HttpMethod createMethod(MessageExchange exchange, NormalizedMessage inMsg) throws Exception {
- PostMethod method = new PostMethod();
- setRetryHandler(method);
- return method;
+ protected String getMethod(MessageExchange exchange, NormalizedMessage inMsg) throws Exception {
+ String mth = null;
+ if (methodExpression != null) {
+ Object o = methodExpression.evaluate(exchange, inMsg);
+ mth = (o != null) ? o.toString() : null;
+ }
+ if (mth == null) {
+ mth = method;
+ }
+ if (mth == null) {
+ if (inMsg.getContent() == null) {
+ mth = HttpMethods.GET;
+ } else {
+ mth = HttpMethods.POST;
+ }
+ }
+ return mth;
}
- protected void setRetryHandler(HttpMethod method) {
- HttpMethodRetryHandler retryHandler = new HttpMethodRetryHandler() {
- public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
- return executionCount < retryCount;
+ protected String getContentType(MessageExchange exchange, NormalizedMessage inMsg) throws Exception {
+ String content = null;
+ if (contentTypeExpression != null) {
+ Object o = contentTypeExpression.evaluate(exchange, inMsg);
+ content = (o != null) ? o.toString() : null;
+ }
+ if (content == null) {
+ content = contentType;
+ }
+ if (content == null) {
+ throw new IllegalStateException("ContentType must not be null");
+ }
+ return content;
+ }
+
+ public void createRequest(final MessageExchange exchange,
+ final NormalizedMessage inMsg,
+ final SmxHttpExchange httpExchange) throws Exception {
+ httpExchange.setURL(getLocationUri(exchange, inMsg));
+ httpExchange.setMethod(getMethod(exchange, inMsg));
+ httpExchange.setRequestHeader(HttpHeaders.CONTENT_TYPE, getContentType(exchange, inMsg));
+ if (getHeaders() != null) {
+ for (Map.Entry<String, String> e : getHeaders().entrySet()) {
+ httpExchange.setRequestHeader(e.getKey(), e.getValue());
}
- };
- method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
+ }
+ if (inMsg.getContent() != null) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ transformer.toResult(inMsg.getContent(), new StreamResult(baos));
+ httpExchange.setRequestContent(new ByteArrayBuffer(baos.toByteArray()));
+ }
}
+ public void handleResponse(MessageExchange exchange, SmxHttpExchange httpExchange) throws Exception {
+ int response = httpExchange.getResponseStatus();
+ if (response != HttpStatus.SC_OK && response != HttpStatus.SC_ACCEPTED) {
+ if (!(exchange instanceof InOnly)) {
+ Fault fault = exchange.createFault();
+ fault.setContent(new StreamSource(httpExchange.getResponseReader()));
+ exchange.setFault(fault);
+ } else {
+ throw new Exception("Invalid status response: " + response);
+ }
+ } else if (exchange instanceof InOut) {
+ NormalizedMessage msg = exchange.createMessage();
+ msg.setContent(new StreamSource(httpExchange.getResponseReader()));
+ exchange.setMessage(msg, "out");
+ } else if (exchange instanceof InOptionalOut) {
+ Reader r = httpExchange.getResponseReader();
+ if (r != null) {
+ NormalizedMessage msg = exchange.createMessage();
+ msg.setContent(new StreamSource(r));
+ exchange.setMessage(msg, "out");
+ } else {
+ exchange.setStatus(ExchangeStatus.DONE);
+ }
+ } else {
+ exchange.setStatus(ExchangeStatus.DONE);
+
+ }
+ }
+
}
Modified: 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=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java Wed Aug 8 04:11:09 2007
@@ -216,7 +216,7 @@
if (handleStaticResource(request, response)) {
return;
}
- // Not giving a specific mutex will synchronize on the contination itself
+ // Not giving a specific mutex will synchronize on the continuation itself
Continuation cont = ContinuationSupport.getContinuation(request, null);
// If the continuation is not a retry
if (!cont.isPending()) {
Modified: 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=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java Wed Aug 8 04:11:09 2007
@@ -16,8 +16,7 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import java.io.IOException;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
@@ -25,27 +24,26 @@
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.xml.namespace.QName;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.URI;
+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.jetty.SmxHttpExchange;
/**
*
* @author gnodet
+ * @since 3.2
* @org.apache.xbean.XBean element="provider"
*/
-public class HttpProviderEndpoint extends ProviderEndpoint implements ExchangeProcessor, HttpEndpointType {
+public class HttpProviderEndpoint extends ProviderEndpoint implements HttpEndpointType {
- private SslParameters ssl;
- private BasicAuthCredentials basicAuthentication;
- private Map<String, HttpMethod> methods = new ConcurrentHashMap<String, HttpMethod>();
- private HttpProviderMarshaler marshaler = new DefaultHttpProviderMarshaler();
+ //private SslParameters ssl;
+ //private BasicAuthCredentials basicAuthentication;
+ private HttpProviderMarshaler marshaler;
+ private String locationURI;
public HttpProviderEndpoint() {
super();
@@ -59,6 +57,24 @@
super(serviceUnit, service, endpoint);
}
+ public String getLocationURI() {
+ return locationURI;
+ }
+
+ public void setLocationURI(String locationURI) {
+ this.locationURI = locationURI;
+ }
+
+ public void start() throws Exception {
+ if (marshaler == null) {
+ DefaultHttpProviderMarshaler m = new DefaultHttpProviderMarshaler();
+ m.setLocationURI(locationURI);
+ marshaler = m;
+ }
+ super.start();
+ }
+
+ /*
public BasicAuthCredentials getBasicAuthentication() {
return basicAuthentication;
}
@@ -74,153 +90,63 @@
public void setSsl(SslParameters ssl) {
this.ssl = ssl;
}
+ */
+
+ /**
+ * @return the marshaler
+ */
+ public HttpProviderMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ /**
+ * @param marshaler the marshaler to set
+ */
+ public void setMarshaler(HttpProviderMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
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(AbstractProcessor.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(AbstractProcessor.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(AbstractProcessor.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();
+ if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ NormalizedMessage nm = exchange.getMessage("in");
+ if (nm == null) {
+ throw new IllegalStateException("Exchange has no input message");
}
+ SmxHttpExchange httpEx = new Exchange(exchange);
+ marshaler.createRequest(exchange, nm, httpEx);
+ getConnectionPool().send(httpEx);
}
}
- 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();
+ protected void handle(SmxHttpExchange httpExchange, MessageExchange exchange) throws IOException {
+ try {
+ marshaler.handleResponse(exchange, httpExchange);
+ boolean txSync = exchange.getStatus() == ExchangeStatus.ACTIVE
+ && exchange.isTransacted()
+ && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC));
+ if (txSync) {
+ sendSync(exchange);
+ } else {
+ send(exchange);
+ }
+ } catch (Exception e) {
+ throw (IOException) new IOException(e.getMessage()).initCause(e);
}
- return relUri;
}
- /*
- protected HttpClient getClient() {
+ protected org.mortbay.jetty.client.HttpClient getConnectionPool() {
HttpComponent comp = (HttpComponent) getServiceUnit().getComponent();
- return comp.getClient();
+ return comp.getConnectionPool();
}
-
- 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());
+
+ protected class Exchange extends SmxHttpExchange {
+ MessageExchange jbiExchange;
+ public Exchange(MessageExchange jbiExchange) {
+ this.jbiExchange = jbiExchange;
+ }
+ protected void onResponseComplete() throws IOException {
+ handle(this, jbiExchange);
}
-
- return host;
}
- */
}
Modified: 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=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderMarshaler.java Wed Aug 8 04:11:09 2007
@@ -19,12 +19,19 @@
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
-import org.apache.commons.httpclient.HttpMethod;
+import org.apache.servicemix.http.jetty.SmxHttpExchange;
+/**
+ *
+ * @author gnodet
+ * @since 3.2
+ */
public interface HttpProviderMarshaler {
- String getDestinationUri(MessageExchange exchange, NormalizedMessage inMsg) throws Exception;
-
- HttpMethod createMethod(MessageExchange exchange, NormalizedMessage inMsg) throws Exception;
+ void createRequest(MessageExchange exchange,
+ NormalizedMessage inMsg,
+ SmxHttpExchange httpExchange) throws Exception;
+ void handleResponse(MessageExchange exchange,
+ SmxHttpExchange httpExchange) throws Exception;
}
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java Wed Aug 8 04:11:09 2007
@@ -81,7 +81,7 @@
msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
msg.put(Message.CONTENT_TYPE, request.getContentType());
Map<String, String> headers = msg.getTransportHeaders();
- for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) {
+ for (Enumeration<?> e = request.getHeaderNames(); e.hasMoreElements();) {
String name = (String) e.nextElement();
String value = request.getHeader(name);
headers.put(name, value);
Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpoint.java?view=auto&rev=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpoint.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderEndpoint.java Wed Aug 8 04:11:09 2007
@@ -0,0 +1,213 @@
+/*
+ * 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 javax.jbi.management.DeploymentException;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap12.SOAP12Address;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.soap.api.Policy;
+import org.apache.servicemix.soap.util.DomUtil;
+import org.apache.servicemix.soap.wsdl.BindingFactory;
+import org.apache.servicemix.soap.wsdl.WSDLUtils;
+import org.apache.servicemix.soap.wsdl.validator.WSIBPValidator;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.types.NCName;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.Endpoint;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.springframework.core.io.Resource;
+
+/**
+ *
+ * @author gnodet
+ * @since 3.2
+ * @org.apache.xbean.XBean element="soap-provider"
+ */
+public class HttpSoapProviderEndpoint extends HttpProviderEndpoint {
+
+ private Resource wsdl;
+ private boolean useJbiWrapper = true;
+ private boolean validateWsdl = true;
+ private Policy[] policies;
+
+ public HttpSoapProviderEndpoint() {
+ super();
+ }
+
+ public HttpSoapProviderEndpoint(DefaultComponent component, ServiceEndpoint endpoint) {
+ super(component, endpoint);
+ }
+
+ public HttpSoapProviderEndpoint(ServiceUnit serviceUnit, QName service, String endpoint) {
+ super(serviceUnit, service, endpoint);
+ }
+
+ public Resource getWsdl() {
+ return wsdl;
+ }
+
+ public void setWsdl(Resource wsdl) {
+ this.wsdl = wsdl;
+ }
+
+ public boolean isValidateWsdl() {
+ return validateWsdl;
+ }
+
+ public void setValidateWsdl(boolean validateWsdl) {
+ this.validateWsdl = validateWsdl;
+ }
+
+ public boolean isUseJbiWrapper() {
+ return useJbiWrapper;
+ }
+
+ public void setUseJbiWrapper(boolean useJbiWrapper) {
+ this.useJbiWrapper = useJbiWrapper;
+ }
+
+ public Policy[] getPolicies() {
+ return policies;
+ }
+
+ public void setPolicies(Policy[] policies) {
+ this.policies = policies;
+ }
+
+
+ @Override
+ public void validate() throws DeploymentException {
+ if (wsdl == null) {
+ throw new DeploymentException("wsdl property must be set");
+ }
+ HttpSoapProviderMarshaler marshaler = new HttpSoapProviderMarshaler();
+ try {
+ description = DomUtil.parse(wsdl.getInputStream());
+ Element elem = description.getDocumentElement();
+ if (WSDLUtils.WSDL1_NAMESPACE.equals(elem.getNamespaceURI())) {
+ validateWsdl1(marshaler);
+ } else if (WSDLUtils.WSDL2_NAMESPACE.equals(elem.getNamespaceURI())) {
+ validateWsdl2(marshaler);
+ } else {
+ throw new DeploymentException("Unrecognized wsdl namespace: " + elem.getNamespaceURI());
+ }
+ marshaler.setUseJbiWrapper(useJbiWrapper);
+ marshaler.setPolicies(policies);
+ setMarshaler(marshaler);
+ } catch (DeploymentException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeploymentException("Unable to read WSDL from: " + wsdl, e);
+ }
+ super.validate();
+ }
+
+ protected void validateWsdl1(HttpSoapProviderMarshaler marshaler) throws WSDLException, IOException, DeploymentException {
+ Definition def = WSDLUtils.createWSDL11Reader().readWSDL(wsdl.getURL().toString());
+ if (validateWsdl) {
+ WSIBPValidator validator = new WSIBPValidator(def);
+ if (!validator.isValid()) {
+ throw new DeploymentException("WSDL is not WS-I BP compliant: " + validator.getErrors());
+ }
+ }
+ Service svc;
+ if (getService() != null) {
+ svc = def.getService(getService());
+ if (svc == null) {
+ throw new DeploymentException("Could not find service '" + getService() + "' in wsdl");
+ }
+ } else if (def.getServices().size() == 1) {
+ svc = (Service) def.getServices().values().iterator().next();
+ setService(svc.getQName());
+ } else {
+ throw new DeploymentException("If service is not set, the WSDL must contain a single service definition");
+ }
+ Port port;
+ if (getEndpoint() != null) {
+ port = svc.getPort(getEndpoint());
+ if (port == null) {
+ throw new DeploymentException("Cound not find port '" + getEndpoint() + "' "
+ + "in wsdl for service '" + getService() + "'");
+ }
+ } else if (svc.getPorts().size() == 1) {
+ port = (Port) svc.getPorts().values().iterator().next();
+ setEndpoint(port.getName());
+ } else {
+ throw new DeploymentException("If endpoint is not set, the WSDL service '" + getService() + "' "
+ + "must contain a single port definition");
+ }
+ SOAPAddress sa11 = WSDLUtils.getExtension(port, SOAPAddress.class);
+ SOAP12Address sa12 = WSDLUtils.getExtension(port, SOAP12Address.class);
+ if (sa11 != null) {
+ marshaler.setBaseUrl(sa11.getLocationURI());
+ } else if (sa12 != null) {
+ marshaler.setBaseUrl(sa12.getLocationURI());
+ } else {
+ throw new DeploymentException("No SOAP address defined on port '" + port.getName() + "'");
+ }
+ description = WSDLUtils.getWSDL11Factory().newWSDLWriter().getDocument(def);
+ marshaler.setBinding(BindingFactory.createBinding(port));
+ }
+
+ protected void validateWsdl2(HttpSoapProviderMarshaler marshaler) throws
+ org.apache.woden.WSDLException, IOException, DeploymentException {
+ WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+ DescriptionElement descElement = reader.readWSDL(wsdl.getURL().toString());
+ Description desc = descElement.toComponent();
+ org.apache.woden.wsdl20.Service svc;
+ if (getService() != null) {
+ svc = desc.getService(getService());
+ if (svc == null) {
+ throw new DeploymentException("Could not find service '" + getService() + "' in wsdl");
+ }
+ } else if (desc.getServices().length == 1) {
+ svc = desc.getServices()[0];
+ setService(svc.getName());
+ } else {
+ throw new DeploymentException("If service is not set, the WSDL must contain a single service definition");
+ }
+ Endpoint endpoint;
+ if (getEndpoint() != null) {
+ endpoint = svc.getEndpoint(new NCName(getEndpoint()));
+ if (endpoint == null) {
+ throw new DeploymentException("Cound not find endpoint '" + getEndpoint() + "' in wsdl for service '" + getService() + "'");
+ }
+ } else if (svc.getEndpoints().length == 1) {
+ endpoint = svc.getEndpoints()[0];
+ setEndpoint(endpoint.getName().toString());
+ } else {
+ throw new DeploymentException("If endpoint is not set, the WSDL service '" + getService() + "' "
+ + "must contain a single port definition");
+ }
+ marshaler.setBinding(BindingFactory.createBinding(endpoint));
+ }
+
+}
Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java?view=auto&rev=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java Wed Aug 8 04:11:09 2007
@@ -0,0 +1,132 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.http.jetty.SmxHttpExchange;
+import org.apache.servicemix.soap.api.InterceptorChain;
+import org.apache.servicemix.soap.api.InterceptorProvider.Phase;
+import org.apache.servicemix.soap.api.Message;
+import org.apache.servicemix.soap.api.Policy;
+import org.apache.servicemix.soap.api.model.Binding;
+import org.apache.servicemix.soap.interceptors.jbi.JbiConstants;
+import org.apache.servicemix.soap.interceptors.xml.StaxInInterceptor;
+import org.mortbay.io.ByteArrayBuffer;
+import org.mortbay.jetty.HttpMethods;
+
+/**
+ *
+ * @author gnodet
+ * @since 3.2
+ */
+public class HttpSoapProviderMarshaler implements HttpProviderMarshaler {
+
+ private Binding<?> binding;
+ private boolean useJbiWrapper = true;
+ private Policy[] policies;
+ private String baseUrl;
+
+ public Binding<?> getBinding() {
+ return binding;
+ }
+
+ public void setBinding(Binding<?> binding) {
+ this.binding = binding;
+ }
+
+ public String getBaseUrl() {
+ return baseUrl;
+ }
+
+ public void setBaseUrl(String baseUrl) {
+ this.baseUrl = baseUrl;
+ }
+
+ public boolean isUseJbiWrapper() {
+ return useJbiWrapper;
+ }
+
+ public void setUseJbiWrapper(boolean useJbiWrapper) {
+ this.useJbiWrapper = useJbiWrapper;
+ }
+
+ public Policy[] getPolicies() {
+ return policies;
+ }
+
+ public void setPolicies(Policy[] policies) {
+ this.policies = policies;
+ }
+
+ public void createRequest(final MessageExchange exchange,
+ final NormalizedMessage inMsg,
+ final SmxHttpExchange httpExchange) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Message msg = binding.createMessage();
+ msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
+ msg.setContent(MessageExchange.class, exchange);
+ msg.setContent(NormalizedMessage.class, inMsg);
+ msg.setContent(OutputStream.class, baos);
+ exchange.setProperty(Message.class.getName(), msg);
+
+ InterceptorChain phaseOut = getChain(Phase.ClientOut);
+ phaseOut.doIntercept(msg);
+ httpExchange.setMethod(HttpMethods.POST);
+ httpExchange.setURL(baseUrl);
+ httpExchange.setRequestContent(new ByteArrayBuffer(baos.toByteArray()));
+ /*
+ httpExchange.setRequestEntity(new Entity() {
+ public void write(OutputStream os, Writer w) throws IOException {
+ // TODO: handle http headers: Content-Type, ...
+ }
+ });
+ */
+ // TODO: add transport headers
+ // TODO: use streaming when appropriate (?)
+ }
+
+ public void handleResponse(MessageExchange exchange, SmxHttpExchange httpExchange) throws Exception {
+ Message req = (Message) exchange.getProperty(Message.class.getName());
+ exchange.setProperty(Message.class.getName(), null);
+ Message msg = binding.createMessage(req);
+ msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
+ msg.setContent(MessageExchange.class, exchange);
+ msg.setContent(InputStream.class, new ByteArrayInputStream(httpExchange.getResponseData()));
+ msg.put(StaxInInterceptor.ENCODING, httpExchange.getResponseEncoding());
+ InterceptorChain phaseOut = getChain(Phase.ClientIn);
+ phaseOut.doIntercept(msg);
+ // TODO: Retrieve headers ?
+ }
+
+ protected InterceptorChain getChain(Phase phase) {
+ InterceptorChain chain = binding.getInterceptorChain(phase);
+ if (policies != null) {
+ for (int i = 0; i < policies.length; i++) {
+ chain.add(policies[i].getInterceptors(phase));
+ }
+ }
+ return chain;
+ }
+
+}
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java Wed Aug 8 04:11:09 2007
@@ -48,8 +48,8 @@
try {
System.setProperty("org.mortbay.log.class", JCLLogger.class.getName());
// For the class to be loaded by invoking a public static method
- Class cl = Thread.currentThread().getContextClassLoader().loadClass("org.mortbay.log.Log");
- cl.getMethod("isDebugEnabled", new Class[0]).invoke(null, null);
+ Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass("org.mortbay.log.Log");
+ cl.getMethod("isDebugEnabled", new Class[0]).invoke(null);
} catch (Exception e) {
e.printStackTrace();
} finally {
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasUserRealm.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasUserRealm.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasUserRealm.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasUserRealm.java Wed Aug 8 04:11:09 2007
@@ -19,11 +19,10 @@
import java.security.GeneralSecurityException;
import java.security.Principal;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.security.auth.Subject;
-import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.security.auth.AuthenticationService;
@@ -43,7 +42,7 @@
private String name = getClass().getName();
private String domain = "servicemix-domain";
private AuthenticationService authenticationService = new JAASAuthenticationService();
- private final Map userMap = new ConcurrentHashMap();
+ private final Map<String, JaasJettyPrincipal> userMap = new ConcurrentHashMap<String, JaasJettyPrincipal>();
/**
* @return the authenticationService
@@ -94,7 +93,7 @@
try {
if ((username != null) && (!username.equals(""))) {
- JaasJettyPrincipal userPrincipal = (JaasJettyPrincipal) userMap.get(username);
+ JaasJettyPrincipal userPrincipal = userMap.get(username);
// user has been previously authenticated, but
// re-authentication has been requested, so remove them
@@ -127,7 +126,7 @@
}
public Principal getPrincipal(String username) {
- return (Principal) userMap.get(username);
+ return userMap.get(username);
}
public boolean isUserInRole(Principal user, String role) {
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java Wed Aug 8 04:11:09 2007
@@ -72,7 +72,7 @@
private Map<String, Server> servers;
private HttpConfiguration configuration;
private BoundedThreadPool threadPool;
- private Map sslParams;
+ private Map<String, SslParameters> sslParams;
private MBeanServer mBeanServer;
private MBeanContainer mbeanContainer;
@@ -99,7 +99,7 @@
mbeanContainer = new MBeanContainer(mBeanServer);
}
servers = new HashMap<String, Server>();
- sslParams = new HashMap();
+ sslParams = new HashMap<String, SslParameters>();
BoundedThreadPool btp = new BoundedThreadPool();
btp.setMaxThreads(this.configuration.getJettyThreadPoolSize());
threadPool = btp;
@@ -111,19 +111,19 @@
public void start() throws Exception {
threadPool.start();
- for (Iterator it = servers.values().iterator(); it.hasNext();) {
- Server server = (Server) it.next();
+ for (Iterator<Server> it = servers.values().iterator(); it.hasNext();) {
+ Server server = it.next();
server.start();
}
}
public void stop() throws Exception {
- for (Iterator it = servers.values().iterator(); it.hasNext();) {
- Server server = (Server) it.next();
+ for (Iterator<Server> it = servers.values().iterator(); it.hasNext();) {
+ Server server = it.next();
server.stop();
}
- for (Iterator it = servers.values().iterator(); it.hasNext();) {
- Server server = (Server) it.next();
+ for (Iterator<Server> it = servers.values().iterator(); it.hasNext();) {
+ Server server = it.next();
server.join();
Connector[] connectors = server.getConnectors();
for (int i = 0; i < connectors.length; i++) {
@@ -142,7 +142,7 @@
server = createServer(url, processor.getSsl());
} else {
// Check ssl params
- SslParameters ssl = (SslParameters) sslParams.get(getKey(url));
+ SslParameters ssl = sslParams.get(getKey(url));
if (ssl != null && !ssl.equals(processor.getSsl())) {
throw new Exception("An https server is already created on port " + url.getPort()
+ " but SSL parameters do not match");
@@ -214,8 +214,8 @@
public synchronized void remove(Object context) throws Exception {
((ContextHandler) context).stop();
- for (Iterator it = servers.values().iterator(); it.hasNext();) {
- Server server = (Server) it.next();
+ for (Iterator<Server> it = servers.values().iterator(); it.hasNext();) {
+ Server server = it.next();
HandlerCollection handlerCollection = (HandlerCollection) server.getHandler();
ContextHandlerCollection contexts = (ContextHandlerCollection) handlerCollection.getHandlers()[0];
Handler[] handlers = contexts.getHandlers();
@@ -226,7 +226,7 @@
}
protected Server getServer(URL url) {
- return (Server) servers.get(getKey(url));
+ return servers.get(getKey(url));
}
protected String getKey(URL url) {
@@ -414,7 +414,7 @@
writer.write("Known services are: <ul>");
for (String serverUri : servers.keySet()) {
- Server server = (Server) JettyContextManager.this.servers.get(serverUri);
+ Server server = JettyContextManager.this.servers.get(serverUri);
Handler[] handlers = server.getChildHandlersByClass(ContextHandler.class);
for (int i = 0; handlers != null && i < handlers.length; i++) {
if (!(handlers[i] instanceof ContextHandler)) {
Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/SmxHttpExchange.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/SmxHttpExchange.java?view=auto&rev=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/SmxHttpExchange.java (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/SmxHttpExchange.java Wed Aug 8 04:11:09 2007
@@ -0,0 +1,132 @@
+/*
+ * 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.jetty;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+import org.mortbay.io.Buffer;
+import org.mortbay.io.BufferUtil;
+import org.mortbay.jetty.HttpFields;
+import org.mortbay.jetty.HttpHeaders;
+import org.mortbay.jetty.client.HttpExchange;
+import org.mortbay.util.StringUtil;
+
+public class SmxHttpExchange extends HttpExchange {
+
+ int responseStatus;
+ HttpFields responseFields;
+ String encoding = "utf-8";
+ ByteArrayOutputStream responseContent;
+ int contentLength;
+
+ public SmxHttpExchange() {
+ responseFields = new HttpFields();
+ }
+
+ /* ------------------------------------------------------------ */
+ public int getResponseStatus() {
+ if (getStatus() < STATUS_PARSING_HEADERS) {
+ throw new IllegalStateException("Response not received");
+ }
+ return responseStatus;
+ }
+
+ /* ------------------------------------------------------------ */
+ public HttpFields getResponseFields() {
+ if (getStatus() < STATUS_PARSING_CONTENT) {
+ throw new IllegalStateException("Headers not complete");
+ }
+ return responseFields;
+ }
+
+ /* ------------------------------------------------------------ */
+ public String getResponseContent() throws UnsupportedEncodingException {
+ if (responseContent != null) {
+ return responseContent.toString(encoding);
+ }
+ return null;
+ }
+
+ /* ------------------------------------------------------------ */
+ public Reader getResponseReader() throws UnsupportedEncodingException {
+ if (responseContent != null) {
+ return new InputStreamReader(new ByteArrayInputStream(responseContent.toByteArray()), encoding);
+ }
+ return null;
+ }
+
+ /* ------------------------------------------------------------ */
+ public byte[] getResponseData() throws UnsupportedEncodingException {
+ if (responseContent != null) {
+ return responseContent.toByteArray();
+ }
+ return null;
+ }
+
+ /* ------------------------------------------------------------ */
+ public String getResponseEncoding() throws UnsupportedEncodingException {
+ return encoding;
+ }
+
+ /* ------------------------------------------------------------ */
+ protected void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException {
+ responseStatus = status;
+ }
+
+ /* ------------------------------------------------------------ */
+ protected void onResponsetHeader(Buffer name, Buffer value) throws IOException {
+ if (responseFields != null) {
+ responseFields.add(name, value);
+ }
+ int header = HttpHeaders.CACHE.getOrdinal(value);
+ switch (header) {
+ case HttpHeaders.CONTENT_LANGUAGE_ORDINAL:
+ contentLength = BufferUtil.toInt(value);
+ break;
+ case HttpHeaders.CONTENT_TYPE_ORDINAL:
+ String mime = StringUtil.asciiToLowerCase(value.toString());
+ int i = mime.indexOf("charset=");
+ if (i > 0) {
+ mime = mime.substring(i + 8);
+ i = mime.indexOf(';');
+ if (i > 0) {
+ mime = mime.substring(0, i);
+ }
+ }
+ if (mime != null && mime.length() > 0) {
+ encoding = mime;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ /* ------------------------------------------------------------ */
+ protected void onResponseContent(Buffer content) throws IOException {
+ if (responseContent == null) {
+ responseContent = new ByteArrayOutputStream(contentLength);
+ }
+ content.writeTo(responseContent);
+ }
+
+}
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java Wed Aug 8 04:11:09 2007
@@ -20,6 +20,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.DeliveryChannel;
@@ -34,7 +35,7 @@
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Node;
-import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.JbiConstants;
@@ -69,15 +70,15 @@
protected ComponentContext context;
protected DeliveryChannel channel;
protected SoapHelper soapHelper;
- protected Map locks;
- protected Map exchanges;
+ protected Map<String, Continuation> locks;
+ protected Map<String, MessageExchange> exchanges;
protected int suspentionTime = 60000;
public ConsumerProcessor(HttpEndpoint endpoint) {
super(endpoint);
this.soapHelper = new SoapHelper(endpoint);
- this.locks = new ConcurrentHashMap();
- this.exchanges = new ConcurrentHashMap();
+ this.locks = new ConcurrentHashMap<String, Continuation>();
+ this.exchanges = new ConcurrentHashMap<String, MessageExchange>();
this.suspentionTime = getConfiguration().getConsumerProcessorSuspendTime();
}
@@ -90,7 +91,7 @@
}
public void process(MessageExchange exchange) throws Exception {
- Continuation cont = (Continuation) locks.remove(exchange.getExchangeId());
+ Continuation cont = locks.remove(exchange.getExchangeId());
if (cont != null) {
synchronized (cont) {
if (log.isDebugEnabled()) {
@@ -179,7 +180,7 @@
}
} else {
String id = (String) request.getAttribute(MessageExchange.class.getName());
- exchange = (MessageExchange) exchanges.remove(id);
+ exchange = exchanges.remove(id);
request.removeAttribute(MessageExchange.class.getName());
boolean result = cont.suspend(0);
// Check if this is a timeout
@@ -278,9 +279,9 @@
writer.write(response.getOutputStream());
}
- protected Map getHeaders(HttpServletRequest request) {
- Map headers = new HashMap();
- Enumeration enumeration = request.getHeaderNames();
+ protected Map<String, String> getHeaders(HttpServletRequest request) {
+ Map<String, String> headers = new HashMap<String, String>();
+ Enumeration<?> enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
String value = request.getHeader(name);
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java Wed Aug 8 04:11:09 2007
@@ -21,8 +21,8 @@
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
@@ -34,7 +34,6 @@
import javax.jbi.messaging.NormalizedMessage;
import javax.servlet.http.HttpServletRequest;
-import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
@@ -73,13 +72,13 @@
protected SoapHelper soapHelper;
protected DeliveryChannel channel;
- private Map methods;
+ private Map<String, PostMethod> methods;
private Protocol protocol;
public ProviderProcessor(HttpEndpoint endpoint) {
super(endpoint);
this.soapHelper = new SoapHelper(endpoint);
- this.methods = new ConcurrentHashMap();
+ this.methods = new ConcurrentHashMap<String, PostMethod>();
}
private String getRelUri(String locationUri) {
@@ -99,13 +98,14 @@
public void process(MessageExchange exchange) throws Exception {
if (exchange.getStatus() == ExchangeStatus.DONE || exchange.getStatus() == ExchangeStatus.ERROR) {
- PostMethod method = (PostMethod) methods.remove(exchange.getExchangeId());
+ PostMethod method = methods.remove(exchange.getExchangeId());
if (method != null) {
method.releaseConnection();
}
return;
}
boolean txSync = exchange.isTransacted() && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC));
+ txSync |= endpoint.isSynchronous();
NormalizedMessage nm = exchange.getMessage("in");
if (nm == null) {
throw new IllegalStateException("Exchange has no input message");
@@ -194,12 +194,12 @@
}
}
+ @SuppressWarnings("unchecked")
private void copyHeaderInformation(NormalizedMessage nm, PostMethod method) {
- Map headers = (Map) nm.getProperty(JbiConstants.PROTOCOL_HEADERS);
+ Map<String, String> headers = (Map<String, String>) nm.getProperty(JbiConstants.PROTOCOL_HEADERS);
if (headers != null) {
- for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
- String name = (String) it.next();
- String value = (String) headers.get(name);
+ for (String name : headers.keySet()) {
+ String value = headers.get(name);
method.addRequestHeader(name, value);
}
}
@@ -296,9 +296,9 @@
public void stop() throws Exception {
}
- protected Map getHeaders(HttpServletRequest request) {
- Map headers = new HashMap();
- Enumeration enumeration = request.getHeaderNames();
+ protected Map<String, String> getHeaders(HttpServletRequest request) {
+ Map<String, String> headers = new HashMap<String, String>();
+ Enumeration<?> enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
String value = request.getHeader(name);
@@ -307,8 +307,8 @@
return headers;
}
- protected Map getHeaders(HttpMethod method) {
- Map headers = new HashMap();
+ protected Map<String, String> getHeaders(HttpMethod method) {
+ Map<String, String> headers = new HashMap<String, String>();
Header[] h = method.getResponseHeaders();
for (int i = 0; i < h.length; i++) {
headers.put(h[i].getName(), h[i].getValue());
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/tools/PortTypeDecorator.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/tools/PortTypeDecorator.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/tools/PortTypeDecorator.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/tools/PortTypeDecorator.java Wed Aug 8 04:11:09 2007
@@ -37,6 +37,11 @@
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPFault;
import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.extensions.soap12.SOAP12Address;
+import javax.wsdl.extensions.soap12.SOAP12Binding;
+import javax.wsdl.extensions.soap12.SOAP12Body;
+import javax.wsdl.extensions.soap12.SOAP12Fault;
+import javax.wsdl.extensions.soap12.SOAP12Operation;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
@@ -45,6 +50,11 @@
import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
import com.ibm.wsdl.extensions.soap.SOAPFaultImpl;
import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
+import com.ibm.wsdl.extensions.soap12.SOAP12AddressImpl;
+import com.ibm.wsdl.extensions.soap12.SOAP12BindingImpl;
+import com.ibm.wsdl.extensions.soap12.SOAP12BodyImpl;
+import com.ibm.wsdl.extensions.soap12.SOAP12FaultImpl;
+import com.ibm.wsdl.extensions.soap12.SOAP12OperationImpl;
public final class PortTypeDecorator {
@@ -58,8 +68,8 @@
def.setTargetNamespace(targetNamespace);
// Add namespaces
- Map namespaces = definition.getNamespaces();
- for (Iterator iter = namespaces.keySet().iterator(); iter.hasNext();) {
+ Map<?, ?> namespaces = definition.getNamespaces();
+ for (Iterator<?> iter = namespaces.keySet().iterator(); iter.hasNext();) {
String prefix = (String) iter.next();
String uri = definition.getNamespace(prefix);
def.addNamespace(prefix, uri);
@@ -76,75 +86,134 @@
return def;
}
-
- public static void decorate(Definition def, PortType portType, String locationUri) throws Exception {
- decorate(def, portType, locationUri, portType.getQName().getLocalPart() + "Binding", portType.getQName()
- .getLocalPart()
- + "Service", "JBI");
+
+ public static void decorate(Definition def,
+ PortType portType,
+ String locationUri) throws Exception {
+ decorate(def,
+ portType,
+ locationUri,
+ portType.getQName().getLocalPart() + "Binding",
+ portType.getQName().getLocalPart() + "Service",
+ "JBI",
+ "1.1");
}
-
- public static void decorate(Definition def, PortType portType, String locationUri, String bindingName,
- String serviceName, String portName) throws Exception {
- def.addNamespace("wsdlsoap", "http://schemas.xmlsoap.org/wsdl/soap/");
+
+ public static void decorate(Definition def,
+ PortType portType,
+ String locationUri,
+ String bindingName,
+ String serviceName,
+ String portName,
+ String soapVersion) throws Exception {
+ boolean soap11 = "1.1".equals(soapVersion);
+ if (soap11) {
+ def.addNamespace("wsdlsoap", "http://schemas.xmlsoap.org/wsdl/soap/");
+ } else {
+ def.addNamespace("wsdlsoap", "http://schemas.xmlsoap.org/wsdl/soap12/");
+ }
// Create binding
Binding binding = def.createBinding();
binding.setQName(new QName(def.getTargetNamespace(), bindingName));
binding.setPortType(portType);
binding.setUndefined(false);
// Create soap extension
- SOAPBinding soap = new SOAPBindingImpl();
- soap.setTransportURI("http://schemas.xmlsoap.org/soap/http");
- soap.setStyle("document");
- binding.addExtensibilityElement(soap);
+ if (soap11) {
+ SOAPBinding soap = new SOAPBindingImpl();
+ soap.setTransportURI("http://schemas.xmlsoap.org/soap/http");
+ soap.setStyle("document");
+ binding.addExtensibilityElement(soap);
+ } else {
+ SOAP12Binding soap = new SOAP12BindingImpl();
+ soap.setTransportURI("http://schemas.xmlsoap.org/soap/http");
+ soap.setStyle("document");
+ binding.addExtensibilityElement(soap);
+ }
// Create operations
- List operations = portType.getOperations();
- for (Iterator iter = operations.iterator(); iter.hasNext();) {
+ List<?> operations = portType.getOperations();
+ for (Iterator<?> iter = operations.iterator(); iter.hasNext();) {
Operation operation = (Operation) iter.next();
- BindingOperation bindingOp = def.createBindingOperation();
- bindingOp.setName(operation.getName());
+ BindingOperation bindingOp = createBindingOperation(def, soap11, operation);
+ binding.addBindingOperation(bindingOp);
+ }
+ def.addBinding(binding);
+ // Create service
+ Service service = def.createService();
+ service.setQName(new QName(def.getTargetNamespace(), serviceName));
+ Port port = def.createPort();
+ port.setName(portName);
+ port.setBinding(binding);
+ if (soap11) {
+ SOAPAddress address = new SOAPAddressImpl();
+ address.setLocationURI(locationUri);
+ port.addExtensibilityElement(address);
+ } else {
+ SOAP12Address address = new SOAP12AddressImpl();
+ address.setLocationURI(locationUri);
+ port.addExtensibilityElement(address);
+ }
+ service.addPort(port);
+ def.addService(service);
+ }
+
+ private static BindingOperation createBindingOperation(Definition def, boolean soap11, Operation operation) {
+ BindingOperation bindingOp = def.createBindingOperation();
+ bindingOp.setName(operation.getName());
+ if (soap11) {
SOAPOperation op = new SOAPOperationImpl();
op.setSoapActionURI("");
bindingOp.addExtensibilityElement(op);
- if (operation.getInput() != null) {
- BindingInput in = def.createBindingInput();
- in.setName(operation.getInput().getName());
+ } else {
+ SOAP12Operation op = new SOAP12OperationImpl();
+ op.setSoapActionURI("");
+ bindingOp.addExtensibilityElement(op);
+ }
+ if (operation.getInput() != null) {
+ BindingInput in = def.createBindingInput();
+ in.setName(operation.getInput().getName());
+ if (soap11) {
SOAPBody body = new SOAPBodyImpl();
body.setUse("literal");
in.addExtensibilityElement(body);
- bindingOp.setBindingInput(in);
+ } else {
+ SOAP12Body body = new SOAP12BodyImpl();
+ body.setUse("literal");
+ in.addExtensibilityElement(body);
}
- if (operation.getOutput() != null) {
- BindingOutput out = def.createBindingOutput();
- out.setName(operation.getOutput().getName());
+ bindingOp.setBindingInput(in);
+ }
+ if (operation.getOutput() != null) {
+ BindingOutput out = def.createBindingOutput();
+ out.setName(operation.getOutput().getName());
+ if (soap11) {
SOAPBody body = new SOAPBodyImpl();
body.setUse("literal");
out.addExtensibilityElement(body);
- bindingOp.setBindingOutput(out);
+ } else {
+ SOAP12Body body = new SOAP12BodyImpl();
+ body.setUse("literal");
+ out.addExtensibilityElement(body);
}
- for (Iterator itf = operation.getFaults().values().iterator(); itf.hasNext();) {
- Fault fault = (Fault) itf.next();
- BindingFault bindingFault = def.createBindingFault();
- bindingFault.setName(fault.getName());
+ bindingOp.setBindingOutput(out);
+ }
+ for (Iterator<?> itf = operation.getFaults().values().iterator(); itf.hasNext();) {
+ Fault fault = (Fault) itf.next();
+ BindingFault bindingFault = def.createBindingFault();
+ bindingFault.setName(fault.getName());
+ if (soap11) {
SOAPFault soapFault = new SOAPFaultImpl();
soapFault.setUse("literal");
soapFault.setName(fault.getName());
bindingFault.addExtensibilityElement(soapFault);
- bindingOp.addBindingFault(bindingFault);
+ } else {
+ SOAP12Fault soapFault = new SOAP12FaultImpl();
+ soapFault.setUse("literal");
+ soapFault.setName(fault.getName());
+ bindingFault.addExtensibilityElement(soapFault);
}
- binding.addBindingOperation(bindingOp);
+ bindingOp.addBindingFault(bindingFault);
}
- def.addBinding(binding);
- // Create service
- Service service = def.createService();
- service.setQName(new QName(def.getTargetNamespace(), serviceName));
- Port port = def.createPort();
- port.setName(portName);
- port.setBinding(binding);
- SOAPAddress address = new SOAPAddressImpl();
- address.setLocationURI(locationUri);
- port.addExtensibilityElement(address);
- service.addPort(port);
- def.addService(service);
+ return bindingOp;
}
public static Definition decorate(Definition definition, String importUri, String targetNamespace,
@@ -153,7 +222,7 @@
Definition def = createImportDef(definition, targetNamespace, importUri);
// Iterator through port types
- for (Iterator it = definition.getPortTypes().values().iterator(); it.hasNext();) {
+ for (Iterator<?> it = definition.getPortTypes().values().iterator(); it.hasNext();) {
PortType portType = (PortType) it.next();
decorate(def, portType, locationUri);
}
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java?view=diff&rev=563813&r1=563812&r2=563813
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java Wed Aug 8 04:11:09 2007
@@ -23,6 +23,7 @@
import javax.jbi.messaging.InOut;
import javax.xml.namespace.QName;
+import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
@@ -30,6 +31,7 @@
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.commons.httpclient.util.EncodingUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.client.DefaultServiceMixClient;
@@ -44,6 +46,9 @@
private static transient Log logger = LogFactory.getLog(HttpSpringTest.class);
protected void setUp() throws Exception {
+ String str = "Basic " + EncodingUtil.getAsciiString(
+ Base64.encodeBase64(EncodingUtil.getBytes("smx:smx", "UTF-8")));
+ System.err.println(str);
if (logger.isDebugEnabled()) {
System.setProperty("javax.net.debug", "all");
}