Permalink
Browse files

AS7-4208 Inconsistent behaviour when dealing with resteasy scanning c…

…ontext params
  • Loading branch information...
stuartwdouglas committed Mar 18, 2012
1 parent 4781044 commit b3a1e8b587ec620982d2ff5218708f52587ba917
@@ -22,14 +22,14 @@
package org.jboss.as.jaxrs;
+import javax.ws.rs.core.Application;
+
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.logging.Cause;
import org.jboss.logging.Message;
import org.jboss.logging.MessageBundle;
import org.jboss.logging.Messages;
-import javax.ws.rs.core.Application;
-
/**
* Date: 05.11.2011
*
@@ -47,7 +47,6 @@
* Creates an exception indicating the JAX-RS application class could not be loaded.
*
* @param cause the cause of the error.
- *
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 11230, value = "Could not load JAX-RS Application class")
@@ -58,7 +57,6 @@
*
* @param app1 the first application.
* @param app2 the second application.
- *
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 11231, value = "More than one Application class found in deployment %s and %s")
@@ -68,7 +66,6 @@
* A message indicating only one JAX-RS application class is allowed.
*
* @param sb a builder with application classes.
- *
* @return the message.
*/
@Message(id = 11232, value = "Only one JAX-RS Application Class allowed. %s")
@@ -84,12 +81,15 @@
/**
* JAX-RS resource @Path annotation is on a class or interface that is not a view
- * @param type The class with the annotation
+ *
+ * @param type The class with the annotation
* @param ejbName The ejb
* @return
*/
@Message(id = 11234, value = "JAX-RS resource %s does not correspond to a view on the EJB %s. @Path annotations can only be placed on classes or interfaces that represent a local, remote or no-interface view of an EJB.")
DeploymentUnitProcessingException typeNameNotAnEjbView(String type, String ejbName);
+ @Message(id = 11235, value = "Invalid value for parameter %s: %s")
+ DeploymentUnitProcessingException invalidParamValue(String param, String value);
}
@@ -25,7 +25,6 @@
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.spec.FilterMetaData;
import org.jboss.metadata.web.spec.ServletMappingMetaData;
-import org.jboss.modules.Module;
import org.jboss.modules.ModuleIdentifier;
import org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher;
import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
@@ -47,7 +46,6 @@
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
- final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (!JaxrsDeploymentMarker.isJaxrsDeployment(deploymentUnit)) {
return;
@@ -76,13 +74,10 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
final ParamValueMetaData param = it.next();
if (param.getParamName().equals(RESTEASY_SCAN)) {
it.remove();
- JAXRS_LOGGER.resteasyScanWarning(RESTEASY_SCAN);
} else if (param.getParamName().equals(RESTEASY_SCAN_RESOURCES)) {
it.remove();
- JAXRS_LOGGER.resteasyScanWarning(RESTEASY_SCAN_RESOURCES);
} else if (param.getParamName().equals(RESTEASY_SCAN_PROVIDERS)) {
it.remove();
- JAXRS_LOGGER.resteasyScanWarning(RESTEASY_SCAN_PROVIDERS);
}
}
}
@@ -155,12 +150,6 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
if (resteasy.hasBootClasses() || resteasy.isDispatcherCreated())
return;
- //if there are no JAX-RS classes in the app just return
- if (resteasy.getScannedApplicationClass() == null
- && resteasy.getScannedJndiComponentResources().isEmpty()
- && resteasy.getScannedProviderClasses().isEmpty()
- && resteasy.getScannedResourceClasses().isEmpty()) return;
-
boolean useScannedClass = false;
String servletName;
if (resteasy.getScannedApplicationClass() == null) {
@@ -21,9 +21,6 @@
*/
package org.jboss.as.jaxrs.deployment;
-import static org.jboss.as.jaxrs.JaxrsLogger.JAXRS_LOGGER;
-import static org.jboss.as.jaxrs.JaxrsMessages.MESSAGES;
-
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
@@ -36,6 +33,7 @@
import javax.ws.rs.core.Application;
import org.jboss.as.jaxrs.JaxrsAnnotations;
+import org.jboss.as.jaxrs.JaxrsMessages;
import org.jboss.as.server.Services;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
@@ -61,6 +59,12 @@
import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrapClasses;
import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
+import static org.jboss.as.jaxrs.JaxrsLogger.JAXRS_LOGGER;
+import static org.jboss.as.jaxrs.JaxrsMessages.MESSAGES;
+import static org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters.RESTEASY_SCAN;
+import static org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters.RESTEASY_SCAN_PROVIDERS;
+import static org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters.RESTEASY_SCAN_RESOURCES;
+
/**
* Processor that finds jax-rs classes in the deployment
*
@@ -80,7 +84,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
}
final DeploymentUnit parent = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
final Map<ModuleIdentifier, ResteasyDeploymentData> deploymentData;
- if(deploymentUnit.getParent() == null) {
+ if (deploymentUnit.getParent() == null) {
deploymentData = Collections.synchronizedMap(new HashMap<ModuleIdentifier, ResteasyDeploymentData>());
deploymentUnit.putAttachment(JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA, deploymentData);
} else {
@@ -171,12 +175,12 @@ protected void scanWebDeployment(final DeploymentUnit du, final JBossWebMetaData
if (contextParams != null) {
for (ParamValueMetaData param : contextParams) {
- if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_SCAN)) {
- resteasyDeploymentData.setScanAll(Boolean.valueOf(param.getParamValue()));
+ if (param.getParamName().equals(RESTEASY_SCAN)) {
+ resteasyDeploymentData.setScanAll(valueOf(RESTEASY_SCAN, param.getParamValue()));
} else if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_SCAN_PROVIDERS)) {
- resteasyDeploymentData.setScanProviders(Boolean.valueOf(param.getParamValue()));
- } else if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_SCAN_RESOURCES)) {
- resteasyDeploymentData.setScanResources(Boolean.valueOf(param.getParamValue()));
+ resteasyDeploymentData.setScanProviders(valueOf(RESTEASY_SCAN_PROVIDERS, param.getParamValue()));
+ } else if (param.getParamName().equals(RESTEASY_SCAN_RESOURCES)) {
+ resteasyDeploymentData.setScanResources(valueOf(RESTEASY_SCAN_RESOURCES, param.getParamValue()));
} else if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_UNWRAPPED_EXCEPTIONS)) {
resteasyDeploymentData.setUnwrappedExceptionsParameterSet(true);
}
@@ -308,4 +312,18 @@ protected void scan(final DeploymentUnit du, final ClassLoader classLoader, fina
return null;
}
+
+ private boolean valueOf(String paramName, String value) throws DeploymentUnitProcessingException {
+ if (value == null) {
+ throw JaxrsMessages.MESSAGES.invalidParamValue(paramName, value);
+ }
+ if (value.toLowerCase().equals("true")) {
+ return true;
+ } else if (value.toLowerCase().equals("false")) {
+ return false;
+ } else {
+ throw JaxrsMessages.MESSAGES.invalidParamValue(paramName, value);
+ }
+ }
+
}
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.as.test.integration.jaxrs.cfg;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+@Path("helloworld")
+@Produces({"text/plain"})
+public class HelloWorldResource {
+ @GET
+ public String getMessage() {
+ return "Hello World!";
+ }
+}
@@ -1,62 +0,0 @@
-package org.jboss.as.test.integration.jaxrs.cfg;
-
-import java.util.concurrent.TimeUnit;
-import java.net.URL;
-
-import org.jboss.as.test.integration.common.HttpRequest;
-import org.jboss.as.test.integration.jaxrs.packaging.war.HelloWorldResource;
-import org.jboss.as.test.integration.jaxrs.packaging.war.WebXml;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-
-public abstract class ResteasyParamsParent {
-
- private final static String DEP_NAME = "default";
-
- public static Archive<?> getDeploy(final String depName,
- final Class<?> clazz, final String paramName,
- final String paramValue) {
- return getDeploy(depName, clazz, paramName, paramValue, "", "");
- }
-
- public static Archive<?> getDeploy(final Class<?> clazz,
- final String paramName, final String paramValue) {
- return getDeploy(DEP_NAME, clazz, paramName, paramValue, "", "");
- }
-
- public static Archive<?> getDeploy(final Class<?> clazz,
- final String paramName, final String paramValue, final String webXmlBefore, final String webXmlAfter) {
- return getDeploy(DEP_NAME, clazz, paramName, paramValue, webXmlBefore, webXmlAfter);
- }
-
- public static Archive<?> getDeploy(final String depName,
- final Class<?> clazz, final String paramName,
- final String paramValue, final String webXmlBefore, final String webXmlAfter) {
- WebArchive war = ShrinkWrap.create(WebArchive.class, "jaxrsnoap_"
- + (depName == null ? DEP_NAME : depName.length() > 0 ? depName
- : DEP_NAME) + ".war");
- war.addPackage(HttpRequest.class.getPackage());
- war.addClasses(clazz, ResteasyParamsParent.class, HelloWorldResource.class);
- war.addAsWebInfResource(
- WebXml.get(webXmlBefore
- + "<servlet-mapping>\n"
- + " <servlet-name>javax.ws.rs.core.Application</servlet-name>\n"
- + " <url-pattern>/myjaxrs/*</url-pattern>\n"
- + "</servlet-mapping>\n"
- + "\n"
- + "<context-param>\n"
- + " <param-name>" + paramName + "</param-name>\n"
- + " <param-value>" + paramValue + "</param-value>\n"
- + "</context-param>\n"
- + webXmlAfter
- + "\n"), "web.xml");
- return war;
- }
-
- public static String performCall(final String urlPattern, URL url)
- throws Exception {
- return HttpRequest.get(url + urlPattern, 5, TimeUnit.SECONDS);
- }
-
-}
Oops, something went wrong.

0 comments on commit b3a1e8b

Please sign in to comment.