cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [20/48] cxf git commit: [CXF-6948] Optionally blocking WebClient from reporting the URI-based operation name, removing the optiona query params
Date Wed, 29 Jun 2016 22:44:18 GMT
[CXF-6948] Optionally blocking WebClient from reporting the URI-based operation name, removing
the optiona query params


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/703e40b8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/703e40b8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/703e40b8

Branch: refs/heads/master-jaxrs-2.1
Commit: 703e40b8a988935a18cf0a312efb801aff57d7f7
Parents: 18a907c
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Jun 20 21:51:13 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Jun 20 21:51:13 2016 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/client/WebClient.java    | 18 +++++++++++++++++-
 .../jaxrs/JAXRS20ClientServerBookTest.java        |  6 +++++-
 2 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/703e40b8/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
index 89780b1..892ce20 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
@@ -48,6 +48,7 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriBuilder;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -55,6 +56,7 @@ import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.util.ClassHelper;
+import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
@@ -81,6 +83,7 @@ public class WebClient extends AbstractClient {
     private static final String REQUEST_ANNS = "request.annotations";
     private static final String RESPONSE_CLASS = "response.class";
     private static final String RESPONSE_TYPE = "response.type";
+    private static final String WEB_CLIENT_OPERATION_REPORTING = "enable.webclient.operation.reporting";
     private BodyWriter bodyWriter = new BodyWriter();
     protected WebClient(String baseAddress) {
         this(convertStringToURI(baseAddress));
@@ -1071,10 +1074,23 @@ public class WebClient extends AbstractClient {
             m.put(Type.class, inGenericType);
         }
         m.getInterceptorChain().add(bodyWriter);
-        setPlainOperationNameProperty(m, httpMethod + ":" + uri.toString());
+        
+        setWebClientOperationProperty(m, httpMethod);
+        
         return m;
     }
     
+    private void setWebClientOperationProperty(Message m, String httpMethod) {
+        Object prop = m.getContextualProperty(WEB_CLIENT_OPERATION_REPORTING);
+        // Enable the operation reporting by default
+        if (prop == null || PropertyUtils.isTrue(prop)) {
+            UriBuilder absPathUri = super.getCurrentBuilder().clone();
+            absPathUri.replaceQuery(null);
+            setPlainOperationNameProperty(m, httpMethod + ":" + absPathUri.build().toString());
+        }
+        
+    }
+
     protected Response doResponse(Message m, 
                                   Class<?> responseClass, 
                                   Type outGenericType) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/703e40b8/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
----------------------------------------------------------------------
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 09815e0..2ac8f9b 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
@@ -62,6 +62,7 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.systest.jaxrs.BookStore.BookInfo;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
@@ -130,7 +131,7 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
     
     @Test
     public void testGetBook() {
-        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
+        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple?a=b";
         doTestGetBook(address, false);
     }
     
@@ -798,6 +799,9 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
 
         @Override
         public void filter(ClientRequestContext context) throws IOException {
+            String opName = 
+                (String)JAXRSUtils.getCurrentMessage().getExchange().get("org.apache.cxf.resource.operation.name");
+            assertFalse(opName.endsWith("?a=b"));
             context.getHeaders().putSingle("Simple", "simple");
             if (context.hasEntity()) {
                 context.getHeaders().putSingle("Content-Type", MediaType.APPLICATION_XML_TYPE);


Mime
View raw message