You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2007/03/20 00:03:49 UTC
svn commit: r520161 - in /incubator/cxf/sandbox/asyncweb: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/cxf/ src/main/java/org/apache/cxf/transport/
src/main/java/org/apache/cxf/transport/asyncwe...
Author: dandiep
Date: Mon Mar 19 16:03:47 2007
New Revision: 520161
URL: http://svn.apache.org/viewvc?view=rev&rev=520161
Log:
Initial cut of an AsyncWeb transport for those who might want to play
with it. Also includes a test called ServiceTest which shows how to
pause an invocation and return a response sometime later (kind of ugly
at the moment). The test seems to be having a few issues with Maven
so its disabled for now, but I'll take a peek at it again later.
Added:
incubator/cxf/sandbox/asyncweb/pom.xml
incubator/cxf/sandbox/asyncweb/src/
incubator/cxf/sandbox/asyncweb/src/main/
incubator/cxf/sandbox/asyncweb/src/main/java/
incubator/cxf/sandbox/asyncweb/src/main/java/org/
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebBackChannel.java
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebDestination.java
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebEngine.java
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebTransportFactory.java
incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/Messages.properties
incubator/cxf/sandbox/asyncweb/src/main/resources/
incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/
incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/NOTICE
incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/cxf/
incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/cxf/cxf-extension-asyncweb.xml
incubator/cxf/sandbox/asyncweb/src/main/resources/org/
incubator/cxf/sandbox/asyncweb/src/main/resources/org/codehaus/
incubator/cxf/sandbox/asyncweb/src/main/resources/org/codehaus/xwire/
incubator/cxf/sandbox/asyncweb/src/main/resources/org/codehaus/xwire/asyncweb/
incubator/cxf/sandbox/asyncweb/src/test/
incubator/cxf/sandbox/asyncweb/src/test/java/
incubator/cxf/sandbox/asyncweb/src/test/java/log4j.properties
incubator/cxf/sandbox/asyncweb/src/test/java/org/
incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/
incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/
incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/
incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/
incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/AsyncWebDestinationTest.java
incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/HelloWorld.java
incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/ServiceTest.java
incubator/cxf/sandbox/asyncweb/src/test/resources/
incubator/cxf/sandbox/asyncweb/src/test/resources/org/
incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/
incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/cxf/
incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/cxf/transport/
incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/cxf/transport/asyncweb/
incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/cxf/transport/asyncweb/test.xml
Added: incubator/cxf/sandbox/asyncweb/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/pom.xml?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/pom.xml (added)
+++ incubator/cxf/sandbox/asyncweb/pom.xml Mon Mar 19 16:03:47 2007
@@ -0,0 +1,93 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-asyncweb</artifactId>
+ <packaging>jar</packaging>
+ <version>2.0-incubator-RC-SNAPSHOT</version>
+ <name>Apache CXF AsyncWeb transport</name>
+ <url>http://cwiki.apache.org/CXF</url>
+
+ <parent>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-parent</artifactId>
+ <version>2.0-incubator-RC-SNAPSHOT</version>
+ </parent>
+
+ <dependencies>
+ <!-- CXF -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxws</artifactId>
+ <version>2.0-incubator-RC-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http</artifactId>
+ <version>2.0-incubator-RC-SNAPSHOT</version>
+ </dependency>
+
+ <!-- AsyncWeb Dependencies -->
+ <dependency>
+ <groupId>org.safehaus.asyncweb</groupId>
+ <artifactId>asyncweb-core</artifactId>
+ <version>0.9.0-20070130.023052-6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.13</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>apache-snapshots</id>
+ <name>Apache SNAPSHOT Repository</name>
+ <url>
+ http://people.apache.org/repo/m2-snapshot-repository/
+ </url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>apache-incubating</id>
+ <name>Apache Incubating Repository</name>
+ <url>
+ http://people.apache.org/repo/m2-incubating-repository/
+ </url>
+ </repository>
+ <repository>
+ <id>safehaus</id>
+ <name>Safehaus Repository</name>
+ <url>http://m2.safehaus.org/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>codehaus.snapshots</id>
+ <name>Safehaus Repository</name>
+ <url>http://snapshots.repository.codehaus.org/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+</project>
Added: incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebBackChannel.java
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebBackChannel.java?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebBackChannel.java (added)
+++ incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebBackChannel.java Mon Mar 19 16:03:47 2007
@@ -0,0 +1,119 @@
+/**
+ * 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.cxf.transport.asyncweb;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.message.Message;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.mina.common.ByteBuffer;
+import org.safehaus.asyncweb.common.DefaultHttpResponse;
+import org.safehaus.asyncweb.common.content.ByteBufferContent;
+import org.safehaus.asyncweb.service.HttpServiceContext;
+
+public class AsyncWebBackChannel implements Conduit {
+ public static final String CREATE_OUTPUT_BUFFER = "asyncweb.createOutputBuffer";
+
+ private HttpServiceContext context;
+ private DefaultHttpResponse response;
+
+ public AsyncWebBackChannel(HttpServiceContext context) {
+ super();
+ this.context = context;
+ this.response = new DefaultHttpResponse();
+ }
+
+ public void close() {
+ }
+
+ public void close(Message message) throws IOException {
+ ByteBuffer bb = message.getContent(ByteBuffer.class);
+ OutputStream out = message.getContent(OutputStream.class);
+ if (out != null) {
+ bb.flip();
+ out.close();
+ }
+
+ writeHeaders(message);
+
+ ByteBufferContent content = new ByteBufferContent(bb);
+ response.setContent(content);
+
+ context.commitResponse(response);
+ }
+
+ public Destination getBackChannel() {
+ return null;
+ }
+
+ public EndpointReferenceType getTarget() {
+ return null;
+ }
+
+ public void send(Message message) throws IOException {
+ if (!Boolean.FALSE.equals(message.get(CREATE_OUTPUT_BUFFER))) {
+ ByteBuffer bb = ByteBuffer.allocate(1024);
+ bb.setAutoExpand(true);
+ OutputStream out = newOutputStream(message, bb);
+ message.setContent(OutputStream.class, out);
+ message.setContent(ByteBuffer.class, bb);
+ }
+ }
+
+ public void setMessageObserver(MessageObserver arg0) {
+ }
+
+ @SuppressWarnings("unchecked")
+ public void writeHeaders(Message message) {
+ Map<?, ?> headers = (Map<?, ?>)message.get(Message.PROTOCOL_HEADERS);
+ if (null != headers) {
+ for (Iterator<?> iter = headers.keySet().iterator(); iter.hasNext();) {
+ String header = (String)iter.next();
+ List<String> headerList = (List<String>)headers.get(header);
+ for (String s : headerList) {
+ response.addHeader(header, s);
+ }
+ }
+ }
+ String ct = (String)message.get(Message.CONTENT_TYPE);
+ if (ct != null) {
+ response.addHeader(Message.CONTENT_TYPE, ct);
+ }
+ }
+
+ public OutputStream newOutputStream(final Message m, final ByteBuffer buf) {
+ return new OutputStream() {
+
+ public synchronized void write(int b) throws IOException {
+ buf.put((byte)b);
+ }
+
+ public synchronized void write(byte[] bytes, int off, int len) throws IOException {
+ buf.put(bytes, off, len);
+ }
+ };
+ }
+}
Added: incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebDestination.java?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebDestination.java (added)
+++ incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebDestination.java Mon Mar 19 16:03:47 2007
@@ -0,0 +1,164 @@
+/**
+ * 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.cxf.transport.asyncweb;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.ConduitInitiator;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.mina.common.ByteBuffer;
+import org.safehaus.asyncweb.common.Content;
+import org.safehaus.asyncweb.common.HttpMethod;
+import org.safehaus.asyncweb.common.HttpRequest;
+import org.safehaus.asyncweb.common.content.ByteBufferContent;
+import org.safehaus.asyncweb.service.HttpService;
+import org.safehaus.asyncweb.service.HttpServiceContext;
+
+public class AsyncWebDestination extends AbstractHTTPDestination implements HttpService {
+
+ public static final String HTTP_SERVICE_CONTEXT = "asyncWeb.serviceContext";
+
+ private static final Logger LOG = Logger.getLogger(AsyncWebDestination.class.getName());
+
+ private MessageObserver observer;
+ private AsyncWebEngine serviceEngine;
+
+ public AsyncWebDestination(Bus bus, ConduitInitiator arg1, EndpointInfo ei, boolean arg3)
+ throws IOException {
+ super(bus, arg1, ei, arg3);
+
+ URL url = new URL(ei.getAddress());
+ serviceEngine = AsyncWebEngine.getServiceEngine(url.getPort());
+
+ serviceEngine.add(url.getPath(), this);
+ }
+
+ @Override
+ protected void copyRequestHeaders(Message msg, Map<String, List<String>> headers) {
+ HttpServiceContext ctx = (HttpServiceContext)msg.get(HTTP_SERVICE_CONTEXT);
+
+ headers.putAll(ctx.getRequest().getHeaders());
+ }
+
+ @Override
+ protected Conduit getInbuiltBackChannel(Message inMessage) {
+ HttpServiceContext ctx = (HttpServiceContext)inMessage.get(HTTP_SERVICE_CONTEXT);
+
+ return new AsyncWebBackChannel(ctx);
+ }
+
+ @Override
+ protected Logger getLogger() {
+ return LOG;
+ }
+
+ public void shutdown() {
+ serviceEngine.shutdown();
+ }
+
+ public void setMessageObserver(MessageObserver obs) {
+ this.observer = obs;
+ }
+
+ public void handleRequest(HttpServiceContext context) throws Exception {
+ try {
+ if (LOG.isLoggable(Level.INFO)) {
+ LOG.info("Service http request on thread: " + Thread.currentThread());
+ }
+
+ HttpRequest req = context.getRequest();
+ HttpMethod method = req.getMethod();
+
+ MessageImpl inMessage = new MessageImpl();
+
+ setupInput(req, method, inMessage);
+
+ inMessage.put(HTTP_SERVICE_CONTEXT, context);
+ inMessage.put(Message.HTTP_REQUEST_METHOD, method.toString());
+ inMessage.put(Message.PATH_INFO, req.getRequestUri().getPath());
+ inMessage.put(Message.QUERY_STRING, req.getRequestUri().getQuery());
+ inMessage.put(Message.CONTENT_TYPE, req.getContentType());
+ // if (!StringUtils.isEmpty(getAddressValue(endpointInfo))) {
+ // inMessage.put(Message.BASE_PATH, new
+ // URL(getAddressValue(endpointInfo)).getPath());
+ // }
+ inMessage.put(Message.FIXED_PARAMETER_ORDER, isFixedParameterOrder());
+
+ setHeaders(inMessage);
+
+ inMessage.setDestination(this);
+
+ observer.onMessage(inMessage);
+ } finally {
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.fine("Finished servicing http request on thread: " + Thread.currentThread());
+ }
+ }
+ }
+
+ private void setupInput(HttpRequest req, HttpMethod method, MessageImpl inMessage) {
+ Content content = req.getContent();
+
+ if (content instanceof ByteBufferContent) {
+ ByteBufferContent bbContent = (ByteBufferContent)content;
+ InputStream is = newInputStream(bbContent.getByteBuffer());
+
+ inMessage.setContent(InputStream.class, is);
+ inMessage.setContent(ByteBuffer.class, bbContent.getByteBuffer());
+ }
+ }
+
+ // HttpService.start();
+ public void start() {
+ }
+
+ // HttpService.stop();
+ public void stop() {
+ }
+
+ public static InputStream newInputStream(final ByteBuffer buf) {
+ return new InputStream() {
+ public synchronized int read() throws IOException {
+ if (!buf.hasRemaining()) {
+ return -1;
+ }
+ return buf.get();
+ }
+
+ public synchronized int read(byte[] bytes, int off, int len) throws IOException {
+ // Read only what's left
+ len = Math.min(len, buf.remaining());
+ buf.get(bytes, off, len);
+ return len;
+ }
+ };
+ }
+}
Added: incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebEngine.java
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebEngine.java?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebEngine.java (added)
+++ incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebEngine.java Mon Mar 19 16:03:47 2007
@@ -0,0 +1,105 @@
+/**
+ * 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.cxf.transport.asyncweb;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.safehaus.asyncweb.service.BasicServiceContainer;
+import org.safehaus.asyncweb.service.ContainerLifecycleException;
+import org.safehaus.asyncweb.service.HttpService;
+import org.safehaus.asyncweb.service.HttpServiceFilter;
+import org.safehaus.asyncweb.service.HttpServiceHandler;
+import org.safehaus.asyncweb.service.Transport;
+import org.safehaus.asyncweb.service.TransportException;
+import org.safehaus.asyncweb.service.resolver.CompositeResolver;
+import org.safehaus.asyncweb.service.resolver.PassThruResolver;
+import org.safehaus.asyncweb.service.resolver.SimplePrefixResolver;
+import org.safehaus.asyncweb.service.transport.mina.DefaultHttpIoHandler;
+import org.safehaus.asyncweb.service.transport.mina.MinaTransport;
+
+public class AsyncWebEngine {
+
+ private static final Map<Integer, AsyncWebEngine> ENGINES =
+ new HashMap<Integer, AsyncWebEngine>();
+
+ private CompositeResolver resolver;
+ private HttpServiceHandler handler;
+
+ private MinaTransport mTransport;
+
+ public AsyncWebEngine(int port) {
+ mTransport = new MinaTransport();
+ mTransport.setPort(port);
+ mTransport.setIoThreads(4);
+ mTransport.setEventThreads(16);
+ mTransport.setIoHandler(new DefaultHttpIoHandler());
+ mTransport.setAddress("localhost");
+
+ resolver = new CompositeResolver();
+
+ handler = new HttpServiceHandler();
+ handler.setServiceResolver(resolver);
+
+ BasicServiceContainer container = new BasicServiceContainer();
+ List<HttpServiceFilter> filters = new ArrayList<HttpServiceFilter>();
+ filters.add(handler);
+ container.setServiceFilters(filters);
+
+ List<Transport> transports = new ArrayList<Transport>();
+ transports.add(mTransport);
+ container.setTransports(transports);
+ mTransport.setIsLoggingTraffic(true);
+
+ try {
+ container.start();
+ } catch (ContainerLifecycleException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static synchronized AsyncWebEngine getServiceEngine(int port) {
+ AsyncWebEngine engine = ENGINES.get(port);
+ if (engine == null) {
+ engine = new AsyncWebEngine(port);
+ ENGINES.put(port, engine);
+ }
+ return engine;
+ }
+
+ public void add(String prefix, HttpService service) {
+ SimplePrefixResolver prefRes = new SimplePrefixResolver();
+ prefRes.setUriPrefix(prefix);
+
+ handler.addHttpService("", service);
+
+ resolver.addResolver(prefRes);
+ resolver.addResolver(new PassThruResolver());
+ }
+
+ public void shutdown() {
+ try {
+ mTransport.stop();
+ } catch (TransportException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebTransportFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebTransportFactory.java?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebTransportFactory.java (added)
+++ incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/AsyncWebTransportFactory.java Mon Mar 19 16:03:47 2007
@@ -0,0 +1,65 @@
+/**
+ * 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.cxf.transport.asyncweb;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.AbstractTransportFactory;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.transport.DestinationFactory;
+
+public class AsyncWebTransportFactory extends AbstractTransportFactory implements DestinationFactory {
+ private static final Set<String> URI_PREFIXES = new HashSet<String>();
+ static {
+ URI_PREFIXES.add("http://");
+ URI_PREFIXES.add("https://");
+ }
+
+ private List<String> transportIds;
+ private Bus bus;
+
+ public Destination getDestination(EndpointInfo ei) throws IOException {
+ return new AsyncWebDestination(bus, null, ei, true);
+ }
+
+ public List<String> getTransportIds() {
+ return transportIds;
+ }
+
+ public void setTransportIds(List<String> transportIds) {
+ this.transportIds = transportIds;
+ }
+
+ public Set<String> getUriPrefixes() {
+ return URI_PREFIXES;
+ }
+
+ public Bus getBus() {
+ return bus;
+ }
+
+ public void setBus(Bus bus) {
+ this.bus = bus;
+ }
+}
Added: incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/main/java/org/apache/cxf/transport/asyncweb/Messages.properties?view=auto&rev=520161
==============================================================================
(empty)
Added: incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/NOTICE?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/NOTICE (added)
+++ incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/NOTICE Mon Mar 19 16:03:47 2007
@@ -0,0 +1,71 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache CXF distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ This product also includes schemas and specification developed by:
+ - the W3C consortium (http://www.w3c.org) ,
+
+ This product also includes software developed by Spring Framework
+ Project (http://www.springframework.org)
+
+ This product also includes XMLSchema developed at the apache
+ software foundation. The original software is available from
+ (http://www.apache.org/dyn/closer.cgi/ws/commons/XmlSchema)
+
+ This product also includes Wsdl4j (The Web Services Description
+ Language for Java Toolkit) developed at Sourceforge. The original
+ software is available from (http://sourceforge.net/projects/wsdl4j)
+
+ This product also inclues SAAJ (The SOAP with Attachments API for Java)
+ The original software is availabe from (http://saaj.dev.java.net/)
+
+ This product also includes JavaMail api developed by Sun MicroSystems, Inc.
+ The original software is avaiable from (http://glassfish.dev.java.net/)
+
+ This product also includes JSR 181 API developed by Java Community Process.
+ The original software is avaliable from (http://glassfish.dev.java.net/)
+
+ This product also includes JSR 250 API developed by Java Community Process.
+ The original software is available from (http://glassfish.dev.java.net/)
+
+ This product also includes Java API for XML Web Service developed by
+ Java Community Process and Sun MicroSystems, Inc. The original software
+ is available from (http://glassfish.dev.java.net/)
+
+ This product also includes Java Architecture for XML Binding developed by Java
+ Community Process and Sun MicroSystems, Inc. The original software is
+ available from (http://jaxb.dev.java.net)
+
+ This product also includes JavaBeans Activation Framework developed by
+ Java Community Process and Sun MicroSystems, Inc. The original software is
+ available from (http://jcp.org/aboutJava/communityprocess/mrel/jsr925/index.html
+
+ This product also includes software developed by Mort Bay Consulting
+ Pty (http://jetty.mortbay.org)
+
+ This product also includes software developed by Codehause
+ (http://woodstox.codehaus.org/)
+
+ This product also includes WS-* schemas developed by International
+ Business Machines Corporation, Microsoft Corporation, BEA Systems,
+ TIBCO Software, SAP AG, Sonic Software, and VeriSign
+ (http://schemas.xmlsoap.org/wsdl/2003-02-11.xsd)
+ (http://schemas.xmlsoap.org/ws/2004/08/addressing/)
+ (http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm.xsd)
+ (http://schemas.xmlsoap.org/ws/2004/09/policy/ws-policy.xsd)
+
+ This Product also includes schemas developed by OASIS
+ (http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd)
+ (http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd)
+
+ Java classes (source and binary) under org.apache.cxf.jaxws.javaee
+ are generated from schema available here:
+ (http://java.sun.com/xml/ns/javaee/javaee_5.xsd)
+
+ Additional copyright notices and license terms applicable are
+ present in the licenses directory of this distribution.
Added: incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/cxf/cxf-extension-asyncweb.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/cxf/cxf-extension-asyncweb.xml?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/cxf/cxf-extension-asyncweb.xml (added)
+++ incubator/cxf/sandbox/asyncweb/src/main/resources/META-INF/cxf/cxf-extension-asyncweb.xml Mon Mar 19 16:03:47 2007
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:foo="http://cxf.apache.org/configuration/foo"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean class="org.codehaus.xwire.asyncweb.AsyncWebTransportFactory" lazy-init="true">
+ <property name="bus" ref="cxf"/>
+ <property name="transportIds">
+ <list>
+ <value>http://schemas.xmlsoap.org/soap/http</value>
+ <value>http://schemas.xmlsoap.org/wsdl/http/</value>
+ <value>http://schemas.xmlsoap.org/wsdl/soap/http</value>
+ <value>http://www.w3.org/2003/05/soap/bindings/HTTP/</value>
+ <value>http://cxf.apache.org/transports/http/configuration</value>
+ <value>http://cxf.apache.org/bindings/xformat</value>
+ </list>
+ </property>
+ </bean>
+</beans>
Added: incubator/cxf/sandbox/asyncweb/src/test/java/log4j.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/test/java/log4j.properties?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/test/java/log4j.properties (added)
+++ incubator/cxf/sandbox/asyncweb/src/test/java/log4j.properties Mon Mar 19 16:03:47 2007
@@ -0,0 +1,6 @@
+log4j.rootLogger=WARN, stdout
+log4j.logger.org.safehaus.asyncweb=INFO
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %5p [%-26.26c{1}] %m%n
Added: incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/AsyncWebDestinationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/AsyncWebDestinationTest.java?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/AsyncWebDestinationTest.java (added)
+++ incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/AsyncWebDestinationTest.java Mon Mar 19 16:03:47 2007
@@ -0,0 +1,90 @@
+/**
+ * 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.cxf.transport.asyncweb;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.ProtocolException;
+import java.net.URL;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.test.AbstractCXFTest;
+import org.apache.cxf.transport.MessageObserver;
+import org.junit.Test;
+import org.safehaus.asyncweb.common.HttpResponseStatus;
+import org.safehaus.asyncweb.service.HttpServiceContext;
+
+public class AsyncWebDestinationTest extends AbstractCXFTest {
+ boolean get;
+
+ @Test
+ public void testGet() throws Exception {
+ EndpointInfo info = new EndpointInfo();
+ info.setAddress("http://localhost:9001/foo");
+
+ AsyncWebDestination dest = new AsyncWebDestination(getBus(), null, info, true);
+
+ MessageObserver obs = new MessageObserver() {
+
+ public void onMessage(Message m) {
+ get = true;
+
+ HttpServiceContext ctx = (HttpServiceContext)m.get(AsyncWebDestination.HTTP_SERVICE_CONTEXT);
+ ctx.commitResponse(HttpResponseStatus.ACCEPTED);
+ }
+
+ };
+ dest.setMessageObserver(obs);
+
+ invoke("http://localhost:9001/foo", null, "GET", null);
+
+ assertTrue(get);
+
+ dest.shutdown();
+ }
+
+ protected InputStream invoke(String urlStr, String message, String method, String ct)
+ throws MalformedURLException, IOException, ProtocolException {
+ URL url = new URL(urlStr);
+ HttpURLConnection c = (HttpURLConnection)url.openConnection();
+ c.setRequestMethod(method);
+
+ if (ct != null) {
+ c.setRequestProperty("Content-Type", ct);
+ }
+
+ if (message != null) {
+ c.setDoOutput(true);
+ OutputStream out = c.getOutputStream();
+ InputStream msgIs = getResourceAsStream(message);
+ assertNotNull(msgIs);
+
+ IOUtils.copy(msgIs, out);
+ out.close();
+ msgIs.close();
+ }
+
+ return c.getInputStream();
+ }
+}
Added: incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/HelloWorld.java
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/HelloWorld.java?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/HelloWorld.java (added)
+++ incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/HelloWorld.java Mon Mar 19 16:03:47 2007
@@ -0,0 +1,54 @@
+/**
+ * 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.cxf.transport.asyncweb;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.apache.cxf.interceptor.InterceptorChain;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+
+public class HelloWorld {
+ public String sayHi(String text, final Exchange e) {
+ System.out.println("invoking sayHi");
+ e.getInMessage().getInterceptorChain().pause();
+
+ TimerTask task = new TimerTask() {
+ @Override
+ public void run() {
+ System.out.println("FINISHING");
+ Message out = e.getOutMessage();
+
+ List<Object> retList = new ArrayList<Object>();
+ retList.add("Helllllllooooo");
+ out.setContent(List.class, retList);
+
+ InterceptorChain chain = e.getInMessage().getInterceptorChain();
+ chain.resume();
+ }
+ };
+
+ Timer timer = new Timer();
+ timer.schedule(task, 2000);
+ return null;
+ }
+}
Added: incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/ServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/ServiceTest.java?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/ServiceTest.java (added)
+++ incubator/cxf/sandbox/asyncweb/src/test/java/org/apache/cxf/transport/asyncweb/ServiceTest.java Mon Mar 19 16:03:47 2007
@@ -0,0 +1,100 @@
+/**
+ * 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.cxf.transport.asyncweb;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.ProtocolException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.service.invoker.BeanInvoker;
+import org.apache.cxf.test.AbstractCXFTest;
+import org.apache.cxf.transport.DestinationFactoryManager;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ServiceTest extends AbstractCXFTest {
+ boolean get;
+
+ @Test
+ @Ignore
+ // for some reason this only works in the IDE
+ public void testInvoke() throws Exception {
+ String add = "http://localhost:9001/hello";
+
+ // Setup the transport factory (normally done by Spring)
+ AsyncWebTransportFactory factory = new AsyncWebTransportFactory();
+ factory.setBus(getBus());
+ List<String> tids = new ArrayList<String>();
+ tids.add("http://schemas.xmlsoap.org/soap/http");
+ factory.setTransportIds(tids);
+
+ DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class);
+ dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/http", factory);
+
+ // Create the service
+ ServerFactoryBean bean = new ServerFactoryBean();
+ bean.setServiceClass(HelloWorld.class);
+ bean.setAddress(add);
+ bean.setBus(getBus());
+ bean.setDestinationFactory(factory);
+ bean.getServiceFactory().setInvoker(new BeanInvoker(new HelloWorld()));
+ bean.create();
+
+ InputStream res = invoke(add, "test.xml", "POST", "text/xml");
+ assertNotNull(res);
+
+ DOMUtils.readXml(res);
+ // DOMUtils.writeXml(doc, System.out);
+
+ getBus().shutdown(false);
+ }
+
+ private InputStream invoke(String urlStr, String message, String method, String ct)
+ throws MalformedURLException, IOException, ProtocolException {
+ URL url = new URL(urlStr);
+ HttpURLConnection c = (HttpURLConnection)url.openConnection();
+ c.setRequestMethod(method);
+
+ if (ct != null) {
+ c.setRequestProperty("Content-Type", ct);
+ }
+
+ if (message != null) {
+ c.setDoOutput(true);
+ OutputStream out = c.getOutputStream();
+ InputStream msgIs = getResourceAsStream(message);
+ assertNotNull(msgIs);
+
+ IOUtils.copy(msgIs, out);
+ out.close();
+ msgIs.close();
+ }
+
+ return c.getInputStream();
+ }
+}
Added: incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/cxf/transport/asyncweb/test.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/cxf/transport/asyncweb/test.xml?view=auto&rev=520161
==============================================================================
--- incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/cxf/transport/asyncweb/test.xml (added)
+++ incubator/cxf/sandbox/asyncweb/src/test/resources/org/apache/cxf/transport/asyncweb/test.xml Mon Mar 19 16:03:47 2007
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <sayHi xmlns="http://asyncweb.xwire.codehaus.org/">
+ <text>hi</text>
+ </sayHi>
+ </soap:Body>
+
+</soap:Envelope>