Author: dkulp
Date: Thu Aug 1 21:49:54 2013
New Revision: 1509445
URL: http://svn.apache.org/r1509445
Log:
Get the localtransport working with requests that don't have a body. (example:
GET)
Modified:
cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalConduit.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
Modified:
cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalConduit.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalConduit.java?rev=1509445&r1=1509444&r2=1509445&view=diff
==============================================================================
---
cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalConduit.java
(original)
+++
cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalConduit.java
Thu Aug 1 21:49:54 2013
@@ -41,6 +41,65 @@ import org.apache.cxf.workqueue.Synchron
public class LocalConduit extends AbstractConduit {
+ private final class LocalConduitOutputStream extends
AbstractWrappedOutputStream {
+ private final LocalConduit conduit;
+ private final Exchange exchange;
+ private final Message message;
+
+ private LocalConduitOutputStream(LocalConduit conduit, Exchange
exchange, Message message) {
+ this.conduit = conduit;
+ this.exchange = exchange;
+ this.message = message;
+ }
+
+ public void close() throws IOException {
+ if (!written) {
+ dispatchToService(true);
+ }
+ super.close();
+ }
+
+ protected void onFirstWrite() throws IOException {
+ dispatchToService(false);
+ }
+ protected void dispatchToService(boolean empty) throws IOException {
+ final MessageImpl inMsg = new MessageImpl();
+ transportFactory.copy(message, inMsg);
+
+ if (!empty) {
+ final PipedInputStream stream = new PipedInputStream();
+ wrappedStream = new PipedOutputStream(stream);
+
+ inMsg.setContent(InputStream.class, stream);
+ }
+ inMsg.setDestination(destination);
+ inMsg.put(IN_CONDUIT, conduit);
+
+ final Runnable receiver = new Runnable() {
+ public void run() {
+ ExchangeImpl ex = new ExchangeImpl();
+ ex.put(Bus.class, destination.getBus());
+ ex.setInMessage(inMsg);
+ inMsg.setExchange(ex);
+ ex.put(IN_EXCHANGE, exchange);
+ destination.getMessageObserver().onMessage(inMsg);
+ }
+ };
+ Executor ex = message.getExchange() != null
+ ? message.getExchange().get(Executor.class) : null;
+ if (ex == null || SynchronousExecutor.isA(ex)) {
+ ex = transportFactory.getExecutor(destination.getBus());
+ if (ex != null) {
+ ex.execute(receiver);
+ } else {
+ new Thread(receiver).start();
+ }
+ } else {
+ ex.execute(receiver);
+ }
+ }
+ }
+
public static final String IN_CONDUIT = LocalConduit.class.getName() +
".inConduit";
public static final String RESPONSE_CONDUIT = LocalConduit.class.getName()
+ ".inConduit";
public static final String IN_EXCHANGE = LocalConduit.class.getName() +
".inExchange";
@@ -124,42 +183,7 @@ public class LocalConduit extends Abstra
}
AbstractWrappedOutputStream cout
- = new AbstractWrappedOutputStream() {
- protected void onFirstWrite() throws IOException {
- final PipedInputStream stream = new PipedInputStream();
- wrappedStream = new PipedOutputStream(stream);
-
- final MessageImpl inMsg = new MessageImpl();
- transportFactory.copy(message, inMsg);
-
- inMsg.setContent(InputStream.class, stream);
- inMsg.setDestination(destination);
- inMsg.put(IN_CONDUIT, conduit);
-
- final Runnable receiver = new Runnable() {
- public void run() {
- ExchangeImpl ex = new ExchangeImpl();
- ex.put(Bus.class, destination.getBus());
- ex.setInMessage(inMsg);
- inMsg.setExchange(ex);
- ex.put(IN_EXCHANGE, exchange);
- destination.getMessageObserver().onMessage(inMsg);
- }
- };
- Executor ex = message.getExchange() != null
- ? message.getExchange().get(Executor.class) : null;
- if (ex == null || SynchronousExecutor.isA(ex)) {
- ex =
transportFactory.getExecutor(destination.getBus());
- if (ex != null) {
- ex.execute(receiver);
- } else {
- new Thread(receiver).start();
- }
- } else {
- ex.execute(receiver);
- }
- }
- };
+ = new LocalConduitOutputStream(conduit, exchange, message);
message.setContent(OutputStream.class, cout);
}
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java?rev=1509445&r1=1509444&r2=1509445&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
Thu Aug 1 21:49:54 2013
@@ -63,7 +63,7 @@ public class JAXRSLocalTransportTest ext
BookStore localProxy =
JAXRSClientFactory.create("local://books", BookStore.class);
-
WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);
+
//WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);
Book book = localProxy.getBook("123");
assertEquals(123L, book.getId());