Author: klape
Date: 2012-07-19 11:48:22 -0400 (Thu, 19 Jul 2012)
New Revision: 16504
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/metadata/wsdl/xsd/SchemaUtils.java
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java
Log:
[JBPAPP-9520] Change temporary WSDL and XSD file names in JBossWS
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2012-07-19
14:20:47 UTC (rev 16503)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2012-07-19
15:48:22 UTC (rev 16504)
@@ -26,6 +26,9 @@
import java.io.PrintStream;
import java.io.Writer;
import java.net.URL;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.math.BigInteger;
import javax.jws.HandlerChain;
import javax.jws.WebService;
@@ -398,10 +401,11 @@
}
}
- private void writeWsdl(ServiceMetaData serviceMetaData, WSDLDefinitions
wsdlDefinitions, EndpointMetaData epMetaData) throws IOException
+ private void writeWsdl(final ServiceMetaData serviceMetaData, WSDLDefinitions
wsdlDefinitions, EndpointMetaData epMetaData) throws IOException
{
// The RI uses upper case, and the TCK expects it, so we just mimic this even
though we don't really have to
String wsdlName =
ToolsUtils.firstLetterUpperCase(serviceMetaData.getServiceName().getLocalPart());
+
// Ensure that types are only in the interface qname
wsdlDefinitions.getWsdlTypes().setNamespace(epMetaData.getPortTypeName().getNamespaceURI());
@@ -415,8 +419,7 @@
else
{
dir = IOUtils.createTempDirectory();
- wsdlFile = File.createTempFile(wsdlName, ".wsdl", dir);
- wsdlFile.deleteOnExit();
+ wsdlFile = computeTempWsdlFile(serviceMetaData, dir, wsdlName);
}
message(wsdlFile.getName());
@@ -431,8 +434,7 @@
}
else
{
- file = File.createTempFile(suggestedFile, ".wsdl", dir);
- file.deleteOnExit();
+ file = computeTempWsdlFile(serviceMetaData, dir, suggestedFile);
}
actualFile = file.getName();
message(actualFile);
@@ -446,6 +448,35 @@
serviceMetaData.setWsdlLocation(wsdlFile.toURL());
}
+ private File computeTempWsdlFile(ServiceMetaData serviceMetaData, File dir, String
wsdlName) throws IOException
+ {
+ File wsdlFile = null;
+ try
+ {
+ byte[] deploymentName =
serviceMetaData.getUnifiedMetaData().getDeploymentName().getBytes("UTF-8");
+ String deploymentNameHash =
toHexString(MessageDigest.getInstance("MD5").digest(deploymentName));
+ wsdlFile = new File(dir + File.separator + wsdlName + "_" +
deploymentNameHash + ".wsdl");
+ }
+ catch(NoSuchAlgorithmException ex)
+ {
+ if(log.isTraceEnabled())
+ log.trace("MD5 has of deployment name failed for WSDL file name.
Falling back to File.createTempFile()", ex);
+ else
+ log.debug("MD5 has of deployment name failed for WSDL file name.
Falling back to File.createTempFile()");
+
+ wsdlFile = File.createTempFile(wsdlName, ".wsdl", dir);
+ }
+
+ wsdlFile.deleteOnExit();
+ return wsdlFile;
+ }
+
+ private String toHexString(byte[] hash)
+ {
+ BigInteger bi = new BigInteger(1, hash);
+ return String.format("%0" + (hash.length << 1) + "x",
bi);
+ }
+
private void message(String msg)
{
if (messageStream != null)
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/metadata/wsdl/xsd/SchemaUtils.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/metadata/wsdl/xsd/SchemaUtils.java 2012-07-19
14:20:47 UTC (rev 16503)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/metadata/wsdl/xsd/SchemaUtils.java 2012-07-19
15:48:22 UTC (rev 16504)
@@ -27,6 +27,11 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.math.BigInteger;
import javax.xml.namespace.QName;
@@ -508,7 +513,7 @@
/** Get the temp file for a given namespace
*/
- public static File getSchemaTempFile(String targetNS) throws IOException
+ public static File getSchemaTempFile(String targetNS, String fileName) throws
IOException
{
if (targetNS.length() == 0)
throw new IllegalArgumentException("Invalid null target namespace");
@@ -521,7 +526,8 @@
try
{
SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
- ServerConfig serverConfig =
spiProvider.getSPI(ServerConfigFactory.class).getServerConfig();File tmpDir =
serverConfig.getServerTempDir();
+ ServerConfig serverConfig =
spiProvider.getSPI(ServerConfigFactory.class).getServerConfig();
+ File tmpDir = serverConfig.getServerTempDir();
tmpdir = serverConfig.getServerTempDir();
tmpdir = new File(tmpdir.getCanonicalPath() + "/jbossws");
tmpdir.mkdirs();
@@ -537,9 +543,35 @@
fname = fname.replace('?', '_');
fname = fname.replace('#', '_');
- return File.createTempFile("JBossWS_" + fname, ".xsd",
tmpdir);
+ File file = null;
+ try
+ {
+ String fileNameHash =
toHexString(MessageDigest.getInstance("MD5").digest(fileName.getBytes("UTF-8")));
+ if(tmpdir == null)
+ {
+ tmpdir = (File) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run()
+ {
+ return new File(System.getProperty("java.io.tmpdir"));
+ }
+ });
+ }
+ file = new File(tmpdir + File.separator + "JBossWS_" + fname +
"_" + fileNameHash + ".xsd");
+ }
+ catch(NoSuchAlgorithmException noAlgEx)
+ {
+ file = File.createTempFile("JBossWS_" + fname, ".xsd",
tmpdir);
+ }
+
+ return file;
}
+ private static String toHexString(byte[] hash)
+ {
+ BigInteger bi = new BigInteger(1, hash);
+ return String.format("%0" + (hash.length << 1) + "x",
bi);
+ }
+
/**
* Get the TargetNamespace from the schema model
*/
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java 2012-07-19
14:20:47 UTC (rev 16503)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java 2012-07-19
15:48:22 UTC (rev 16504)
@@ -544,14 +544,14 @@
{
log.trace("processSchemaInclude: [targetNS=" + targetNS +
",parentURL=" + wsdlLoc + "]");
- tmpFile = SchemaUtils.getSchemaTempFile(targetNS);
+ tmpFile = SchemaUtils.getSchemaTempFile(targetNS, getFileName(wsdlLoc));
tempFiles.add(tmpFile);
publishedLocations.put(wsdlLoc, tmpFile.toURL());
}
else
{
- tmpFile = SchemaUtils.getSchemaTempFile("no_namespace");
+ tmpFile = SchemaUtils.getSchemaTempFile("no_namespace",
getFileName(wsdlLoc));
tempFiles.add(tmpFile);
publishedLocations.put(wsdlLoc, tmpFile.toURL());
@@ -600,6 +600,22 @@
handleSchemaImports(schemaEl, wsdlLoc);
}
+ private String getFileName(URL url)
+ {
+ String query = url.getQuery();
+ if(query != null)
+ {
+ if(query.contains("="))
+ {
+ return query.split("=")[1];
+ }
+ }
+
+ String exUrl = url.toExternalForm();
+ String[] paths = exUrl.split("/");
+ return paths[paths.length-1];
+ }
+
private void handleSchemaImports(Element schemaEl, URL parentURL) throws
WSDLException, IOException
{
if (parentURL == null)