Author: veithen
Date: Thu Sep 11 13:39:12 2008
New Revision: 694465
URL: http://svn.apache.org/viewvc?rev=694465&view=rev
Log:
HTTP transport tests:
- Added Jetty based test endpoints for REST and echo.
- Fixed some issues so that we can again execute the test suite against
SimpleHTTPServer.
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyByteArrayAsyncEndpoint.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEchoEndpoint.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEndpoint.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyRESTAsyncEndpoint.java
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyAsyncEndpoint.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/server/axis2/AxisAsyncEndpoint.java
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java?rev=694465&r1=694464&r2=694465&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java
Thu Sep 11 13:39:12 2008
@@ -55,7 +55,7 @@
@Override
public TransportInDescription createTransportInDescription()
throws Exception {
TransportInDescription desc =
super.createTransportInDescription();
- desc.addParameter(new Parameter(SimpleHTTPServer.PARAM_PORT,
"8888"));
+ desc.addParameter(new Parameter(SimpleHTTPServer.PARAM_PORT,
"8280"));
return desc;
}
};
@@ -77,13 +77,15 @@
builder.addRESTAsyncTestClient(new JavaNetRESTClient());
builder.addAxisAsyncEndpoint(new AxisAsyncEndpoint());
- builder.addByteArrayAsyncEndpoint(new JettyAsyncEndpoint());
+ builder.addByteArrayAsyncEndpoint(new JettyByteArrayAsyncEndpoint());
+ builder.addRESTAsyncEndpoint(new JettyRESTAsyncEndpoint());
builder.addRequestResponseChannel(channel);
builder.addAxisRequestResponseTestClient(new
AxisRequestResponseTestClient());
builder.addEchoEndpoint(new AxisEchoEndpoint());
+ builder.addEchoEndpoint(new JettyEchoEndpoint());
builder.build();
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyAsyncEndpoint.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyAsyncEndpoint.java?rev=694465&r1=694464&r2=694465&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyAsyncEndpoint.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyAsyncEndpoint.java
Thu Sep 11 13:39:12 2008
@@ -20,91 +20,41 @@
package org.apache.synapse.transport.nhttp;
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.util.Enumeration;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
-
-import org.apache.commons.io.IOUtils;
import org.apache.synapse.transport.testkit.message.IncomingMessage;
import org.apache.synapse.transport.testkit.name.Name;
import org.apache.synapse.transport.testkit.server.AsyncEndpoint;
-import org.apache.synapse.transport.testkit.util.LogManager;
import org.mortbay.http.HttpException;
-import org.mortbay.http.HttpHandler;
import org.mortbay.http.HttpRequest;
import org.mortbay.http.HttpResponse;
-import org.mortbay.http.handler.AbstractHttpHandler;
@Name("jetty")
[EMAIL PROTECTED]("serial")
-public class JettyAsyncEndpoint implements AsyncEndpoint<byte[]> {
- private LogManager logManager;
- private JettyServer server;
- private HttpHandler handler;
- BlockingQueue<IncomingMessage<byte[]>> queue;
+public abstract class JettyAsyncEndpoint<M> extends JettyEndpoint implements
AsyncEndpoint<M> {
+ private BlockingQueue<IncomingMessage<M>> queue;
@SuppressWarnings("unused")
- private void setUp(LogManager logManager, JettyServer server, HttpChannel
channel) throws Exception {
- this.logManager = logManager;
- this.server = server;
- final String path = "/" + channel.getServiceName();
- queue = new LinkedBlockingQueue<IncomingMessage<byte[]>>();
- handler = new AbstractHttpHandler() {
- public void handle(String pathInContext, String pathParams,
- HttpRequest request, HttpResponse response) throws
HttpException,
- IOException {
-
- byte[] data = IOUtils.toByteArray(request.getInputStream());
- logRequest(request, data);
- if (pathInContext.equals(path)) {
- ContentType contentType;
- try {
- contentType = new
ContentType(request.getContentType());
- } catch (ParseException ex) {
- throw new HttpException(500, "Unparsable
Content-Type");
- }
- queue.add(new IncomingMessage<byte[]>(contentType, data));
- request.setHandled(true);
- }
- }
- };
- server.getContext().addHandler(handler);
- handler.start();
+ private void setUp() throws Exception {
+ queue = new LinkedBlockingQueue<IncomingMessage<M>>();
}
- void logRequest(HttpRequest request, byte[] data) throws IOException {
- OutputStream out = logManager.createLog("jetty");
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(out), false);
- for (Enumeration<?> e = request.getFieldNames(); e.hasMoreElements();
) {
- String name = (String)e.nextElement();
- for (Enumeration<?> e2 = request.getFieldValues(name);
e2.hasMoreElements(); ) {
- pw.print(name);
- pw.print(": ");
- pw.println((String)e2.nextElement());
- }
- }
- pw.println();
- pw.flush();
- out.write(data);
+ @Override
+ protected void handle(String pathParams, HttpRequest request, HttpResponse
response)
+ throws HttpException, IOException {
+
+ queue.add(handle(request));
}
+ protected abstract IncomingMessage<M> handle(HttpRequest request) throws
HttpException, IOException;
+
@SuppressWarnings("unused")
private void tearDown() throws Exception {
- handler.stop();
- server.getContext().removeHandler(handler);
- server = null;
queue = null;
- logManager = null;
}
- public IncomingMessage<byte[]> waitForMessage(int timeout) throws
Throwable {
+ public IncomingMessage<M> waitForMessage(int timeout) throws Throwable {
return queue.poll(timeout, TimeUnit.MILLISECONDS);
}
}
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyByteArrayAsyncEndpoint.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyByteArrayAsyncEndpoint.java?rev=694465&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyByteArrayAsyncEndpoint.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyByteArrayAsyncEndpoint.java
Thu Sep 11 13:39:12 2008
@@ -0,0 +1,78 @@
+/*
+ * 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.synapse.transport.nhttp;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.Enumeration;
+
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.synapse.transport.testkit.message.IncomingMessage;
+import org.apache.synapse.transport.testkit.util.LogManager;
+import org.mortbay.http.HttpException;
+import org.mortbay.http.HttpRequest;
+
+public class JettyByteArrayAsyncEndpoint extends JettyAsyncEndpoint<byte[]> {
+ private LogManager logManager;
+
+ @SuppressWarnings("unused")
+ private void setUp(LogManager logManager) throws Exception {
+ this.logManager = logManager;
+ }
+
+ @Override
+ protected IncomingMessage<byte[]> handle(HttpRequest request) throws
HttpException, IOException {
+ byte[] data = IOUtils.toByteArray(request.getInputStream());
+ logRequest(request, data);
+ ContentType contentType;
+ try {
+ contentType = new ContentType(request.getContentType());
+ } catch (ParseException ex) {
+ throw new HttpException(500, "Unparsable Content-Type");
+ }
+ return new IncomingMessage<byte[]>(contentType, data);
+ }
+
+ private void logRequest(HttpRequest request, byte[] data) throws
IOException {
+ OutputStream out = logManager.createLog("jetty");
+ PrintWriter pw = new PrintWriter(new OutputStreamWriter(out), false);
+ for (Enumeration<?> e = request.getFieldNames(); e.hasMoreElements();
) {
+ String name = (String)e.nextElement();
+ for (Enumeration<?> e2 = request.getFieldValues(name);
e2.hasMoreElements(); ) {
+ pw.print(name);
+ pw.print(": ");
+ pw.println((String)e2.nextElement());
+ }
+ }
+ pw.println();
+ pw.flush();
+ out.write(data);
+ }
+
+ @SuppressWarnings("unused")
+ private void tearDown() throws Exception {
+ logManager = null;
+ }
+}
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEchoEndpoint.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEchoEndpoint.java?rev=694465&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEchoEndpoint.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEchoEndpoint.java
Thu Sep 11 13:39:12 2008
@@ -0,0 +1,37 @@
+/*
+ * 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.synapse.transport.nhttp;
+
+import java.io.IOException;
+
+import org.apache.commons.io.IOUtils;
+import org.mortbay.http.HttpException;
+import org.mortbay.http.HttpRequest;
+import org.mortbay.http.HttpResponse;
+
+public class JettyEchoEndpoint extends JettyEndpoint {
+ @Override
+ protected void handle(String pathParams, HttpRequest request,
+ HttpResponse response) throws HttpException, IOException {
+
+ response.setContentType(request.getContentType());
+ IOUtils.copy(request.getInputStream(), response.getOutputStream());
+ }
+}
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEndpoint.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEndpoint.java?rev=694465&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEndpoint.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyEndpoint.java
Thu Sep 11 13:39:12 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.synapse.transport.nhttp;
+
+import java.io.IOException;
+
+import org.apache.synapse.transport.testkit.server.Endpoint;
+import org.mortbay.http.HttpException;
+import org.mortbay.http.HttpHandler;
+import org.mortbay.http.HttpRequest;
+import org.mortbay.http.HttpResponse;
+import org.mortbay.http.handler.AbstractHttpHandler;
+
+public abstract class JettyEndpoint implements Endpoint {
+ private JettyServer server;
+ private HttpHandler handler;
+
+ @SuppressWarnings({ "unused", "serial" })
+ private void setUp(JettyServer server, HttpChannel channel) throws
Exception {
+ this.server = server;
+ final String path = "/" + channel.getServiceName();
+ handler = new AbstractHttpHandler() {
+ public void handle(String pathInContext, String pathParams,
+ HttpRequest request, HttpResponse response) throws
HttpException,
+ IOException {
+
+ if (pathInContext.equals(path)) {
+ JettyEndpoint.this.handle(pathParams, request, response);
+ request.setHandled(true);
+ }
+ }
+ };
+ server.getContext().addHandler(handler);
+ handler.start();
+ }
+
+ @SuppressWarnings("unused")
+ private void tearDown() throws Exception {
+ handler.stop();
+ server.getContext().removeHandler(handler);
+ server = null;
+ }
+
+ protected abstract void handle(String pathParams, HttpRequest request,
HttpResponse response)
+ throws HttpException, IOException;
+
+}
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyRESTAsyncEndpoint.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyRESTAsyncEndpoint.java?rev=694465&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyRESTAsyncEndpoint.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/JettyRESTAsyncEndpoint.java
Thu Sep 11 13:39:12 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.synapse.transport.nhttp;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.synapse.transport.testkit.message.IncomingMessage;
+import org.apache.synapse.transport.testkit.message.RESTMessage;
+import org.apache.synapse.transport.testkit.message.RESTMessage.Parameter;
+import org.mortbay.http.HttpException;
+import org.mortbay.http.HttpRequest;
+
+public class JettyRESTAsyncEndpoint extends JettyAsyncEndpoint<RESTMessage> {
+ @Override
+ protected IncomingMessage<RESTMessage> handle(HttpRequest request)
+ throws HttpException, IOException {
+
+ List<Parameter> parameters = new LinkedList<Parameter>();
+ for (Map.Entry<String,List<String>> entry :
+
((Map<String,List<String>>)request.getParameters()).entrySet()) {
+ for (String value : entry.getValue()) {
+ parameters.add(new Parameter(entry.getKey(), value));
+ }
+ }
+ return new IncomingMessage<RESTMessage>(null, new
RESTMessage(parameters.toArray(
+ new Parameter[parameters.size()])));
+ }
+}
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/server/axis2/AxisAsyncEndpoint.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/server/axis2/AxisAsyncEndpoint.java?rev=694465&r1=694464&r2=694465&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/server/axis2/AxisAsyncEndpoint.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/server/axis2/AxisAsyncEndpoint.java
Thu Sep 11 13:39:12 2008
@@ -48,7 +48,7 @@
@Override
protected AxisOperation createOperation() {
- AxisOperation operation = new InOnlyAxisOperation(new QName("in"));
+ AxisOperation operation = new InOnlyAxisOperation(new
QName("default"));
operation.setMessageReceiver(this);
return operation;
}