Author: richard.opalka(a)jboss.com
Date: 2009-07-24 19:18:13 -0400 (Fri, 24 Jul 2009)
New Revision: 10383
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifier.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifierImpl.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/util/Helper.java
Log:
[JBWS-2332] refactoring
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifier.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifier.java 2009-07-24
15:17:53 UTC (rev 10382)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifier.java 2009-07-24
23:18:13 UTC (rev 10383)
@@ -23,6 +23,7 @@
import org.jboss.wsf.spi.deployment.Deployment;
+// TODO: remove this
/**
* Modifies the web app according to the stack requirements.
*
@@ -31,6 +32,7 @@
*/
public interface WebMetaDataModifier
{
+ // TODO: move these properties to jbossws-common and reuse them in AS integration and
in stacks
static String PROPERTY_WEBAPP_CONTEXT_PARAMETERS =
"org.jboss.ws.webapp.ContextParameterMap";
static String PROPERTY_WEBAPP_SERVLET_CLASS =
"org.jboss.ws.webapp.ServletClass";
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifierImpl.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifierImpl.java 2009-07-24
15:17:53 UTC (rev 10382)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifierImpl.java 2009-07-24
23:18:13 UTC (rev 10383)
@@ -25,7 +25,7 @@
import org.jboss.metadata.javaee.spec.ParamValueMetaData;
import org.jboss.metadata.web.jboss.JBossServletMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
-import org.jboss.metadata.web.spec.ListenerMetaData;
+import org.jboss.metadata.web.spec.ServletMetaData;
import org.jboss.webservices.integration.util.Helper;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.Endpoint;
@@ -37,141 +37,98 @@
import java.util.Map;
/**
- * The rewriter for web.xml
+ * The rewriter of web.xml metadata.
*
* @author Thomas.Diesler(a)jboss.org
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public class WebMetaDataModifierImpl implements WebMetaDataModifier
{
- // logging support
- private static Logger log = Logger.getLogger(WebMetaDataModifierImpl.class);
- public void modifyMetaData(Deployment dep)
+ public void modifyMetaData( final Deployment dep )
{
- JBossWebMetaData jbwmd = Helper.getRequiredAttachment( dep, JBossWebMetaData.class
);
+ final JBossWebMetaData jbossWebMD = Helper.getRequiredAttachment( dep,
JBossWebMetaData.class );
- try
- {
- modifyMetaData(dep, jbwmd);
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception e)
- {
- throw new WebServiceException(e);
- }
+ propagateContextProperties( dep, jbossWebMD );
+ configureWebserviceEndpoints( dep, jbossWebMD );
}
- private void modifyMetaData(Deployment dep, JBossWebMetaData jbwmd) throws
ClassNotFoundException
+ private void propagateContextProperties( final Deployment dep, final JBossWebMetaData
jbossWebMD )
{
- String servletClass = (String)dep.getProperty(PROPERTY_WEBAPP_SERVLET_CLASS);
- if (servletClass == null)
- throw new IllegalStateException("Cannot obtain context property: " +
PROPERTY_WEBAPP_SERVLET_CLASS);
-
- Map<String, String> depCtxParams = (Map<String,
String>)dep.getProperty(PROPERTY_WEBAPP_CONTEXT_PARAMETERS);
- if (depCtxParams != null)
+ Map< String, String > depCtxParams = ( Map< String, String > )
dep.getProperty( PROPERTY_WEBAPP_CONTEXT_PARAMETERS );
+ if ( depCtxParams != null )
{
- List<ParamValueMetaData> contextParams = jbwmd.getContextParams();
- if (contextParams == null)
- {
- contextParams = new ArrayList<ParamValueMetaData>();
- jbwmd.setContextParams(contextParams);
- }
+ List< ParamValueMetaData > contextParams = getContextParameters(
jbossWebMD );
- for (Map.Entry<String, String> entry : depCtxParams.entrySet())
+ for ( Map.Entry< String, String > entry : depCtxParams.entrySet() )
{
- ParamValueMetaData param = new ParamValueMetaData();
- param.setParamName(entry.getKey());
- param.setParamValue(entry.getValue());
- contextParams.add(param);
+ ParamValueMetaData param = newParameter( entry.getKey(), entry.getValue() );
+ contextParams.add( param );
}
}
-
- for (Iterator it = jbwmd.getServlets().iterator(); it.hasNext();)
+ }
+
+ private void configureWebserviceEndpoints( final Deployment dep, final
JBossWebMetaData jbossWebMD )
+ {
+ for (Iterator it = jbossWebMD.getServlets().iterator(); it.hasNext();)
{
- JBossServletMetaData servlet = (JBossServletMetaData)it.next();
- List<ParamValueMetaData> initParams = servlet.getInitParam();
- if (initParams == null)
- {
- initParams = new ArrayList<ParamValueMetaData>();
- servlet.setInitParam(initParams);
- }
-
- String linkName = servlet.getServletName();
+ ServletMetaData servletMD = (ServletMetaData)it.next();
+ String endpointClassName = servletMD.getServletClass();
+ ClassLoader loader = dep.getInitialClassLoader();
+ Class< ? > endpointClass = Helper.getEndpointClass( servletMD, loader );
+ String stackEndpointServletName = getStackEndpointServletName(dep);
- // find the servlet-class
- String orgServletClassName = servlet.getServletClass();
-
- // JSP
- if (orgServletClassName == null)
- continue;
-
- // Get the servlet class
- Class orgServletClass = null;
- try
+ if ( endpointClass != null )
{
- ClassLoader loader = dep.getInitialClassLoader();
- orgServletClass = loader.loadClass(orgServletClassName);
+ servletMD.setServletClass(stackEndpointServletName);
+ List<ParamValueMetaData> initParams = getServletInitParameters(
servletMD );
+ ParamValueMetaData endpointClassParameter =
newParameter(Endpoint.SEPID_DOMAIN_ENDPOINT, endpointClassName );
+ initParams.add( endpointClassParameter );
}
- catch (ClassNotFoundException ex)
- {
- log.warn("Cannot load servlet class: " + orgServletClassName);
- }
-
- String targetBeanName = null;
-
- // Nothing to do if we have an <init-param>
- if (isAlreadyModified(servlet))
- {
- for (ParamValueMetaData initParam : initParams)
- {
- String paramName = initParam.getParamName();
- String paramValue = initParam.getParamValue();
- if (Endpoint.SEPID_DOMAIN_ENDPOINT.equals(paramName))
- {
- targetBeanName = paramValue;
- }
- }
- }
- else
- {
- // Check if it is a real servlet that we can ignore
- if (orgServletClass != null &&
javax.servlet.Servlet.class.isAssignableFrom(orgServletClass))
- {
- log.info("Ignore servlet: " + orgServletClassName);
- continue;
- }
-
- servlet.setServletClass(servletClass);
-
- // add additional init params
- if (orgServletClassName.equals(servletClass) == false)
- {
- targetBeanName = orgServletClassName;
- ParamValueMetaData initParam = new ParamValueMetaData();
- initParam.setParamName(Endpoint.SEPID_DOMAIN_ENDPOINT);
- initParam.setParamValue(targetBeanName);
- initParams.add(initParam);
- }
- }
-
- if (targetBeanName == null)
- throw new IllegalStateException("Cannot obtain service endpoint bean
for: " + linkName);
}
}
-
- // Return true if the web.xml is already modified
- private boolean isAlreadyModified(JBossServletMetaData servlet)
+
+ private String getStackEndpointServletName( final Deployment dep )
{
- for (ParamValueMetaData initParam : servlet.getInitParam())
+ final String stackSpecificEndpointServlet = ( String ) dep.getProperty(
PROPERTY_WEBAPP_SERVLET_CLASS );
+ if ( stackSpecificEndpointServlet == null )
{
- String paramName = initParam.getParamName();
- if (Endpoint.SEPID_DOMAIN_ENDPOINT.equals(paramName))
- return true;
+ throw new IllegalStateException( "Cannot obtain context property: " +
PROPERTY_WEBAPP_SERVLET_CLASS );
}
- return false;
+
+ return stackSpecificEndpointServlet;
}
+
+ private ParamValueMetaData newParameter( final String key, final String value )
+ {
+ ParamValueMetaData paramMD = new ParamValueMetaData();
+ paramMD.setParamName( key );
+ paramMD.setParamValue( value );
+ return paramMD;
+ }
+
+ private List< ParamValueMetaData > getServletInitParameters( final
ServletMetaData servletMD )
+ {
+ List< ParamValueMetaData > initParams = servletMD.getInitParam();
+ if (initParams == null)
+ {
+ initParams = new ArrayList< ParamValueMetaData >();
+ servletMD.setInitParam(initParams);
+ }
+
+ return initParams;
+ }
+
+ private List< ParamValueMetaData > getContextParameters( final JBossWebMetaData
jbossWebMD )
+ {
+ List< ParamValueMetaData > contextParams = jbossWebMD.getContextParams();
+ if (contextParams == null)
+ {
+ contextParams = new ArrayList< ParamValueMetaData >();
+ jbossWebMD.setContextParams( contextParams );
+ }
+
+ return contextParams;
+ }
+
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/util/Helper.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/util/Helper.java 2009-07-24
15:17:53 UTC (rev 10382)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/util/Helper.java 2009-07-24
23:18:13 UTC (rev 10383)
@@ -287,7 +287,7 @@
try
{
final Class< ? > endpointClass = loader.loadClass( endpointClassName
);
- final boolean notServlet = !endpointClass.isAssignableFrom( Servlet.class );
+ final boolean notServlet = !Servlet.class.isAssignableFrom( endpointClass );
if ( notServlet )
{
Show replies by date