This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 0c16491 [CXF-7676] Create a proxy OutputStream to create an
EntityStream that a user's ClientRequestFilter can interact with and holds a
reference that we can set our URLConnectionWrappedOutputStream to later.
0c16491 is described below
commit 0c16491b063abe09155feac5fba605f251bb19c4
Author: Adam Anderson <[email protected]>
AuthorDate: Mon Mar 12 14:42:50 2018 -0500
[CXF-7676] Create a proxy OutputStream to create an EntityStream that a
user's ClientRequestFilter can interact with and holds a reference that we can
set our URLConnectionWrappedOutputStream to later.
---
.../spec/ClientRequestFilterInterceptor.java | 8 ++++
.../org/apache/cxf/transport/http/HTTPConduit.java | 20 +++++++---
.../cxf/transport/http/ProxyOutputStream.java | 29 ++++++++++++++
.../org/apache/cxf/systest/jaxrs/BookStore.java | 8 ++++
.../systest/jaxrs/JAXRS20ClientServerBookTest.java | 21 ++++++++++
.../cxf/systest/jaxrs/ReplacingOutputStream.java | 45 ++++++++++++++++++++++
6 files changed, 126 insertions(+), 5 deletions(-)
diff --git
a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestFilterInterceptor.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestFilterInterceptor.java
index 44430f3..d207d76 100644
---
a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestFilterInterceptor.java
+++
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestFilterInterceptor.java
@@ -19,6 +19,7 @@
package org.apache.cxf.jaxrs.client.spec;
import java.io.IOException;
+import java.io.OutputStream;
import java.util.List;
import java.util.Map;
@@ -39,6 +40,7 @@ import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.http.ProxyOutputStream;
public class ClientRequestFilterInterceptor extends
AbstractOutDatabindingInterceptor {
@@ -52,6 +54,12 @@ public class ClientRequestFilterInterceptor extends
AbstractOutDatabindingInterc
return;
}
+ // create an empty proxy output stream that the filter can interact
with
+ // and save a reference for later
+ ProxyOutputStream pos = new ProxyOutputStream();
+ outMessage.setContent(OutputStream.class, pos);
+ outMessage.setContent(ProxyOutputStream.class, pos);
+
List<ProviderInfo<ClientRequestFilter>> filters =
pf.getClientRequestFilters();
if (!filters.isEmpty()) {
diff --git
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
index 4b84aa3..fda7b8f 100644
---
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
+++
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
@@ -562,11 +562,21 @@ public abstract class HTTPConduit
setHeadersByAuthorizationPolicy(message, currentAddress.getURI());
new Headers(message).setFromClientPolicy(getClient(message));
- message.setContent(OutputStream.class,
- createOutputStream(message,
- needToCacheRequest,
- isChunking,
- chunkThreshold));
+
+ // set the OutputStream on the ProxyOutputStream
+ ProxyOutputStream pos = message.getContent(ProxyOutputStream.class);
+ if (pos != null && message.getContent(OutputStream.class) != null) {
+ pos.setWrappedOutputStream(createOutputStream(message,
+ needToCacheRequest,
+ isChunking,
+ chunkThreshold));
+ } else {
+ message.setContent(OutputStream.class,
+ createOutputStream(message,
+ needToCacheRequest,
+ isChunking,
+ chunkThreshold));
+ }
// We are now "ready" to "send" the message.
}
diff --git
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyOutputStream.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyOutputStream.java
new file mode 100644
index 0000000..f1d0f4a
--- /dev/null
+++
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyOutputStream.java
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+import java.io.OutputStream;
+
+import org.apache.cxf.io.AbstractWrappedOutputStream;
+
+public class ProxyOutputStream extends AbstractWrappedOutputStream {
+ public void setWrappedOutputStream(OutputStream os) {
+ this.wrappedStream = os;
+ }
+}
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index fe84366..538b99b 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -1668,6 +1668,14 @@ public class BookStore {
public BookSubresource getBookFromSubresource() {
return new BookSubresourceImpl();
}
+
+ @POST
+ @Path("/entityecho")
+ @Consumes("text/plain")
+ @Produces("text/plain")
+ public Response echoEntity(String entity) {
+ return Response.ok().entity(entity).build();
+ }
public final String init() {
books.clear();
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index 418408f..f3b37a8 100644
---
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -834,6 +834,27 @@ public class JAXRS20ClientServerBookTest extends
AbstractBusClientServerTestBase
ExceptionUtils.getRootCause(e) instanceof
UnknownHostException);
}
}
+
+ @Test
+ public void testGetSetEntityStream() {
+ String address = "http://localhost:" + PORT + "/bookstore/entityecho";
+ String entity = "BOOKSTORE";
+
+ Client client = ClientBuilder.newClient();
+ client.register(new ClientRequestFilter() {
+ @Override
+ public void filter(ClientRequestContext context) throws
IOException {
+ context.setEntityStream(new ReplacingOutputStream(
+ context.getEntityStream(), 'X', 'O'));
+ }
+ });
+
+ WebTarget target = client.target(address);
+
+ Response response = target.request().post(
+ Entity.entity(entity.replace('O', 'X'), "text/plain"));
+ assertEquals(entity, response.readEntity(String.class));
+ }
private static class ReplaceBodyFilter implements ClientRequestFilter {
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ReplacingOutputStream.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ReplacingOutputStream.java
new file mode 100644
index 0000000..0668961
--- /dev/null
+++
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ReplacingOutputStream.java
@@ -0,0 +1,45 @@
+/**
+ * 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.systest.jaxrs;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.cxf.io.AbstractWrappedOutputStream;
+
+public class ReplacingOutputStream extends AbstractWrappedOutputStream {
+
+ private char oldChar;
+ private char newChar;
+
+ public ReplacingOutputStream(OutputStream wrappedStream, char oldChar,
char newChar) {
+ super(wrappedStream);
+ this.oldChar = oldChar;
+ this.newChar = newChar;
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException {
+ replace(b);
+ }
+
+ private void replace(byte[] b) throws IOException {
+ this.wrappedStream.write(new String(b).replace(this.oldChar,
this.newChar).getBytes());
+ }
+}
--
To stop receiving notification emails like this one, please contact
[email protected].