This class will implement an interface that is defined by the
MDQ code. It will be registered within the MDQ framework, and the
MDQ code will call this when it finds an application that was
deployed without WSDL. This class will use the WsGen tool to
generate a WSDL Definition based on the Java source for the application.
| Method from org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator Detail: |
public static String expandDirs(String dirPaths) {
StringTokenizer st = new StringTokenizer(dirPaths, File.pathSeparator);
StringBuffer buffer = new StringBuffer();
while (st.hasMoreTokens()) {
String d = st.nextToken();
File dir = new File(d);
if (dir.isDirectory()) {
File[] files = dir.listFiles(new JavaArchiveFilter());
for (int i = 0; i < files.length; i++) {
buffer.append(files[i]).append(File.pathSeparator);
}
}
}
return buffer.toString();
}
Expand a directory path or list of directory paths (File.pathSeparator
delimited) into a list of file paths of all the jar files in those
directories. |
public void generateWsdl(String className,
String bindingType) throws WebServiceException {
generateWsdl(className, bindingType, null);
}
This method will drive the call to WsGen to generate a WSDL file for
applications deployed without WSDL. We will then read this file in from
disk and create a Definition. After we are done with the file we will
remove it from disk. |
public void generateWsdl(String className,
String bindingType,
JAXWSCatalogManager catalogManager) throws WebServiceException {
AxisConfiguration axisConfiguration = axisService.getAxisConfiguration();
File tempFile = (File) axisConfiguration.getParameterValue(
Constants.Configuration.ARTIFACTS_TEMP_DIR);
if (tempFile == null) {
tempFile = new File(getProperty_doPriv("java.io.tmpdir"), "_axis2");
}
Parameter servletConfigParam = axisConfiguration
.getParameter(HTTPConstants.HTTP_SERVLETCONFIG);
String webBase = null;
if (servletConfigParam != null) {
Object obj = servletConfigParam.getValue();
ServletContext servletContext;
if (obj instanceof ServletConfig) {
ServletConfig servletConfig = (ServletConfig) obj;
servletContext = servletConfig.getServletContext();
webBase = servletContext.getRealPath("/WEB-INF");
}
}
if(classPath == null) {
this.classPath = getDefaultClasspath(webBase);
}
if (log.isDebugEnabled()) {
log.debug("For implementation class " + className +
" WsGen classpath: " +
classPath);
}
String localOutputDirectory = tempFile.getAbsolutePath() + className;
if (log.isDebugEnabled()) {
log.debug("Output directory for generated WSDL file: " + localOutputDirectory);
}
boolean errorOnRead = false;
try {
if (log.isDebugEnabled()) {
log.debug("Generating new WSDL Definition");
}
createOutputDirectory(localOutputDirectory);
Class clazz;
try {
// Try the one in JDK16
clazz = Class.forName("com.sun.tools.internal.ws.spi.WSToolsObjectFactory");
} catch (Throwable t){
// Look for the RI
clazz = Class.forName("com.sun.tools.ws.spi.WSToolsObjectFactory");
}
Method m1 = clazz.getMethod("newInstance", new Class[]{});
Object factory = m1.invoke(new Object[]{});
String[] arguments = getWsGenArguments(className, bindingType, localOutputDirectory);
OutputStream os = new ByteArrayOutputStream();
Method m2 = clazz.getMethod("wsgen", new Class[]{OutputStream.class, String[].class});
m2.invoke(factory, os, arguments);
os.close();
wsdlDefMap = readInWSDL(localOutputDirectory);
if (wsdlDefMap.isEmpty()) {
throw new Exception("A WSDL Definition could not be generated for " +
"the implementation class: " + className);
}
docMap = readInSchema(localOutputDirectory, catalogManager);
}
catch (Throwable t) {
String msg =
"Error occurred generating WSDL file for Web service implementation class " +
"{" + className + "}: {" + t + "}";
log.error(msg, t);
throw new WebServiceException(msg, t);
}
}
This method will drive the call to WsGen to generate a WSDL file for
applications deployed without WSDL. We will then read this file in from
disk and create a Definition. After we are done with the file we will
remove it from disk. This method accepts a CatalogManager as a parameter
for the eventual use in by an XMLSchemaCollection. |
public static JAXWSCatalogManager getCatalogManager(AxisService service) {
Parameter param = service.getParameter(EndpointDescription.AXIS_SERVICE_PARAMETER);
if (param != null) {
EndpointDescription ed = (EndpointDescription)param.getValue();
return ed.getServiceDescription().getCatalogManager();
} else
return new OASISCatalogManager();
}
Get the CatalogManager associated with an AxisService |
public String getDefaultClasspath(String webBase) {
HashSet classpath = new HashSet();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
fillClassPath(cl, classpath);
// Just to be safe (the above doesn't seem to return the webapp
// classpath in all cases), manually do this:
if (webBase != null) {
addPath(classpath, webBase + File.separatorChar + "classes");
try {
String libBase = webBase + File.separatorChar + "lib";
File libDir = new File(libBase);
String[] jarFiles = libDir.list();
for (int i = 0; i < jarFiles.length; i++) {
String jarFile = jarFiles[i];
if (jarFile.endsWith(".jar")) {
addPath(classpath, libBase +
File.separatorChar +
jarFile);
}
}
} catch (Exception e) {
// Oh well. No big deal.
}
}
URL serviceArchive = axisService.getFileName();
if(serviceArchive != null) {
try {
classpath.add(Utils.toFile(serviceArchive).getCanonicalPath());
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage(), e);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
// axis.ext.dirs can be used in any appserver
getClassPathFromDirectoryProperty(classpath, "axis.ext.dirs");
// classpath used by Jasper
getClassPathFromProperty(classpath, "org.apache.catalina.jsp_classpath");
// websphere stuff.
getClassPathFromProperty(classpath, "ws.ext.dirs");
getClassPathFromProperty(classpath, "com.ibm.websphere.servlet.application.classpath");
// java class path
getClassPathFromProperty(classpath, "java.class.path");
// Load jars from java external directory
getClassPathFromDirectoryProperty(classpath, "java.ext.dirs");
// boot classpath isn't found in above search
getClassPathFromProperty(classpath, "sun.boot.class.path");
StringBuffer path = new StringBuffer();
for (Iterator iterator = classpath.iterator(); iterator.hasNext();) {
String s = (String) iterator.next();
path.append(s);
path.append(File.pathSeparatorChar);
}
log.debug(path);
return path.toString();
}
Get the default classpath from various thingies in the message context |
public XmlSchema getSchema(AxisService service,
String xsd) throws AxisFault {
Parameter wsdlParameter = service.getParameter(WSDLConstants.WSDL_4_J_DEFINITION);
if (wsdlParameter != null) {
ArrayList list = service.getSchema();
if (list.size() > 0) {
if (xsd == null || xsd.length() == 0) {
return (XmlSchema) list.get(0);
}
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
XmlSchema schema = (XmlSchema) iterator.next();
XmlSchema[] schemas = SchemaUtil.getAllSchemas(schema);
for (int i = 0; i < schemas.length; i++) {
String uri = schemas[i].getSourceURI();
if (uri != null && uri.endsWith(xsd)) {
return schemas[i];
}
}
}
return (XmlSchema) list.get(0);
}
}
initialize(service);
XmlSchema schema = docMap.get(xsd);
if (schema == null) {
docMap.values().iterator().next();
}
return schema;
}
|
public Definition getWSDL(AxisService service) throws AxisFault {
Parameter wsdlParameter = service.getParameter(WSDLConstants.WSDL_4_J_DEFINITION);
if (wsdlParameter != null) {
Object value = wsdlParameter.getValue();
if (value != null) {
return (Definition) value;
}
}
initialize(service);
return wsdlDefMap.values().iterator().next();
}
|
public static boolean isJar(InputStream is) {
try {
JarInputStream jis = new JarInputStream(is);
if (jis.getNextEntry() != null) {
return true;
}
} catch (IOException ioe) {
}
return false;
}
Check if this inputstream is a jar/zip |