openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1784250 - in /openwebbeans/meecrowave/trunk: integration-tests/ integration-tests/beanvalidation/ integration-tests/beanvalidation/src/ integration-tests/beanvalidation/src/main/ integration-tests/beanvalidation/src/main/java/ integration-...
Date Fri, 24 Feb 2017 09:17:38 GMT
Author: rmannibucau
Date: Fri Feb 24 09:17:38 2017
New Revision: 1784250

URL: http://svn.apache.org/viewvc?rev=1784250&view=rev
Log:
MEECROWAVE-18 bean validation mapper OOTB

Added:
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/pom.xml
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/meecrowave/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/meecrowave/beanvalidation/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/meecrowave/beanvalidation/itest/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/meecrowave/beanvalidation/itest/Service.java
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/meecrowave/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/meecrowave/beanvalidation/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/meecrowave/beanvalidation/itest/
    openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/meecrowave/beanvalidation/itest/ServiceTest.java
Modified:
    openwebbeans/meecrowave/trunk/integration-tests/pom.xml
    openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java
    openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java
    openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java
    openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java

Added: openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/pom.xml?rev=1784250&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/pom.xml (added)
+++ openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/pom.xml Fri Feb 24 09:17:38
2017
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="
+            http://maven.apache.org/POM/4.0.0
+            http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>integration-tests</artifactId>
+    <groupId>org.apache.meecrowave</groupId>
+    <version>0.3.1-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>beanvalidation</artifactId>
+  <name>Meecrowave :: Integration Tests :: Bean Validation</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.meecrowave</groupId>
+      <artifactId>meecrowave-core</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-validation_1.1_spec</artifactId>
+      <version>1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.bval</groupId>
+      <artifactId>bval-jsr</artifactId>
+      <version>1.1.2</version>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Added: openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/meecrowave/beanvalidation/itest/Service.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/meecrowave/beanvalidation/itest/Service.java?rev=1784250&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/meecrowave/beanvalidation/itest/Service.java
(added)
+++ openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/main/java/org/apache/meecrowave/beanvalidation/itest/Service.java
Fri Feb 24 09:17:38 2017
@@ -0,0 +1,54 @@
+/*
+ * 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.meecrowave.beanvalidation.itest;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+@Path("test")
+@ApplicationScoped
+public class Service {
+    @GET
+    @Valid
+    @Produces(MediaType.APPLICATION_JSON)
+    public Res get(@QueryParam("val") final String val) {
+        final Res res = new Res();
+        res.setValue(val);
+        return res;
+    }
+
+    public static class Res {
+        @NotNull
+        private String value;
+
+        public String getValue() {
+            return value;
+        }
+
+        void setValue(final String value) {
+            this.value = value;
+        }
+    }
+}

Added: openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/meecrowave/beanvalidation/itest/ServiceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/meecrowave/beanvalidation/itest/ServiceTest.java?rev=1784250&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/meecrowave/beanvalidation/itest/ServiceTest.java
(added)
+++ openwebbeans/meecrowave/trunk/integration-tests/beanvalidation/src/test/java/org/apache/meecrowave/beanvalidation/itest/ServiceTest.java
Fri Feb 24 09:17:38 2017
@@ -0,0 +1,58 @@
+/*
+ * 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.meecrowave.beanvalidation.itest;
+
+import org.apache.meecrowave.Meecrowave;
+import org.junit.Test;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.Response;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
+import static org.junit.Assert.assertEquals;
+
+public class ServiceTest {
+    @Test
+    public void bval() {
+        try (final Meecrowave container = new Meecrowave(new Meecrowave.Builder()
+                .includePackages(Service.class.getPackage().getName())
+                .randomHttpPort())
+                .bake()) {
+            final String uri = "http://localhost:" + container.getConfiguration().getHttpPort()
+ "/test";
+            final Client client = ClientBuilder.newClient();
+            try {
+                assertEquals(
+                        "{\"value\":\"ok\"}",
+                        client.target(uri)
+                                .queryParam("val", "ok")
+                                .request(APPLICATION_JSON_TYPE)
+                                .get(String.class));
+                assertEquals(
+                        Response.Status.BAD_REQUEST.getStatusCode(),
+                        client.target(uri)
+                                .request(APPLICATION_JSON_TYPE)
+                                .get()
+                                .getStatus());
+            } finally {
+                client.close();
+            }
+        }
+    }
+}

Modified: openwebbeans/meecrowave/trunk/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/pom.xml?rev=1784250&r1=1784249&r2=1784250&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/integration-tests/pom.xml Fri Feb 24 09:17:38 2017
@@ -34,5 +34,6 @@
 
   <modules>
     <module>app-groovy</module>
+    <module>beanvalidation</module>
   </modules>
 </project>

Modified: openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java?rev=1784250&r1=1784249&r2=1784250&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
Fri Feb 24 09:17:38 2017
@@ -102,6 +102,7 @@ public class MeecrowaveConfiguration imp
     private boolean tomcatNoJmx = true;
     private boolean injectServletContainerInitializer = true;
     private String tomcatAccessLogPattern;
+    private boolean jaxrsAutoActivateBeanValidation = true;
 
     // configurable cause when set to Local arquillian bypass some protocol configuration
cause of container default
     private String arquillianProtocol = "Servlet 3.1";
@@ -748,4 +749,12 @@ public class MeecrowaveConfiguration imp
     public void setArquillianProtocol(final String arquillianProtocol) {
         this.arquillianProtocol = arquillianProtocol;
     }
+
+    public boolean isJaxrsAutoActivateBeanValidation() {
+        return jaxrsAutoActivateBeanValidation;
+    }
+
+    public void setJaxrsAutoActivateBeanValidation(final boolean jaxrsAutoActivateBeanValidation)
{
+        this.jaxrsAutoActivateBeanValidation = jaxrsAutoActivateBeanValidation;
+    }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java?rev=1784250&r1=1784249&r2=1784250&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
Fri Feb 24 09:17:38 2017
@@ -925,6 +925,9 @@ public class Meecrowave implements AutoC
         @CliOption(name = "jaxrs-default-providers", description = "If jaxrsProviderSetup
is true the list of default providers to load (or defaulting to johnson jsonb and jsonp ones)")
         private String jaxrsDefaultProviders;
 
+        @CliOption(name = "jaxrs-beanvalidation", description = "Should bean validation be
activated on JAX-RS endpoint if present in the classpath.")
+        private boolean jaxrsAutoActivateBeanValidation = true;
+
         @CliOption(name = "jaxrs-log-provider", description = "Should JAX-RS providers be
logged")
         private boolean jaxrsLogProviders = false;
 
@@ -1283,6 +1286,14 @@ public class Meecrowave implements AutoC
             this.loggingGlobalSetup = loggingGlobalSetup;
         }
 
+        public boolean isJaxrsAutoActivateBeanValidation() {
+            return jaxrsAutoActivateBeanValidation;
+        }
+
+        public void setJaxrsAutoActivateBeanValidation(final boolean jaxrsAutoActivateBeanValidation)
{
+            this.jaxrsAutoActivateBeanValidation = jaxrsAutoActivateBeanValidation;
+        }
+
         public boolean isJaxrsProviderSetup() {
             return jaxrsProviderSetup;
         }

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java?rev=1784250&r1=1784249&r2=1784250&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java
Fri Feb 24 09:17:38 2017
@@ -33,9 +33,9 @@ import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-import static java.util.Arrays.asList;
 import static java.util.Optional.of;
 import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.toList;
 
 @Named("cxf")
 @ApplicationScoped
@@ -71,7 +71,7 @@ public class MeecrowaveBus implements Bu
                                         }
                                     })
                                     .collect(Collectors.<Object>toList()))
-                            .orElseGet(() -> asList(
+                            .orElseGet(() -> Stream.<Object>of(
                                     new ConfiguredJsonbJaxrsProvider(
                                             builder.getJsonbEncoding(), builder.isJsonbNulls(),
                                             builder.isJsonbIJson(), builder.isJsonbPrettify(),
@@ -80,7 +80,18 @@ public class MeecrowaveBus implements Bu
                                     new ConfiguredJsrProvider(
                                             builder.getJsonpBufferStrategy(), builder.getJsonpMaxStringLen(),
                                             builder.getJsonpMaxReadBufferLen(), builder.getJsonpMaxWriteBufferLen(),
-                                            builder.isJsonpSupportsComment(), builder.isJsonpPrettify())));
+                                            builder.isJsonpSupportsComment(), builder.isJsonpPrettify()))
+                                    .collect(toList()));
+
+            if (builder.isJaxrsAutoActivateBeanValidation()) {
+                try { // we don't need the jaxrsbeanvalidationfeature since bean validation
cdi extension handles it normally
+                    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+                    contextClassLoader.loadClass("javax.validation.Validation");
+                    providers.add(contextClassLoader.loadClass("org.apache.cxf.jaxrs.validation.ValidationExceptionMapper").newInstance());
+                } catch (final Exception | NoClassDefFoundError e) {
+                    // no-op
+                }
+            }
 
             // client
             if (getProperty("org.apache.cxf.jaxrs.bus.providers") == null) {

Modified: openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java?rev=1784250&r1=1784249&r2=1784250&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java
Fri Feb 24 09:17:38 2017
@@ -92,6 +92,7 @@ public class MeecrowaveExtension {
     private boolean tomcatNoJmx = true;
     private boolean injectServletContainerInitializer = true;
     private String tomcatAccessLogPattern;
+    private boolean jaxrsAutoActivateBeanValidation = true;
 
     public boolean isJava9SkipWorkarounds() {
         return java9SkipWorkarounds;
@@ -628,4 +629,12 @@ public class MeecrowaveExtension {
     public void setTomcatAccessLogPattern(final String tomcatAccessLogPattern) {
         this.tomcatAccessLogPattern = tomcatAccessLogPattern;
     }
+
+    public boolean isJaxrsAutoActivateBeanValidation() {
+        return jaxrsAutoActivateBeanValidation;
+    }
+
+    public void setJaxrsAutoActivateBeanValidation(final boolean jaxrsAutoActivateBeanValidation)
{
+        this.jaxrsAutoActivateBeanValidation = jaxrsAutoActivateBeanValidation;
+    }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java?rev=1784250&r1=1784249&r2=1784250&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java
Fri Feb 24 09:17:38 2017
@@ -328,6 +328,10 @@ public class MeecrowaveTask extends Defa
     @Optional
     private String tomcatAccessLogPattern;
 
+    @Input
+    @Optional
+    private boolean jaxrsAutoActivateBeanValidation = true;
+
     @TaskAction
     public void bake() {
         fixConfig();
@@ -1136,4 +1140,12 @@ public class MeecrowaveTask extends Defa
     public void setTomcatAccessLogPattern(final String tomcatAccessLogPattern) {
         this.tomcatAccessLogPattern = tomcatAccessLogPattern;
     }
+
+    public boolean isJaxrsAutoActivateBeanValidation() {
+        return jaxrsAutoActivateBeanValidation;
+    }
+
+    public void setJaxrsAutoActivateBeanValidation(final boolean jaxrsAutoActivateBeanValidation)
{
+        this.jaxrsAutoActivateBeanValidation = jaxrsAutoActivateBeanValidation;
+    }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java?rev=1784250&r1=1784249&r2=1784250&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
Fri Feb 24 09:17:38 2017
@@ -172,6 +172,9 @@ public class MeecrowaveRunMojo extends A
     @Parameter(property = "meecrowave.skip")
     private boolean skip;
 
+    @Parameter(property = "meecrowave.jaxrs-beanvalidation", defaultValue = "true")
+    private boolean jaxrsAutoActivateBeanValidation;
+
     @Parameter(property = "meecrowave.jaxrs-default-providers")
     private String jaxrsDefaultProviders;
 



Mime
View raw message