Author: dkulp
Date: Fri Jul 27 18:42:30 2012
New Revision: 1366487
URL: http://svn.apache.org/viewvc?rev=1366487&view=rev
Log:
Add netty experiment - seemed to work fairly OK, but VERY VERY low level.
Would need to write a lot of code to handle connection management, keep-alives,
etc...
Added:
cxf/sandbox/dkulp_async_clients/http-netty/
cxf/sandbox/dkulp_async_clients/http-netty/pom.xml
cxf/sandbox/dkulp_async_clients/http-netty/src/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
cxf/sandbox/dkulp_async_clients/http-netty/src/test/
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/transport/
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/transport/http/
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/transport/http/asyncclient/
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
Added: cxf/sandbox/dkulp_async_clients/http-netty/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-netty/pom.xml?rev=1366487&view=auto
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-netty/pom.xml (added)
+++ cxf/sandbox/dkulp_async_clients/http-netty/pom.xml Fri Jul 27 18:42:30 2012
@@ -0,0 +1,111 @@
+<!--
+ 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.
+-->
+<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-http-netty</artifactId>
+ <packaging>jar</packaging>
+ <version>2.7.0-SNAPSHOT</version>
+ <name>Apache CXF Runtime HTTP Transport</name>
+ <description>Apache CXF Runtime HTTP Netty Transport</description>
+ <url>http://cxf.apache.org</url>
+
+ <parent>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-parent</artifactId>
+ <version>2.7.0-SNAPSHOT</version>
+ <relativePath>../../../parent/pom.xml</relativePath>
+ </parent>
+ <properties>
+ <cxf.osgi.import>
+ javax.servlet*;version="${cxf.osgi.javax.servlet.version}",
+ </cxf.osgi.import>
+ <cxf.osgi.export>
+ org.apache.cxf.*,
+ </cxf.osgi.export>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty</artifactId>
+ <version>3.5.3.Final</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.ning</groupId>
+ <artifactId>async-http-client</artifactId>
+ <version>1.7.5</version>
+ </dependency>
+
+
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-jetty</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxws</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-testutils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+
+</project>
Added:
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java?rev=1366487&view=auto
==============================================================================
---
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
(added)
+++
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
Fri Jul 27 18:42:30 2012
@@ -0,0 +1,279 @@
+/**
+ * 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.http.asyncclient;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.helpers.HttpHeaderHelper;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.http.Headers;
+import org.apache.cxf.transport.https.HttpsURLConnectionInfo;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.cxf.version.Version;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+
+import org.jboss.netty.bootstrap.ClientBootstrap;
+import org.jboss.netty.buffer.ChannelBufferInputStream;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
+import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
+import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
+import org.jboss.netty.handler.codec.http.HttpClientCodec;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpVersion;
+
+/**
+ *
+ */
+public class AsyncHTTPConduit extends HTTPConduit {
+ final ClientSocketChannelFactory factory;
+ final ClientBootstrap bootstrap;
+ ChannelFuture cachedChannel;
+
+ public AsyncHTTPConduit(Bus b, EndpointInfo ei, EndpointReferenceType t,
+ ClientSocketChannelFactory f) throws IOException {
+ super(b, ei, t);
+ this.factory = f;
+ bootstrap = new ClientBootstrap(factory);
+ bootstrap.setPipelineFactory(new CXFClientPipelineFactory());
+ }
+
+ public void close() {
+ if (cachedChannel != null) {
+ cachedChannel.getChannel().close();
+ }
+ }
+ public ChannelFuture getChannel(URL url) {
+ if (cachedChannel == null) {
+ cachedChannel = bootstrap.connect(new
InetSocketAddress(url.getHost(), url.getPort()));
+ }
+ return cachedChannel;
+ }
+
+ protected void setupConnection(Message message, URL url, HTTPClientPolicy
csPolicy) throws IOException {
+ String httpRequestMethod =
+ (String)message.get(Message.HTTP_REQUEST_METHOD);
+ if (httpRequestMethod == null) {
+ httpRequestMethod = "POST";
+ message.put(Message.HTTP_REQUEST_METHOD, httpRequestMethod);
+ }
+
+
+ ChannelFuture future = getChannel(url);
+ message.put(ChannelFuture.class, future);
+ message.put(ClientBootstrap.class, bootstrap);
+
+ DefaultHttpRequest request = new
DefaultHttpRequest(HttpVersion.HTTP_1_1,
+
HttpMethod.valueOf(httpRequestMethod),
+ url.getPath());
+ request.addHeader("Host", url.getHost() + ":" + url.getPort());
+ message.put(DefaultHttpRequest.class, request);
+ }
+
+ static class CXFClientPipelineFactory implements ChannelPipelineFactory {
+
+ public ChannelPipeline getPipeline() throws Exception {
+ // Create a default pipeline implementation.
+ ChannelPipeline pipeline =
org.jboss.netty.channel.Channels.pipeline();
+ // Enable HTTPS if necessary.
+ /*
+ if (ssl) {
+ SSLEngine engine =
+
SecureChatSslContextFactory.getClientContext().createSSLEngine();
+ engine.setUseClientMode(true);
+ pipeline.addLast("ssl", new SslHandler(engine));
+ */
+ pipeline.addLast("codec", new HttpClientCodec());
+ pipeline.addLast("cxfhandler", new CXFHandler());
+ return pipeline;
+ }
+
+ }
+ static class CXFHandler extends SimpleChannelHandler {
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
+ AsyncWrappedOutputStream out =
(AsyncWrappedOutputStream)ctx.getAttachment();
+ out.handleMessage((DefaultHttpResponse)e.getMessage());
+ }
+ }
+
+ protected OutputStream createOutputStream(Message message,
+ boolean needToCacheRequest,
+ boolean isChunking,
+ int chunkThreshold) {
+ DefaultHttpRequest request = message.get(DefaultHttpRequest.class);
+ String url = request.getUri(); //FIXME get the URL
+ return new AsyncWrappedOutputStream(message,
+ needToCacheRequest,
+ isChunking,
+ chunkThreshold,
+ getConduitName(),
+ url);
+ }
+
+
+ class AsyncWrappedOutputStream extends WrappedOutputStream {
+ DefaultHttpRequest request;
+ ChannelFuture channelFuture;
+ ChannelFuture msgFuture;
+ LoadingByteArrayOutputStream fixedBuffer;
+ DefaultHttpResponse response;
+ public AsyncWrappedOutputStream(Message message,
+ boolean needToCacheRequest,
+ boolean isChunking,
+ int chunkThreshold,
+ String conduitName,
+ String url) {
+ super(message, needToCacheRequest, isChunking,
+ chunkThreshold, conduitName,
+ url);
+ request = message.get(DefaultHttpRequest.class);
+ channelFuture = message.get(ChannelFuture.class);
+ }
+
+ public synchronized void handleMessage(DefaultHttpResponse message) {
+ response = message;
+ notifyAll();
+ }
+ public synchronized void waitForResponse() throws IOException {
+ while (response == null) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ throw new IOException(e);
+ }
+ }
+ }
+
+ protected void setProtocolHeaders() throws IOException {
+ Headers h = new Headers(outMessage);
+ request.setHeader("Content-Type", h.determineContentType());
+ for (Map.Entry<String, List<String>> header :
h.headerMap().entrySet()) {
+ if
(HttpHeaderHelper.CONTENT_TYPE.equalsIgnoreCase(header.getKey())) {
+ continue;
+ }
+
+ StringBuilder b = new StringBuilder();
+ for (int i = 0; i < header.getValue().size(); i++) {
+ b.append(header.getValue().get(i));
+ if (i + 1 < header.getValue().size()) {
+ b.append(',');
+ }
+ }
+ request.setHeader(header.getKey(), b.toString());
+ }
+ if (!h.headerMap().containsKey("User-Agent")) {
+ request.setHeader("User-Agent",
Version.getCompleteVersionString());
+ }
+ }
+
+ protected void setFixedLengthStreamingMode(int i) {
+ fixedBuffer = buffer;
+ }
+ public void thresholdReached() throws IOException {
+ request.setChunked(true);
+ }
+
+ protected void setupWrappedStream() throws IOException {
+
+ wrappedStream = new OutputStream() {
+ public void write(int b) throws IOException {
+ }
+ };
+ if (fixedBuffer != null) {
+ request.addHeader("Content-Length",
Integer.toString(fixedBuffer.size()));
+
request.setContent(ChannelBuffers.wrappedBuffer(fixedBuffer.getRawBytes(), 0,
fixedBuffer.size()));
+ }
+ channelFuture.awaitUninterruptibly();
+
channelFuture.getChannel().getPipeline().getContext("cxfhandler").setAttachment(this);
+ channelFuture.getChannel().write(request);
+ }
+
+ protected void handleResponseAsync() throws IOException {
+ }
+ protected void closeInputStream() throws IOException {
+ }
+
+ protected boolean usingProxy() {
+ return false;
+ }
+ protected HttpsURLConnectionInfo getHttpsURLConnectionInfo() throws
IOException {
+ return null;
+ }
+ protected int getResponseCode() throws IOException {
+ waitForResponse();
+ return response.getStatus().getCode();
+ }
+ protected String getResponseMessage() throws IOException {
+ waitForResponse();
+ return response.getStatus().getReasonPhrase();
+ }
+
+ private void readHeaders(Headers h) {
+ h.headerMap().clear();
+ for (String n : response.getHeaderNames()) {
+ h.headerMap().put(n, response.getHeaders(n));
+ }
+ }
+ protected void updateResponseHeaders(Message inMessage) {
+ Headers h = new Headers(inMessage);
+ readHeaders(h);
+ inMessage.put(Message.CONTENT_TYPE, h.determineContentType());
+ cookies.readFromHeaders(h);
+ }
+ protected void updateCookiesBeforeRetransmit() {
+ Headers h = new Headers();
+ readHeaders(h);
+ cookies.readFromHeaders(h);
+ }
+ protected void retransmitStream() throws IOException {
+ }
+ protected void setupNewConnection(String newURL) throws IOException {
+ }
+ protected InputStream getInputStream() throws IOException {
+ return new ChannelBufferInputStream(response.getContent()) {
+ public void close() throws IOException {
+ super.close();
+ }
+ };
+ }
+ protected InputStream getPartialResponse() throws IOException {
+ return null;
+ }
+
+ }
+
+}
Added:
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java?rev=1366487&view=auto
==============================================================================
---
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
(added)
+++
cxf/sandbox/dkulp_async_clients/http-netty/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
Fri Jul 27 18:42:30 2012
@@ -0,0 +1,125 @@
+/**
+ * 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.http.asyncclient;
+
+import java.io.IOException;
+
+import javax.annotation.Resource;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.http.HTTPConduitConfigurer;
+import org.apache.cxf.transport.http.HTTPTransportFactory;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
+import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
+
+/**
+ *
+ */
+@NoJSR250Annotations(unlessNull = "bus")
+public class AsyncHTTPTransportFactory extends HTTPTransportFactory implements
BusLifeCycleListener {
+ ClientSocketChannelFactory channelFactory;
+
+ public AsyncHTTPTransportFactory() {
+ super();
+ }
+ public AsyncHTTPTransportFactory(Bus b) {
+ super(b);
+ addListener(b);
+ }
+ public AsyncHTTPTransportFactory(Bus b, DestinationRegistry registry) {
+ super(b, registry);
+ addListener(b);
+ }
+
+ public AsyncHTTPTransportFactory(DestinationRegistry registry) {
+ super(registry);
+ }
+
+ @Resource
+ public void setBus(Bus b) {
+ super.setBus(b);
+ addListener(b);
+ }
+ public void initComplete() {
+ }
+ public synchronized void preShutdown() {
+ if (channelFactory != null) {
+ channelFactory.releaseExternalResources();
+ }
+ }
+ public void postShutdown() {
+ if (channelFactory != null) {
+ channelFactory.releaseExternalResources();
+ }
+ }
+
+ private void addListener(Bus b) {
+
b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
+ }
+
+
+ public synchronized ClientSocketChannelFactory getChannelFactory() {
+ if (channelFactory == null) {
+ channelFactory =
getBus().getExtension(ClientSocketChannelFactory.class);
+ if (channelFactory == null) {
+ channelFactory = (ClientSocketChannelFactory)getBus()
+ .getProperty(ClientSocketChannelFactory.class.getName());
+ }
+ if (channelFactory == null) {
+ channelFactory = new NioClientSocketChannelFactory();
+ }
+ }
+ return channelFactory;
+ }
+
+ /**
+ * This call creates a new HTTP Conduit based on the EndpointInfo and
+ * EndpointReferenceType.
+ * TODO: What are the formal constraints on EndpointInfo and
+ * EndpointReferenceType values?
+ */
+ public Conduit getConduit(
+ EndpointInfo endpointInfo,
+ EndpointReferenceType target
+ ) throws IOException {
+ HTTPConduit conduit = new AsyncHTTPConduit(bus, endpointInfo, target,
getChannelFactory());
+ // Spring configure the conduit.
+ String address = conduit.getAddress();
+ if (address != null && address.indexOf('?') != -1) {
+ address = address.substring(0, address.indexOf('?'));
+ }
+ HTTPConduitConfigurer c1 =
bus.getExtension(HTTPConduitConfigurer.class);
+ if (c1 != null) {
+ c1.configure(conduit.getBeanName(), address, conduit);
+ }
+ configure(conduit, conduit.getBeanName(), address);
+ conduit.finalizeConfig();
+ return conduit;
+ }
+
+}
Added:
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java?rev=1366487&view=auto
==============================================================================
---
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
(added)
+++
cxf/sandbox/dkulp_async_clients/http-netty/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
Fri Jul 27 18:42:30 2012
@@ -0,0 +1,125 @@
+/**
+ * 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.http.asyncclient;
+
+import java.net.URL;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.hello_world.Greeter;
+import org.apache.hello_world.services.SOAPService;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+
+public class AsyncHTTPConduitTest extends AbstractBusClientServerTestBase {
+ public static final String PORT = allocatePort(AsyncHTTPConduitTest.class);
+ public static final String PORT2 =
allocatePort(AsyncHTTPConduitTest.class, 2);
+
+ static Endpoint ep;
+ @BeforeClass
+ public static void start() throws Exception {
+ Bus b = createStaticBus();
+ new AsyncHTTPTransportFactory(b);
+ ep = Endpoint.publish("http://localhost:" + PORT +
"/SoapContext/SoapPort",
+ new org.apache.hello_world.GreeterImpl());
+ ep = Endpoint.publish("http://localhost:" + PORT2 +
"/SoapContext/SoapPort",
+ new org.apache.hello_world.GreeterImpl());
+ }
+
+ @AfterClass
+ public static void stop() throws Exception {
+ ep.stop();
+ ep = null;
+ }
+
+ @Test
+ public void testCall() throws Exception {
+ URL wsdl = getClass().getResource("/wsdl/hello_world_services.wsdl");
+ assertNotNull("WSDL is null", wsdl);
+
+ SOAPService service = new SOAPService();
+ assertNotNull("Service is null", service);
+
+ StringBuilder builder = new StringBuilder("NaNaNa");
+ for (int x = 0; x < 1; x++) {
+ builder.append(" NaNaNa ");
+ }
+
+ Greeter g = service.getSoapPort();
+ assertNotNull("Port is null", g);
+ updateAddressPort(g, PORT);
+ g.greetMe(builder.toString());
+ }
+
+ @Test
+ public void testCalls() throws Exception {
+ URL wsdl = getClass().getResource("/wsdl/hello_world_services.wsdl");
+ assertNotNull("WSDL is null", wsdl);
+
+ SOAPService service = new SOAPService();
+ assertNotNull("Service is null", service);
+
+ StringBuilder builder = new StringBuilder("NaNaNa");
+ for (int x = 0; x < 1; x++) {
+ builder.append(" NaNaNa ");
+ }
+
+ Greeter g = service.getSoapPort();
+ assertNotNull("Port is null", g);
+ updateAddressPort(g, PORT);
+
+ //warmup
+ for (int x = 0; x < 10000; x++) {
+ //builder.append("a");
+ //long s1 = System.nanoTime();
+ //System.out.println("aa1: " + s1);
+ String value = g.greetMe(builder.toString());
+ //long s2 = System.nanoTime();
+ //System.out.println("aa2: " + s2 + " " + (s2 - s1));
+ assertEquals("Hello " + builder.toString(), value);
+ //System.out.println();
+ }
+
+ long start = System.currentTimeMillis();
+ for (int x = 0; x < 10000; x++) {
+ //builder.append("a");
+ //long s1 = System.nanoTime();
+ //System.out.println("aa1: " + s1);
+ g.greetMe(builder.toString());
+ //long s2 = System.nanoTime();
+ //System.out.println("aa2: " + s2 + " " + (s2 - s1));
+ //System.out.println();
+ }
+ long end = System.currentTimeMillis();
+ System.out.println("Total: " + (end - start));
+ /*
+ updateAddressPort(g, PORT2);
+ String value = g.greetMe(builder.toString());
+ assertEquals("Hello " + builder.toString(), value);
+ */
+ }
+
+}