You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2006/04/26 15:48:15 UTC
svn commit: r397196 -
/incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/handler/WebServiceEntryPointServlet.java
Author: jboynes
Date: Wed Apr 26 06:48:13 2006
New Revision: 397196
URL: http://svn.apache.org/viewcvs?rev=397196&view=rev
Log:
cleanup of servlet code
Modified:
incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/handler/WebServiceEntryPointServlet.java
Modified: incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/handler/WebServiceEntryPointServlet.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/handler/WebServiceEntryPointServlet.java?rev=397196&r1=397195&r2=397196&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/handler/WebServiceEntryPointServlet.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/handler/WebServiceEntryPointServlet.java Wed Apr 26 06:48:13 2006
@@ -22,8 +22,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.Iterator;
-
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -44,8 +42,6 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.transport.http.AxisServlet;
import org.apache.tuscany.binding.axis2.assembly.WebServiceBinding;
-import org.apache.tuscany.common.resource.ResourceLoader;
-import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
import org.apache.tuscany.core.context.CompositeContext;
import org.apache.tuscany.core.context.Context;
import org.apache.tuscany.core.context.EntryPointContext;
@@ -57,18 +53,9 @@
* @version $Rev: 383148 $ $Date: 2006-03-04 08:07:17 -0800 (Sat, 04 Mar 2006) $
*/
public class WebServiceEntryPointServlet extends AxisServlet {
-
private static final long serialVersionUID = -2085869393709833372L;
- private boolean tuscanyGetDefaultAxis2xmlChecked;
-
-
- // private static final String CONFIGURATION_CONTEXT = "CONFIGURATION_CONTEXT";
-
- // public static final String SESSION_ID = "SessionId";
-
- // private ConfigurationContext configContext;
-
- // private AxisConfiguration axisConfiguration;
+ private static final String MODULE_COMPONENT_NAME = "org.apache.tuscany.core.webapp.ModuleComponentContext";
+ private boolean tuscanyGetDefaultAxis2xmlChecked;
public void init(ServletConfig config) throws ServletException {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
@@ -90,84 +77,68 @@
}
}
}
+
@SuppressWarnings("deprecation")
- private void initTuscany(final AxisConfiguration axisConfig,
- ServletConfig config)
- throws AxisFault, ServletException {
+ private void initTuscany(final AxisConfiguration axisConfig, ServletConfig config) throws AxisFault {
// Get the current SCA module context
-
ServletContext servletContext = config.getServletContext();
-
- CompositeContext moduleContext = (CompositeContext)servletContext
- .getAttribute("org.apache.tuscany.core.webapp.ModuleComponentContext");
+
+ CompositeContext moduleContext = (CompositeContext) servletContext.getAttribute(MODULE_COMPONENT_NAME);
Module module = (Module) moduleContext.getComposite();
-
- for (Iterator<EntryPoint> i = module.getEntryPoints().iterator(); i.hasNext();) {
- EntryPoint entryPoint = i.next();
+ for (EntryPoint entryPoint : module.getEntryPoints()) {
final String epName = entryPoint.getName();
Context entryPointContext = moduleContext.getContext(epName);
Binding binding = entryPoint.getBindings().get(0);
- if (binding instanceof WebServiceBinding) {
+ if (!(binding instanceof WebServiceBinding)) {
+ continue;
+ }
- WebServiceBinding wsBinding = (WebServiceBinding) binding;
- Definition definition = wsBinding.getWSDLDefinition();
- Port port = wsBinding.getWSDLPort();
- QName qname = new QName(definition.getTargetNamespace(), port.getName());
+ WebServiceBinding wsBinding = (WebServiceBinding) binding;
+ Definition definition = wsBinding.getWSDLDefinition();
+ Port port = wsBinding.getWSDLPort();
+ QName qname = new QName(definition.getTargetNamespace(), port.getName());
- WebServicePortMetaData wsdlPortInfo = new WebServicePortMetaData(definition, port, null,
- false);
+ WebServicePortMetaData wsdlPortInfo = new WebServicePortMetaData(definition, port, null, false);
- WebServiceEntryPointInOutSyncMessageReceiver msgrec
+ WebServiceEntryPointInOutSyncMessageReceiver msgrec
= new WebServiceEntryPointInOutSyncMessageReceiver((EntryPointContext) entryPointContext,
- wsdlPortInfo,
- wsBinding.getTypeHelper(),
- wsBinding.getResourceLoader().getClassLoader());
-
- AxisServiceGroup serviceGroup = new AxisServiceGroup(axisConfig);
- axisConfig.addMessageReceiver(WebServiceEntryPointInOutSyncMessageReceiver.MEP_URL, msgrec);
- serviceGroup.setServiceGroupName(wsdlPortInfo.getServiceName().getLocalPart());
-
- // to create service from wsdl stream --->
- // AxisServiceBuilder axisServiceBuilder = new AxisServiceBuilder();
- // return axisServiceBuilder.getAxisService(in);
-
- AxisService axisService = new AxisService(epName);
- axisService.setParent(serviceGroup);
- axisService.setWSDLDefinition(definition);
- axisService.setServiceDescription("Tuscany configured service EntryPoint name '"
- + epName + '\'');
- axisService.addMessageReceiver(WebServiceEntryPointInOutSyncMessageReceiver.MEP_URL,
- msgrec);
-
- // Create operation descriptions for all the operations
- PortType wsdlPortType = wsdlPortInfo.getPortType();
- for (Iterator<?> j = wsdlPortType.getOperations().iterator(); j.hasNext();) {
- Operation wsdlOperation = (Operation)j.next();
- String operationName = wsdlOperation.getName();
- QName name = new QName(qname.getNamespaceURI(), operationName);
- AxisOperation axisOp = new InOutAxisOperation(name);
- axisOp.setMessageReceiver(msgrec);
- axisService.addOperation(axisOp);
- axisOp.setMessageExchangePattern(WebServiceEntryPointInOutSyncMessageReceiver.MEP_URL);
-
-
-
- }
- axisConfig.addService(axisService);
- axisConfig.addServiceGroup(serviceGroup);
+ wsdlPortInfo,
+ wsBinding.getTypeHelper(),
+ wsBinding.getResourceLoader().getClassLoader());
+
+ AxisServiceGroup serviceGroup = new AxisServiceGroup(axisConfig);
+ axisConfig.addMessageReceiver(WebServiceEntryPointInOutSyncMessageReceiver.MEP_URL, msgrec);
+ serviceGroup.setServiceGroupName(wsdlPortInfo.getServiceName().getLocalPart());
+
+ AxisService axisService = new AxisService(epName);
+ axisService.setParent(serviceGroup);
+ axisService.setWSDLDefinition(definition);
+ axisService.setServiceDescription("Tuscany configured service EntryPoint name '" + epName + '\'');
+ axisService.addMessageReceiver(WebServiceEntryPointInOutSyncMessageReceiver.MEP_URL, msgrec);
+
+ // Create operation descriptions for all the operations
+ PortType wsdlPortType = wsdlPortInfo.getPortType();
+ for (Object o : wsdlPortType.getOperations()) {
+ Operation wsdlOperation = (Operation) o;
+ String operationName = wsdlOperation.getName();
+ QName name = new QName(qname.getNamespaceURI(), operationName);
+ AxisOperation axisOp = new InOutAxisOperation(name);
+ axisOp.setMessageReceiver(msgrec);
+ axisService.addOperation(axisOp);
+ axisOp.setMessageExchangePattern(WebServiceEntryPointInOutSyncMessageReceiver.MEP_URL);
}
+ axisConfig.addService(axisService);
+ axisConfig.addServiceGroup(serviceGroup);
}
}
@SuppressWarnings("deprecation")
- protected synchronized void tuscanyGetDefaultAxis2xml(ServletConfig config)
- throws ServletException {
-
+ protected synchronized void tuscanyGetDefaultAxis2xml(ServletConfig config) throws IOException {
if (tuscanyGetDefaultAxis2xmlChecked) {
// already checked.
return;
@@ -175,54 +146,46 @@
tuscanyGetDefaultAxis2xmlChecked = true;
ServletContext context = config.getServletContext();
String repoDir = context.getRealPath("/WEB-INF");
- String axis2config = repoDir + "/" + DeploymentConstants.DIRECTORY_CONF
- + "/" + DeploymentConstants.AXIS2_CONFIGURATION_XML;
-
+ String axis2config = repoDir +
+ "/" + DeploymentConstants.DIRECTORY_CONF +
+ "/" + DeploymentConstants.AXIS2_CONFIGURATION_XML;
+
File axis2xmlFile = new File(axis2config);
constructSubDirectories(axis2xmlFile.getParentFile());
if (axis2xmlFile.exists()) {
// do nothing if there.
return;
}
-
- CompositeContext moduleContext = (CompositeContext)config.getServletContext()
- .getAttribute("org.apache.tuscany.core.webapp.ModuleComponentContext");
- Module module = (Module) moduleContext.getComposite();
-
-
- ResourceLoader resourceLoader = new ResourceLoaderImpl(module.getClass().getClassLoader());
+ URL url = getClass().getResource("/org/apache/tuscany/binding/axis2/engine/config/axis2.xml");
+ InputStream defaultAxis2xml = url.openStream();
try {
-
- URL url = resourceLoader.getResource("org/apache/tuscany/binding/axis2/engine/config/axis2.xml");
- InputStream defaultAxis2xml = url.openStream();
FileOutputStream out = new FileOutputStream(axis2xmlFile);
- byte[] buff = new byte[1024];
- for (int len = -1; (len = defaultAxis2xml.read(buff)) > 0;) {
- out.write(buff, 0, len);
+ try {
+ byte[] buff = new byte[1024];
+ for (int len; (len = defaultAxis2xml.read(buff)) > 0;) {
+ out.write(buff, 0, len);
+ }
+ } finally {
+ out.close();
}
-
+ } finally {
defaultAxis2xml.close();
- out.close();
-
- } catch (IOException e1) {
- throw new ServletException(e1);
}
-
}
+
protected void constructSubDirectories(File in) {
if (in.exists()) {
return;
}
constructSubDirectories(in.getParentFile());
in.mkdir();
-
}
+
@Override
- protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
- throws ServletException, IOException {
-
+ protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
+
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
ClassLoader mycl = getClass().getClassLoader();
try {
@@ -238,14 +201,10 @@
Thread.currentThread().setContextClassLoader(tccl);
}
}
-
-
}
+
@Override
- protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
- throws ServletException, IOException {
-
-
+ protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
ClassLoader mycl = getClass().getClassLoader();
try {
@@ -261,7 +220,5 @@
Thread.currentThread().setContextClassLoader(tccl);
}
}
-
}
-
}