cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1543874 - in /cxf/trunk: core/src/main/java/org/apache/cxf/message/ core/src/main/java/org/apache/cxf/service/invoker/ core/src/main/java/org/apache/cxf/validation/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/front...
Date Wed, 20 Nov 2013 16:58:04 GMT
Author: sergeyb
Date: Wed Nov 20 16:58:04 2013
New Revision: 1543874

URL: http://svn.apache.org/r1543874
Log:
[CXF-5308] Making the nest effort in AbstractValidationInterceptor to get a singleton service
object, introducing ValidationFeature

Added:
    cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationFeature.java   (with
props)
Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java
    cxf/trunk/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java
    cxf/trunk/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
    cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationInInterceptor.java
    cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.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/validation/JAXRSValidationFeature.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java?rev=1543874&r1=1543873&r2=1543874&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java Wed Nov 20 16:58:04 2013
@@ -56,6 +56,11 @@ public interface Message extends StringM
     String INVOCATION_CONTEXT = "org.apache.cxf.invocation.context";
     
     /**
+     *  Current Service Object
+     */
+    String SERVICE_OBJECT = "org.apache.cxf.service.object";
+    
+    /**
      * A Map containing the MIME headers for a SOAP message.
      */
     String MIME_HEADERS = "org.apache.cxf.mime.headers";

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java?rev=1543874&r1=1543873&r2=1543874&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java Wed Nov
20 16:58:04 2013
@@ -62,4 +62,8 @@ public class FactoryInvoker extends Abst
     public void releaseServiceObject(final Exchange ex, Object obj) {
         factory.release(ex, obj);
     }
