Author: richard.opalka(a)jboss.com
Date: 2009-07-27 03:57:01 -0400 (Mon, 27 Jul 2009)
New Revision: 10385
Removed:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifierImpl.java
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifier.java
container/jboss50/branches/ropalka-jboss510/src/main/resources/jbossws-jboss50.deployer/META-INF/stack-agnostic-jboss-beans.xml
Log:
[JBWS-2332] refactoring + javadoc
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-27
07:50:34 UTC (rev 10384)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifier.java 2009-07-27
07:57:01 UTC (rev 10385)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -21,20 +21,178 @@
*/
package org.jboss.webservices.integration.tomcat.jse;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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.ServletMetaData;
+import org.jboss.webservices.integration.util.Helper;
+import org.jboss.wsf.common.integration.Constants;
import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Endpoint;
-// TODO: remove this
/**
- * Modifies the web app according to the stack requirements.
+ * The rewriter of jboss web meta data.
+ * It configures WS transport for every webservice endpoint
+ * plus propagates WS stack specific context parameters if requested.
*
- * @author Thomas.Diesler(a)jboss.org
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
-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";
+public final class WebMetaDataModifier
+{
- void modifyMetaData( Deployment dep );
+ /**
+ * Constructor.
+ */
+ public WebMetaDataModifier()
+ {
+ super();
+ }
+
+ /**
+ * Modifies web meta data to configure webservice stack.
+ *
+ * @param dep webservice deployment
+ */
+ public void modifyMetaData( final Deployment dep )
+ {
+ final JBossWebMetaData jbossWebMD = Helper.getRequiredAttachment( dep,
JBossWebMetaData.class );
+
+ this.propagateContextProps( dep, jbossWebMD );
+ this.configureEndpoints( dep, jbossWebMD );
+ }
+
+ /**
+ * Propagates webservice specific context parameters if requested.
+ *
+ * @param dep webservice deployment
+ * @param jbossWebMD web meta data
+ */
+ @SuppressWarnings( "unchecked" )
+ private void propagateContextProps( final Deployment dep, final JBossWebMetaData
jbossWebMD )
+ {
+ final Map< String, String > webserviceContextParams = ( Map< String,
String > )
+ dep.getProperty( Constants.STACK_CONTEXT_PARAMS );
+
+ if ( webserviceContextParams != null )
+ {
+ final List< ParamValueMetaData > contextParams = this.getContextParams(
jbossWebMD );
+
+ for ( Map.Entry< String, String > entry :
webserviceContextParams.entrySet() )
+ {
+ final ParamValueMetaData newParam = this.newParameter( entry.getKey(),
entry.getValue() );
+ contextParams.add( newParam );
+ }
+ }
+ }
+
+ /**
+ * Configures transport servlet class for every found webservice endpoint.
+ *
+ * @param dep webservice deployment
+ * @param jbossWebMD web meta data
+ */
+ private void configureEndpoints( final Deployment dep, final JBossWebMetaData
jbossWebMD )
+ {
+ final Iterator< JBossServletMetaData > servlets =
jbossWebMD.getServlets().iterator();
+
+ while ( servlets.hasNext() )
+ {
+ final ServletMetaData servletMD = servlets.next();
+ final ClassLoader loader = dep.getInitialClassLoader();
+ final boolean isWebserviceEndpoint = Helper.getEndpointClass( servletMD, loader
) != null;
+
+ if ( isWebserviceEndpoint )
+ {
+ // set transport servlet
+ servletMD.setServletClass( this.getTransportClassName( dep ) );
+
+ // configure webservice endpoint
+ final String endpointClassName = servletMD.getServletClass();
+ final List< ParamValueMetaData > initParams =
this.getServletInitParams( servletMD );
+ final ParamValueMetaData endpointParam = this.newParameter(
+ Endpoint.SEPID_DOMAIN_ENDPOINT, endpointClassName );
+
+ initParams.add( endpointParam );
+ }
+ }
+ }
+
+ /**
+ * Returns stack specific transport class name.
+ *
+ * @param dep webservice deployment
+ * @return stack specific transport class name
+ * @throws IllegalStateException if transport class name is not found in deployment
properties map
+ */
+ private String getTransportClassName( final Deployment dep )
+ {
+ final String transportClassName = ( String ) dep.getProperty(
Constants.STACK_TRANSPORT_CLASS );
+
+ if ( transportClassName == null )
+ {
+ throw new IllegalStateException( "Cannot obtain deployment property: "
+ Constants.STACK_TRANSPORT_CLASS );
+ }
+
+ return transportClassName;
+ }
+
+ /**
+ * Creates new parameter with specified key and value.
+ *
+ * @param key the key
+ * @param value the value
+ * @return new parameter
+ */
+ private ParamValueMetaData newParameter( final String key, final String value )
+ {
+ final ParamValueMetaData paramMD = new ParamValueMetaData();
+ paramMD.setParamName( key );
+ paramMD.setParamValue( value );
+
+ return paramMD;
+ }
+
+ /**
+ * Gets servlet init params list. Constructs new init params list if it does not exist
yet.
+ *
+ * @param servletMD servlet meta data
+ * @return servlet init params list
+ */
+ private List< ParamValueMetaData > getServletInitParams( final ServletMetaData
servletMD )
+ {
+ List< ParamValueMetaData > initParams = servletMD.getInitParam();
+
+ if ( initParams == null )
+ {
+ initParams = new ArrayList< ParamValueMetaData >();
+ servletMD.setInitParam( initParams );
+ }
+
+ return initParams;
+ }
+
+ /**
+ * Gets context params list. Constructs new context params list if it does not exist
yet.
+ *
+ * @param jbossWebMD web meta data
+ * @return context params list
+ */
+ private List< ParamValueMetaData > getContextParams( final JBossWebMetaData
jbossWebMD )
+ {
+ List< ParamValueMetaData > contextParams = jbossWebMD.getContextParams();
+
+ if ( contextParams == null )
+ {
+ contextParams = new ArrayList< ParamValueMetaData >();
+ jbossWebMD.setContextParams( contextParams );
+ }
+
+ return contextParams;
+ }
+
}
Deleted:
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-27
07:50:34 UTC (rev 10384)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/WebMetaDataModifierImpl.java 2009-07-27
07:57:01 UTC (rev 10385)
@@ -1,134 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.webservices.integration.tomcat.jse;
-
-import org.jboss.logging.Logger;
-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.ServletMetaData;
-import org.jboss.webservices.integration.util.Helper;
-import org.jboss.wsf.spi.deployment.Deployment;
-import org.jboss.wsf.spi.deployment.Endpoint;
-
-import javax.xml.ws.WebServiceException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 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
-{
-
- public void modifyMetaData( final Deployment dep )
- {
- final JBossWebMetaData jbossWebMD = Helper.getRequiredAttachment( dep,
JBossWebMetaData.class );
-
- propagateContextProperties( dep, jbossWebMD );
- configureWebserviceEndpoints( dep, jbossWebMD );
- }
-
- private void propagateContextProperties( final Deployment dep, final JBossWebMetaData
jbossWebMD )
- {
- Map< String, String > depCtxParams = ( Map< String, String > )
dep.getProperty( PROPERTY_WEBAPP_CONTEXT_PARAMETERS );
- if ( depCtxParams != null )
- {
- List< ParamValueMetaData > contextParams = getContextParameters(
jbossWebMD );
-
- for ( Map.Entry< String, String > entry : depCtxParams.entrySet() )
- {
- ParamValueMetaData param = newParameter( entry.getKey(), entry.getValue() );
- contextParams.add( param );
- }
- }
- }
-
- private void configureWebserviceEndpoints( final Deployment dep, final
JBossWebMetaData jbossWebMD )
- {
- for (Iterator it = jbossWebMD.getServlets().iterator(); it.hasNext();)
- {
- ServletMetaData servletMD = (ServletMetaData)it.next();
- String endpointClassName = servletMD.getServletClass();
- ClassLoader loader = dep.getInitialClassLoader();
- Class< ? > endpointClass = Helper.getEndpointClass( servletMD, loader );
- String stackEndpointServletName = getStackEndpointServletName(dep);
-
- if ( endpointClass != null )
- {
- servletMD.setServletClass(stackEndpointServletName);
- List<ParamValueMetaData> initParams = getServletInitParameters(
servletMD );
- ParamValueMetaData endpointClassParameter =
newParameter(Endpoint.SEPID_DOMAIN_ENDPOINT, endpointClassName );
- initParams.add( endpointClassParameter );
- }
- }
- }
-
- private String getStackEndpointServletName( final Deployment dep )
- {
- final String stackSpecificEndpointServlet = ( String ) dep.getProperty(
PROPERTY_WEBAPP_SERVLET_CLASS );
- if ( stackSpecificEndpointServlet == null )
- {
- throw new IllegalStateException( "Cannot obtain context property: " +
PROPERTY_WEBAPP_SERVLET_CLASS );
- }
-
- 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/resources/jbossws-jboss50.deployer/META-INF/stack-agnostic-jboss-beans.xml
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/resources/jbossws-jboss50.deployer/META-INF/stack-agnostic-jboss-beans.xml 2009-07-27
07:50:34 UTC (rev 10384)
+++
container/jboss50/branches/ropalka-jboss510/src/main/resources/jbossws-jboss50.deployer/META-INF/stack-agnostic-jboss-beans.xml 2009-07-27
07:57:01 UTC (rev 10385)
@@ -66,7 +66,7 @@
<!-- Deployment aspect helper beans -->
<bean name="WSSecurityHandlerEJB21"
class="org.jboss.webservices.integration.tomcat.ejb.SecurityHandlerEJB21"/>
<bean name="WSSecurityHandlerEJB3"
class="org.jboss.webservices.integration.tomcat.ejb.SecurityHandlerEJB3"/>
- <bean name="WSWebMetaDataModifier"
class="org.jboss.webservices.integration.tomcat.jse.WebMetaDataModifierImpl"/>
+ <bean name="WSWebMetaDataModifier"
class="org.jboss.webservices.integration.tomcat.jse.WebMetaDataModifier"/>
<!-- The AS specific deployment aspects -->
<bean name="WSContainerMetaDataDeploymentAspect"
class="org.jboss.webservices.integration.metadata.ContainerMetaDataDeploymentAspect">