Author: sergeyb
Date: Fri Mar 22 11:25:35 2013
New Revision: 1459728
URL: http://svn.apache.org/r1459728
Log:
[CXF-4912] Initial support for the wadl parameter validation
Added:
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
(with props)
cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
(with props)
Modified:
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Modified:
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1459728&r1=1459727&r2=1459728&view=diff
==============================================================================
---
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
(original)
+++
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Fri Mar 22 11:25:35 2013
@@ -95,6 +95,7 @@ import org.apache.cxf.jaxrs.utils.JAXRSU
import org.apache.cxf.jaxrs.utils.ResourceUtils;
import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.tools.common.ToolException;
import org.apache.ws.commons.schema.XmlSchema;
public class SourceGenerator {
@@ -120,6 +121,7 @@ public class SourceGenerator {
FormParam.class));
private static final Map<String, Class<?>> HTTP_METHOD_ANNOTATIONS;
private static final Map<String, Class<?>> PARAM_ANNOTATIONS;
+ private static final String PLAIN_PARAM_STYLE = "plain";
private static final Set<String> RESOURCE_LEVEL_PARAMS;
private static final Map<String, String> AUTOBOXED_PRIMITIVES_MAP;
private static final Map<String, String> XSD_SPECIFIC_TYPE_MAP;
@@ -919,7 +921,8 @@ public class SourceGenerator {
for (int i = 0; i < inParamEls.size(); i++) {
Element paramEl = inParamEls.get(i);
- Class<?> paramAnn =
PARAM_ANNOTATIONS.get(paramEl.getAttribute("style"));
+
+ Class<?> paramAnn =
getParamAnnotation(paramEl.getAttribute("style"));
if (paramAnn == QueryParam.class && form) {
paramAnn = FormParam.class;
}
@@ -1002,6 +1005,18 @@ public class SourceGenerator {
}
}
+ private Class<?> getParamAnnotation(String paramStyle) {
+ Class<?> paramAnn = PARAM_ANNOTATIONS.get(paramStyle);
+ if (paramAnn == null) {
+ String error = "Unsupported parameter style: " + paramStyle;
+ if (PLAIN_PARAM_STYLE.equals(paramStyle)) {
+ error += ", plain style parameters have to be wrapped by
representations";
+ }
+ throw new ToolException(error);
+ }
+ return paramAnn;
+ }
+
private void generateEnumClass(String clsName, List<Element> options, File
src, String classPackage) {
StringBuilder sbImports = new StringBuilder();
StringBuilder sbCode = new StringBuilder();
Added:
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java?rev=1459728&view=auto
==============================================================================
---
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
(added)
+++
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
Fri Mar 22 11:25:35 2013
@@ -0,0 +1,52 @@
+/**
+ * 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.tools.wadlto.jaxrs;
+
+import java.net.URISyntaxException;
+
+import org.apache.cxf.tools.common.ProcessorTestBase;
+import org.apache.cxf.tools.common.ToolContext;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.wadlto.WadlToolConstants;
+
+import org.junit.Test;
+
+public class ValidateWadlTest extends ProcessorTestBase {
+
+ @Test
+ public void testCodeGenInterfaces() throws Exception {
+ try {
+ JAXRSContainer container = new JAXRSContainer(null);
+
+ ToolContext context = new ToolContext();
+ context.put(WadlToolConstants.CFG_WADLURL,
getLocation("/wadl/invalidParamStyle.xml"));
+ container.setContext(context);
+ container.execute();
+ fail();
+ } catch (ToolException e) {
+ String message = e.getMessage();
+ assertTrue(message.startsWith("Unsupported parameter style:
plain"));
+ }
+ }
+
+ protected String getLocation(String wsdlFile) throws URISyntaxException {
+ return getClass().getResource(wsdlFile).toString();
+ }
+}
Propchange:
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml?rev=1459728&view=auto
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
(added)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
Fri Mar 22 11:25:35 2013
@@ -0,0 +1,31 @@
+<?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.
+-->
+<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:prefix1="http://superbooks">
+
+ <resources base="http://localhost:8080/baz">
+ <resource path="/bookstore">
+ <method name="POST">
+ <request>
+ <param name="name" style="plain" type="xs:string"/>
+ </request>
+ </method>
+ </resource>
+ </resources>
+</application>
Propchange:
cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml