cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r904195 - in /cxf/trunk: api/src/main/java/org/apache/cxf/message/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ ...
Date Thu, 28 Jan 2010 18:12:01 GMT
Author: sergeyb
Date: Thu Jan 28 18:12:00 2010
New Revision: 904195

URL: http://svn.apache.org/viewvc?rev=904195&view=rev
Log:
JAXRS : support for oneway invocations

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Oneway.java   (with
props)
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java?rev=904195&r1=904194&r2=904195&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java Thu Jan 28 18:12:00 2010
@@ -67,7 +67,7 @@
      */
     String DECOUPLED_CHANNEL_MESSAGE = "decoupled.channel.message";
     String PARTIAL_RESPONSE_MESSAGE = "org.apache.cxf.partial.response";
-    String ONE_WAY_MESSAGE = "OnewayMessage";
+    String ONE_WAY_REQUEST = "OnewayRequest";
     
     String PROTOCOL_HEADERS = Message.class.getName() + ".PROTOCOL_HEADERS";
     String RESPONSE_CODE = Message.class.getName() + ".RESPONSE_CODE";

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=904195&r1=904194&r2=904195&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Thu Jan
28 18:12:00 2010
@@ -81,6 +81,9 @@
         try {
             return invoke(exchange, request, serviceObject);
         } finally {
+            if (exchange.isOneWay()) {
+                ProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
+            }
             if (!isServiceObjectRequestScope(exchange.getInMessage())) {
                 provider.releaseInstance(exchange.getInMessage(), serviceObject);
             } else {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=904195&r1=904194&r2=904195&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Thu Jan 28 18:12:00 2010
@@ -557,7 +557,7 @@
         exchange.put(Bus.class, cfg.getBus());
         exchange.put(MessageObserver.class, new ClientMessageObserver(cfg));
         exchange.put(Endpoint.class, cfg.getConduitSelector().getEndpoint());
-        exchange.setOneWay(false);
+        exchange.setOneWay("true".equals(headers.getFirst(Message.ONE_WAY_REQUEST)));
         m.setExchange(exchange);
         
         PhaseInterceptorChain chain = setupOutInterceptorChain(cfg);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=904195&r1=904194&r2=904195&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Thu Jan 28 18:12:00 2010
@@ -403,6 +403,7 @@
                           MultivaluedMap<ParameterType, Parameter> types,
                           List<Object> pathParams) throws Throwable {
         Message outMessage = createMessage(ori.getHttpMethod(), headers, uri);
+        outMessage.getExchange().setOneWay(ori.isOneway());
         if (pathParams.size() != 0) { 
             List<String> vars = ori.getURITemplate().getVariables();
             MultivaluedMap<String, String> templatesMap =  new MetadataMap<String,
String>(vars.size());

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Oneway.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Oneway.java?rev=904195&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Oneway.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Oneway.java Thu Jan
28 18:12:00 2010
@@ -0,0 +1,34 @@
+/**
+ * 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.jaxrs.ext;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Can be used to nominate oneway methods
+ * 
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Oneway {
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Oneway.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Oneway.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=904195&r1=904194&r2=904195&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Thu Jan 28 18:12:00 2010
@@ -173,7 +173,7 @@
                     ori = JAXRSUtils.findTargetMethod(resource, 
                         message, httpMethod, values, 
                         requestContentType, acceptContentTypes, false);
-                    setMessageProperties(message, ori, values, resources.size());
+                    setExchangeProperties(message, ori, values, resources.size());
                 } catch (WebApplicationException ex) {
                     operChecked = true;
                 }
@@ -203,7 +203,7 @@
             try {                
                 ori = JAXRSUtils.findTargetMethod(resource, message, 
                                             httpMethod, values, requestContentType, acceptContentTypes,
true);
-                setMessageProperties(message, ori, values, resources.size());
+                setExchangeProperties(message, ori, values, resources.size());
             } catch (WebApplicationException ex) {
                 if (ex.getResponse() != null && ex.getResponse().getStatus() == 405

                     && "OPTIONS".equalsIgnoreCase(httpMethod)) {
@@ -224,14 +224,14 @@
 
             LOG.fine("Found operation: " + ori.getMethodToInvoke().getName());
         }
-        setMessageProperties(message, ori, values, resources.size());  
+        setExchangeProperties(message, ori, values, resources.size());  
       
         //Process parameters
         List<Object> params = JAXRSUtils.processParameters(ori, values, message);
         message.setContent(List.class, params);
     }
     
-    private void setMessageProperties(Message message, OperationResourceInfo ori, 
+    private void setExchangeProperties(Message message, OperationResourceInfo ori, 
                                       MultivaluedMap<String, String> values,
                                       int numberOfResources) {
         message.getExchange().put(OperationResourceInfo.class, ori);
@@ -244,7 +244,8 @@
         }
         message.getExchange().put("org.apache.cxf.resource.operation.name", plainOperationName);
         
-        message.getExchange().setOneWay(
-            MessageUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_MESSAGE,
null)));
+        boolean oneway = ori.isOneway() 
+            || MessageUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST,
null));
+        message.getExchange().setOneWay(oneway);
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java?rev=904195&r1=904194&r2=904195&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
Thu Jan 28 18:12:00 2010
@@ -28,6 +28,7 @@
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -43,6 +44,7 @@
     private boolean encoded;
     private String defaultParamValue;
     private List<Parameter> parameters;
+    private boolean oneway; 
 
     public OperationResourceInfo(Method mInvoke, ClassResourceInfo cri) {
         this(mInvoke, mInvoke, cri);
@@ -58,6 +60,7 @@
         this.encoded = ori.encoded;
         this.defaultParamValue = ori.defaultParamValue;
         this.parameters = ori.parameters;
+        this.oneway = ori.oneway;
         this.classResourceInfo = cri;
     }
     
@@ -71,6 +74,7 @@
         checkMediaTypes(null, null);
         checkEncoded();
         checkDefaultParameterValue();
+        checkOneway();
     }
     
     public OperationResourceInfo(Method m, 
@@ -89,6 +93,16 @@
         parameters = params;
     }
 
+    private void checkOneway() {
+        if (annotatedMethod != null) {
+            oneway = AnnotationUtils.getAnnotation(annotatedMethod.getAnnotations(), Oneway.class)
!= null;
+        }
+    }
+
+    public boolean isOneway() {
+        return oneway;
+    }
+    
     public List<Parameter> getParameters() {
         return parameters;
     }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=904195&r1=904194&r2=904195&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Thu
Jan 28 18:12:00 2010
@@ -65,6 +65,7 @@
 import javax.xml.transform.dom.DOMSource;
 
 import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
 @Path("/bookstore")
@@ -489,6 +490,15 @@
     }
     
     @POST
+    @Path("/oneway")
+    @Oneway
+    public void onewayRequest() {
+        if (!PhaseInterceptorChain.getCurrentMessage().getExchange().isOneWay()) {
+            throw new WebApplicationException();
+        }
+    }
+    
+    @POST
     @Path("/books/customstatus")
     @Produces("text/xml")
     @Consumes("text/xml")

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=904195&r1=904194&r2=904195&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Thu Jan 28 18:12:00 2010
@@ -61,6 +61,20 @@
     
     
     @Test
+    public void testOnewayWebClient() throws Exception {
+        WebClient client = WebClient.create("http://localhost:9080/bookstore/oneway");
+        Response r = client.header("OnewayRequest", "true").post(null);
+        assertEquals(202, r.getStatus());
+    }
+    
+    @Test
+    public void testOnewayProxy() throws Exception {
+        BookStore proxy = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
+        proxy.onewayRequest();
+        assertEquals(202, WebClient.client(proxy).getResponse().getStatus());
+    }
+    
+    @Test
     public void testPropogateException() throws Exception {
         getAndCompare("http://localhost:9080/bookstore/propogateexception",
                       "", "application/xml", 500);



Mime
View raw message