wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1511849 [2/2] - in /wink/2.x/trunk: ./ wink-bv-server/ wink-bv-server/src/ wink-bv-server/src/main/ wink-bv-server/src/main/java/ wink-bv-server/src/main/java/org/ wink-bv-server/src/main/java/org/apache/ wink-bv-server/src/main/java/org/a...
Date Thu, 08 Aug 2013 16:17:06 GMT
Modified: wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/InvokeMethodHandler.java
URL: http://svn.apache.org/viewvc/wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/InvokeMethodHandler.java?rev=1511849&r1=1511848&r2=1511849&view=diff
==============================================================================
--- wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/InvokeMethodHandler.java
(original)
+++ wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/InvokeMethodHandler.java
Thu Aug  8 16:17:04 2013
@@ -25,6 +25,7 @@ import java.util.Arrays;
 
 import org.apache.wink.common.internal.application.ApplicationExceptionAttribute;
 import org.apache.wink.common.internal.log.LogUtils;
+import org.apache.wink.server.internal.validation.InvocationValidator;
 import org.apache.wink.server.handlers.AbstractHandler;
 import org.apache.wink.server.handlers.MessageContext;
 import org.apache.wink.server.internal.log.ResourceInvocation.ResourceInvocationData;
@@ -41,11 +42,22 @@ public class InvokeMethodHandler extends
         Method javaMethod = null;
         Object instance = null;
         Object[] parameters = null;
+        InvocationValidator invocationValidator;
         try {
             SearchResult searchResult = context.getAttribute(SearchResult.class);
             javaMethod = searchResult.getMethod().getMetadata().getReflectionMethod();
             parameters = searchResult.getInvocationParameters();
             instance = searchResult.getResource().getInstance(context);
+
+            invocationValidator = context.getAttribute(InvocationValidator.class);
+
+            //TODO discuss combination with other frameworks (e.g. cdi 1.1 interceptor which
does the same)
+            InvocationValidator.ValidationTask validationTask = null;
+            if (invocationValidator != null) {
+                validationTask = invocationValidator.createValidationTaskFor(context, instance,
javaMethod, parameters);
+                validationTask.validateBeforeTargetInvocation();
+            }
+
             if (logger.isTraceEnabled()) {
                 logger
                     .trace("Invoking method {} of declaring class {} on the instance of a
class {}@{} with parameters {}", //$NON-NLS-1$
@@ -61,6 +73,11 @@ public class InvokeMethodHandler extends
                 resInvocationData.addInvocation(context);
             }
             Object result = javaMethod.invoke(instance, parameters);
+
+            if (validationTask != null) {
+                validationTask.validateInvocationResult(result);
+            }
+
             context.setResponseEntity(result);
         } catch (InvocationTargetException ite) {
             try {

Modified: wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/ServerMessageContext.java
URL: http://svn.apache.org/viewvc/wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/ServerMessageContext.java?rev=1511849&r1=1511848&r2=1511849&view=diff
==============================================================================
--- wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/ServerMessageContext.java
(original)
+++ wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/ServerMessageContext.java
Thu Aug  8 16:17:04 2013
@@ -45,6 +45,7 @@ import org.apache.wink.common.internal.c
 import org.apache.wink.common.internal.contexts.ProvidersImpl;
 import org.apache.wink.common.internal.registry.ProvidersRegistry;
 import org.apache.wink.common.internal.runtime.AbstractRuntimeContext;
+import org.apache.wink.server.internal.validation.InvocationValidator;
 import org.apache.wink.server.handlers.MessageContext;
 import org.apache.wink.server.internal.DeploymentConfiguration;
 import org.apache.wink.server.internal.MediaTypeMapper;
@@ -89,6 +90,7 @@ public class ServerMessageContext extend
         setAttribute(DeploymentConfiguration.class, configuration);  // legacy
         setAttribute(ResourceRegistry.class, configuration.getResourceRegistry());
         setAttribute(ProvidersRegistry.class, configuration.getProvidersRegistry());
+        setAttribute(InvocationValidator.class, configuration.getInvocationValidator());
         if (configuration.isDefaultResponseCharset() || configuration.isUseAcceptCharset())
{
             setAttribute(MediaTypeCharsetAdjuster.class, ServerMediaTypeCharsetAdjuster.getInstance());
         }

Modified: wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/servlet/RestServlet.java
URL: http://svn.apache.org/viewvc/wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/servlet/RestServlet.java?rev=1511849&r1=1511848&r2=1511849&view=diff
==============================================================================
--- wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/servlet/RestServlet.java
(original)
+++ wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/servlet/RestServlet.java
Thu Aug  8 16:17:04 2013
@@ -321,6 +321,10 @@ public class RestServlet extends Abstrac
             of.releaseAll(null);
         }
 
+        if (getRequestProcessor().getConfiguration().getInvocationValidator() != null) {
+            getRequestProcessor().getConfiguration().getInvocationValidator().reset();
+        }
+
         /*
          * Be sure to call super.destroy()
          */

Added: wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/validation/InvocationValidator.java
URL: http://svn.apache.org/viewvc/wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/validation/InvocationValidator.java?rev=1511849&view=auto
==============================================================================
--- wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/validation/InvocationValidator.java
(added)
+++ wink/2.x/trunk/wink-server/src/main/java/org/apache/wink/server/internal/validation/InvocationValidator.java
Thu Aug  8 16:17:04 2013
@@ -0,0 +1,59 @@
+/*
+ * 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.wink.server.internal.validation;
+
+import org.apache.wink.common.RuntimeContext;
+import org.apache.wink.common.internal.lifecycle.LifecycleManagersRegistry;
+import org.apache.wink.common.internal.registry.ProvidersRegistry;
+import org.apache.wink.server.handlers.MessageContext;
+
+import java.lang.reflect.Method;
+
+public interface InvocationValidator {
+    /**
+     * Allows to check if the validator can be bootstrapped.
+     * If it wasn't successful e.g. based on a config or due to missing dependencies,...
and there are additional
+     * implementations of {@link InvocationValidator}, they get the chance.
+     * @param context needed to use {@link ObjectFactory} properly
+     * @param lifecycleManagersRegistry allows to get an {@link ObjectFactory} to do a lookup
in the current environment,
+     *                         before a validator gets bootstrapped manually (e.g. cdi supports
injection of a
+     *                         javax.validation.ValidatorFactory -> it isn't always needed
to bootstrap it manually)
+     * @return true if bootstrapping was successful, false otherwise
+     */
+    boolean init(RuntimeContext context,
+                 LifecycleManagersRegistry lifecycleManagersRegistry,
+                 ProvidersRegistry providersRegistry);
+
+    ValidationTask createValidationTaskFor(MessageContext context,
+                                           Object invocationTargetInstance,
+                                           Method invocationTargetMethod,
+                                           Object... arguments);
+
+    /**
+     * Resets the internal state, e.g. in case of an application restart to void leaking
caches,...
+     */
+    void reset();
+
+    interface ValidationTask {
+        ValidationTask validateBeforeTargetInvocation();
+
+        ValidationTask validateInvocationResult(Object result);
+    }
+}



Mime
View raw message