You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ve...@apache.org on 2010/01/23 21:31:53 UTC
svn commit: r902481 - in /webservices/axis2/trunk/java/modules:
jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java
kernel/src/org/apache/axis2/deployment/POJODeployer.java
kernel/src/org/apache/axis2/deployment/util/Utils.java
Author: veithen
Date: Sat Jan 23 20:31:52 2010
New Revision: 902481
URL: http://svn.apache.org/viewvc?rev=902481&view=rev
Log:
Eliminated some duplicate code and resolved AXIS2-4326.
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java?rev=902481&r1=902480&r2=902481&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java Sat Jan 23 20:31:52 2010
@@ -25,7 +25,6 @@
import org.apache.axis2.deployment.Deployer;
import org.apache.axis2.deployment.DeploymentEngine;
import org.apache.axis2.deployment.DeploymentErrorMsgs;
-import org.apache.axis2.deployment.DeploymentException;
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
import org.apache.axis2.deployment.util.Utils;
import org.apache.axis2.description.AxisOperation;
@@ -59,8 +58,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.jar.JarInputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
/*
* JAXWSDeployer is a custom deployer modeled after the POJODeployer. Its purpose
@@ -157,7 +154,7 @@
axisConfig.isChildFirstClassLoading());
Thread.currentThread().setContextClassLoader(classLoader);
- ArrayList<String> classList = getListOfClasses(deploymentFileData);
+ List<String> classList = Utils.getListOfClasses(deploymentFileData);
AxisServiceGroup serviceGroup = deployClasses(groupName, location, classLoader, classList);
if(serviceGroup == null) {
@@ -230,39 +227,6 @@
return serviceGroup;
}
- protected ArrayList<String> getListOfClasses(DeploymentFileData deploymentFileData) throws IOException {
- ArrayList<String> classList;
- FileInputStream fin = null;
- ZipInputStream zin = null;
- try {
- fin = new FileInputStream(deploymentFileData.getAbsolutePath());
- zin = new ZipInputStream(fin);
- ZipEntry entry;
- classList = new ArrayList<String>();
- while ((entry = zin.getNextEntry()) != null) {
- String name = entry.getName();
- if (name.endsWith(".class")) {
- name = name.replaceAll(".class", "");
- name = name.replaceAll("/", ".");
- classList.add(name);
- }
- }
- zin.close();
- fin.close();
- } catch (Exception e) {
- log.debug(Messages.getMessage("deployingexception", e.getMessage()), e);
- throw new DeploymentException(e);
- } finally {
- if (zin != null) {
- zin.close();
- }
- if (fin != null) {
- fin.close();
- }
- }
- return classList;
- }
-
protected void storeFaultyService(DeploymentFileData deploymentFileData, Throwable t) {
StringWriter errorWriter = new StringWriter();
PrintWriter ptintWriter = new PrintWriter(errorWriter);
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java?rev=902481&r1=902480&r2=902481&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java Sat Jan 23 20:31:52 2010
@@ -37,7 +37,6 @@
import org.apache.commons.logging.LogFactory;
import java.io.File;
-import java.io.FileInputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
@@ -45,8 +44,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
+import java.util.List;
public class POJODeployer implements Deployer {
@@ -81,8 +79,7 @@
configCtx.getAxisConfiguration().isChildFirstClassLoading());
Thread.currentThread().setContextClassLoader(classLoader);
- String className = file.getName();
- className = className.replaceAll(".class", "");
+ String className = Utils.getClassNameFromResourceName(file.getName());
Class<?> clazz = Loader.loadClass(className);
log.info(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_POJO,
serviceHierarchy + className,
@@ -118,33 +115,7 @@
configCtx.getAxisConfiguration().addService(axisService);
} else if ("jar".equals(extension)) {
- ArrayList<String> classList;
- FileInputStream fin = null;
- ZipInputStream zin = null;
- try {
- fin = new FileInputStream(deploymentFileData.getAbsolutePath());
- zin = new ZipInputStream(fin);
- ZipEntry entry;
- classList = new ArrayList<String>();
- while ((entry = zin.getNextEntry()) != null) {
- String name = entry.getName();
- if (name.endsWith(".class")) {
- classList.add(name);
- }
- }
- zin.close();
- fin.close();
- } catch (Exception e) {
- log.debug(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_EXCEPTION,e.getMessage()),e);
- throw new DeploymentException(e);
- } finally {
- if (zin != null) {
- zin.close();
- }
- if (fin != null) {
- fin.close();
- }
- }
+ List<String> classList = Utils.getListOfClasses(deploymentFileData);
ArrayList<AxisService> axisServiceList = new ArrayList<AxisService>();
for (String className : classList) {
ArrayList<URL> urls = new ArrayList<URL>();
@@ -162,8 +133,6 @@
getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR),
configCtx.getAxisConfiguration().isChildFirstClassLoading());
Thread.currentThread().setContextClassLoader(classLoader);
- className = className.replaceAll(".class", "");
- className = className.replaceAll("/", ".");
Class<?> clazz = Loader.loadClass(className);
/**
@@ -357,7 +326,7 @@
fileName = Utils.getShortFileName(fileName);
if (fileName.endsWith(".class")) {
- String className = fileName.replaceAll(".class", "");
+ String className = Utils.getClassNameFromResourceName(fileName);
className = serviceHierarchy + className;
try {
AxisServiceGroup serviceGroup =
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java?rev=902481&r1=902480&r2=902481&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java Sat Jan 23 20:31:52 2010
@@ -31,6 +31,7 @@
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.deployment.DeploymentClassLoader;
import org.apache.axis2.deployment.DeploymentConstants;
+import org.apache.axis2.deployment.DeploymentErrorMsgs;
import org.apache.axis2.deployment.DeploymentException;
import org.apache.axis2.deployment.repository.util.ArchiveReader;
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
@@ -42,6 +43,7 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.Handler;
import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.i18n.Messages;
import org.apache.axis2.jsr181.JSR181Helper;
import org.apache.axis2.jsr181.WebMethodAnnotation;
import org.apache.axis2.jsr181.WebServiceAnnotation;
@@ -1950,4 +1952,53 @@
}
return serviceHierarchy;
}
+
+ /**
+ * Get the class name from a resource name referring to a class file.
+ *
+ * @param resourceName the resource name
+ * @return the class name
+ */
+ public static String getClassNameFromResourceName(String resourceName) {
+ if (!resourceName.endsWith(".class")) {
+ throw new IllegalArgumentException("The resource name doesn't refer to a class file");
+ }
+ return resourceName.substring(0, resourceName.length()-6).replace('/', '.');
+ }
+
+ /**
+ * Scan a JAR file and return the list of classes contained in the JAR.
+ *
+ * @param deploymentFileData
+ * the JAR to scan
+ * @return a list of Java class names
+ * @throws DeploymentException
+ * if an error occurs while scanning the file
+ */
+ public static List<String> getListOfClasses(DeploymentFileData deploymentFileData) throws DeploymentException {
+ try {
+ FileInputStream fin = new FileInputStream(deploymentFileData.getAbsolutePath());
+ try {
+ ZipInputStream zin = new ZipInputStream(fin);
+ try {
+ ZipEntry entry;
+ List<String> classList = new ArrayList<String>();
+ while ((entry = zin.getNextEntry()) != null) {
+ String name = entry.getName();
+ if (name.endsWith(".class")) {
+ classList.add(getClassNameFromResourceName(name));
+ }
+ }
+ return classList;
+ } finally {
+ zin.close();
+ }
+ } finally {
+ fin.close();
+ }
+ } catch (IOException e) {
+ log.debug(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_EXCEPTION, e.getMessage()), e);
+ throw new DeploymentException(e);
+ }
+ }
}