You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/01/21 17:52:36 UTC
svn commit: r1560089 - in /cxf/trunk:
core/src/main/java/org/apache/cxf/validation/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/
Author: sergeyb
Date: Tue Jan 21 16:52:36 2014
New Revision: 1560089
URL: http://svn.apache.org/r1560089
Log:
Relaxing the service object and method checks in the out validation interceptors which should not run if the chain was forwarded to the outbound interceptor, thanks to Andriy Redko
Added:
cxf/trunk/core/src/main/java/org/apache/cxf/validation/Messages.properties (with props)
Modified:
cxf/trunk/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationInInterceptor.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationUtils.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
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=1560089&r1=1560088&r2=1560089&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 Tue Jan 21 16:52:36 2014
@@ -20,10 +20,10 @@ package org.apache.cxf.validation;
import java.lang.reflect.Method;
import java.util.List;
+import java.util.ResourceBundle;
import java.util.logging.Logger;
-import javax.validation.ValidationException;
-
+import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.interceptor.Fault;
@@ -37,7 +37,8 @@ import org.apache.cxf.service.invoker.Me
import org.apache.cxf.service.model.BindingOperationInfo;
public abstract class AbstractValidationInterceptor extends AbstractPhaseInterceptor< Message > {
- private static final Logger LOG = LogUtils.getL7dLogger(AbstractValidationInterceptor.class);
+ protected static final Logger LOG = LogUtils.getL7dLogger(AbstractValidationInterceptor.class);
+ protected static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractValidationInterceptor.class);
private Object serviceObject;
private volatile BeanValidationProvider provider;
@@ -58,16 +59,12 @@ public abstract class AbstractValidation
public void handleMessage(Message message) throws Fault {
final Object theServiceObject = getServiceObject(message);
if (theServiceObject == null) {
- String error = "Service object is not available";
- LOG.severe(error);
- throw new ValidationException(error);
+ return;
}
final Method method = getServiceMethod(message);
if (method == null) {
- String error = "Service method is not available";
- LOG.severe(error);
- throw new ValidationException(error);
+ return;
}
Modified: cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationInInterceptor.java?rev=1560089&r1=1560088&r2=1560089&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationInInterceptor.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationInInterceptor.java Tue Jan 21 16:52:36 2014
@@ -21,6 +21,8 @@ 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;
@@ -32,6 +34,23 @@ public class BeanValidationInInterceptor
super(phase);
}
+ protected Object getServiceObject(Message message) {
+ return checkNotNull(super.getServiceObject(message), "SERVICE_OBJECT_NULL");
+ }
+
+ protected Method getServiceMethod(Message message) {
+ return (Method)checkNotNull(super.getServiceMethod(message), "SERVICE_METHOD_NULL");
+ }
+
+ private Object checkNotNull(Object object, String name) {
+ if (object == null) {
+ String message = new org.apache.cxf.common.i18n.Message(name, BUNDLE).toString();
+ LOG.severe(message);
+ throw new ValidationException(message.toString());
+ }
+ return object;
+ }
+
@Override
protected void handleValidation(final Message message, final Object resourceInstance,
final Method method, final List<Object> arguments) {
Added: cxf/trunk/core/src/main/java/org/apache/cxf/validation/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/validation/Messages.properties?rev=1560089&view=auto
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/validation/Messages.properties (added)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/validation/Messages.properties Tue Jan 21 16:52:36 2014
@@ -0,0 +1,22 @@
+#
+#
+# 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.
+#
+#
+SERVICE_OBJECT_NULL=Service Object is null
+SERVICE_METHOD_NULL=Service Method is null
\ No newline at end of file
Propchange: cxf/trunk/core/src/main/java/org/apache/cxf/validation/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/core/src/main/java/org/apache/cxf/validation/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/core/src/main/java/org/apache/cxf/validation/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationUtils.java?rev=1560089&r1=1560088&r2=1560089&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationUtils.java Tue Jan 21 16:52:36 2014
@@ -32,6 +32,9 @@ public final class ValidationUtils {
}
public static Object getResourceInstance(Message message) {
final OperationResourceInfo ori = message.getExchange().get(OperationResourceInfo.class);
+ if (ori == null) {
+ return null;
+ }
final ResourceProvider resourceProvider = ori.getClassResourceInfo().getResourceProvider();
if (!resourceProvider.isSingleton()) {
String error = "Service object is not a singleton, use a custom invoker to validate";
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java?rev=1560089&r1=1560088&r2=1560089&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java Tue Jan 21 16:52:36 2014
@@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.Collections;
import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -213,6 +214,14 @@ public class JAXRSClientServerValidation
assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
}
+ @Test
+ public void testThatResponseValidationIsNotTriggeredForUnacceptableMediaType() {
+ final Response r = createWebClient("/bookstore/books/direct")
+ .type(MediaType.APPLICATION_JSON)
+ .post(new BookWithValidation("BeanVal", "1"));
+ assertEquals(Status.UNSUPPORTED_MEDIA_TYPE.getStatusCode(), r.getStatus());
+ }
+
@Override
protected String getPort() {
return PORT;