+    
+    public boolean isSingletonFactory() {
+        return factory instanceof SingletonFactory; 
+    }
 }

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java?rev=1543874&r1=1543873&r2=1543874&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
(original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
Wed Nov 20 16:58:04 2013
@@ -25,11 +25,14 @@ import java.util.logging.Logger;
 import javax.validation.ValidationException;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.service.Service;
+import org.apache.cxf.service.invoker.FactoryInvoker;
+import org.apache.cxf.service.invoker.Invoker;
 import org.apache.cxf.service.invoker.MethodDispatcher;
 import org.apache.cxf.service.model.BindingOperationInfo;
 
@@ -75,7 +78,24 @@ public abstract class AbstractValidation
     }
     
     protected Object getServiceObject(Message message) {
-        return serviceObject;
+        if (serviceObject != null) {
+            return serviceObject;
+        }
+        Object current = message.getExchange().get(Message.SERVICE_OBJECT);
+        if (current != null) {
+            return current;
+        }
+        Endpoint e = message.getExchange().get(Endpoint.class);
+        if (e != null && e.getService() != null) {
+            Invoker invoker = e.getService().getInvoker();
+            if (invoker instanceof FactoryInvoker) {
+                FactoryInvoker factoryInvoker = (FactoryInvoker)invoker;
+                if (factoryInvoker.isSingletonFactory()) {
+                    return factoryInvoker.getServiceObject(message.getExchange()); 
+                }
+            }
+        }
+        return null;
     }
     
     protected Method getServiceMethod(Message message) {

Added: cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationFeature.java?rev=1543874&view=auto
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationFeature.java (added)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationFeature.java Wed Nov
20 16:58:04 2013
@@ -0,0 +1,33 @@
+/**
+ * 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.validation;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.interceptor.InterceptorProvider;
+
+
+public class ValidationFeature extends AbstractFeature {
+
+    @Override
+    protected void initializeProvider(InterceptorProvider provider, Bus bus) {
+        provider.getInInterceptors().add(new ValidationInInterceptor());
+        provider.getOutInterceptors().add(new ValidationOutInterceptor());
+    }
+}

Propchange: cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationFeature.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationFeature.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationInInterceptor.java?rev=1543874&r1=1543873&r2=1543874&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationInInterceptor.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationInInterceptor.java Wed
Nov 20 16:58:04 2013
@@ -21,10 +21,14 @@ package org.apache.cxf.validation;
 import java.lang.reflect.Method;
 import java.util.List;
 
+import javax.validation.ValidationException;
+
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 
 public class ValidationInInterceptor extends AbstractValidationInterceptor {
+    static final String INPUT_VALIDATION_FAILED = "input.validation.failed";
+    
     public ValidationInInterceptor() {
         super(Phase.PRE_INVOKE);
     }
@@ -35,10 +39,19 @@ public class ValidationInInterceptor ext
     @Override
     protected void handleValidation(final Message message, final Object resourceInstance,
                                     final Method method, final List<Object> arguments)
{
-        ValidationProvider provider = getProvider(message);
         if (arguments.size() > 0) {
-            provider.validateParameters(resourceInstance, method, arguments.toArray());
+            try {
+                ValidationProvider provider = getProvider(message);
+                provider.validateParameters(resourceInstance, method, unwrapArgs(arguments).toArray());
+                message.getExchange().put(ValidationProvider.class, provider);
+            } catch (ValidationException ex) {
+                message.getExchange().put(INPUT_VALIDATION_FAILED, true);
+                throw ex;
+            }
         }
-        message.getExchange().put(ValidationProvider.class, provider);
+    }
+    
+    protected List<Object> unwrapArgs(List<Object> arguments) {
+        return arguments;
     }
 }

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java?rev=1543874&r1=1543873&r2=1543874&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java Wed
Nov 20 16:58:04 2013
@@ -21,6 +21,7 @@ package org.apache.cxf.validation;
 import java.lang.reflect.Method;
 import java.util.List;
 
+import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 
@@ -35,8 +36,9 @@ public class ValidationOutInterceptor ex
     
     @Override
     protected void handleValidation(final Message message, final Object resourceInstance,
-                                    final Method method, final List<Object> arguments)
{  
-        if (arguments.size() == 1) {
+                                    final Method method, final List<Object> arguments)
{
+        if (arguments.size() == 1
+            && !PropertyUtils.isTrue(message.getExchange().get(ValidationInInterceptor.INPUT_VALIDATION_FAILED)))
{
             Object entity = unwrapEntity(arguments.get(0));
             ValidationProvider theProvider = getOutProvider(message);
             if (isEnforceOnlyBeanConstraints()) {

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=1543874&r1=1543873&r2=1543874&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
Wed Nov 20 16:58:04 2013
@@ -47,6 +47,7 @@ import org.apache.cxf.jaxrs.impl.Metadat
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
@@ -55,6 +56,7 @@ import org.apache.cxf.jaxrs.utils.HttpUt
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.logging.FaultListener;
 import org.apache.cxf.logging.NoOpFaultListener;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.message.MessageImpl;
@@ -235,21 +237,28 @@ public class JAXRSInInterceptor extends 
     private void setExchangeProperties(Message message, OperationResourceInfo ori, 
                                       MultivaluedMap<String, String> values,
                                       int numberOfResources) {
-        message.getExchange().put(OperationResourceInfo.class, ori);
-        message.getExchange().put(JAXRSUtils.ROOT_RESOURCE_CLASS, ori.getClassResourceInfo());
+        final Exchange exchange = message.getExchange();
+        final ClassResourceInfo cri = ori.getClassResourceInfo();
+        exchange.put(OperationResourceInfo.class, ori);
+        exchange.put(JAXRSUtils.ROOT_RESOURCE_CLASS, cri);
         message.put(RESOURCE_METHOD, ori.getMethodToInvoke());
         message.put(URITemplate.TEMPLATE_PARAMETERS, values);
         
         String plainOperationName = ori.getMethodToInvoke().getName();
         if (numberOfResources > 1) {
-            plainOperationName = ori.getClassResourceInfo().getServiceClass().getSimpleName()
-                + "#" + plainOperationName;
+            plainOperationName = cri.getServiceClass().getSimpleName() + "#" + plainOperationName;
         }
-        message.getExchange().put(RESOURCE_OPERATION_NAME, plainOperationName);
+        exchange.put(RESOURCE_OPERATION_NAME, plainOperationName);
         
-        boolean oneway = ori.isOneway() 
-            || MessageUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST,
null));
-        message.getExchange().setOneWay(oneway);
+        if (ori.isOneway() 
+            || MessageUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST,
null))) {
+            exchange.setOneWay(true);        
+        }
+        ResourceProvider rp = cri.getResourceProvider(); 
+        if (rp instanceof SingletonResourceProvider) {
+            //cri.isSingleton is not guaranteed to indicate we have a 'pure' singleton 
+            exchange.put(Message.SERVICE_OBJECT, rp.getInstance(message));
+        }
     }
     
     @Override

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationFeature.java?rev=1543874&r1=1543873&r2=1543874&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationFeature.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationFeature.java
Wed Nov 20 16:58:04 2013
@@ -28,6 +28,6 @@ public class JAXRSValidationFeature exte
     @Override
     protected void initializeProvider(InterceptorProvider provider, Bus bus) {
         provider.getInInterceptors().add(new JAXRSValidationInInterceptor());
-        provider.getOutInterceptors().add(new JAXRSValidationInInterceptor());
+        provider.getOutInterceptors().add(new JAXRSValidationOutInterceptor());
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInInterceptor.java?rev=1543874&r1=1543873&r2=1543874&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInInterceptor.java
Wed Nov 20 16:58:04 2013
@@ -19,10 +19,7 @@
 package org.apache.cxf.jaxrs.validation;
 
 import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.List;
 
-import javax.validation.ValidationException;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 
@@ -32,7 +29,6 @@ import org.apache.cxf.validation.Validat
 
 
 public class JAXRSValidationInInterceptor extends ValidationInInterceptor implements ContainerRequestFilter
{
-    static final String INPUT_VALIDATION_FAILED = "input.validation.failed";
     public JAXRSValidationInInterceptor() {
     }
     public JAXRSValidationInInterceptor(String phase) {
@@ -45,18 +41,6 @@ public class JAXRSValidationInIntercepto
     }
     
     @Override
-    protected void handleValidation(final Message message, final Object resourceInstance,
-                                    final Method method, final List<Object> arguments)
{
-        try {
-            super.handleValidation(message, resourceInstance, method, arguments);
-        } catch (ValidationException ex) {
-            message.getExchange().put(INPUT_VALIDATION_FAILED, true);
-            throw ex;
-        }
-    }
-    
-    
-    @Override
     public void filter(ContainerRequestContext context) throws IOException {
         super.handleMessage(PhaseInterceptorChain.getCurrentMessage());
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java?rev=1543874&r1=1543873&r2=1543874&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java
Wed Nov 20 16:58:04 2013
@@ -19,15 +19,12 @@
 package org.apache.cxf.jaxrs.validation;
 
 import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.List;
 
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerResponseContext;
 import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.core.Response;
 
-import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.validation.ValidationOutInterceptor;
@@ -42,14 +39,6 @@ public class JAXRSValidationOutIntercept
     }
     
     @Override
-    protected void handleValidation(final Message message, final Object resourceInstance,
-                                    final Method method, final List<Object> arguments)
{
-        if (!PropertyUtils.isTrue(message.getExchange().get(JAXRSValidationInInterceptor.INPUT_VALIDATION_FAILED)))
{
-            super.handleValidation(message, resourceInstance, method, arguments);
-        }
-    }
-    
-    @Override
     protected Object getServiceObject(Message message) {
         return ValidationUtils.getResourceInstance(message);
     }



Mime
View raw message