|
Lines 16-24
Link Here
|
| 16 |
|
16 |
|
| 17 |
package org.eclipse.gemini.web.internal.url; |
17 |
package org.eclipse.gemini.web.internal.url; |
| 18 |
|
18 |
|
|
|
19 |
import java.io.File; |
| 20 |
import java.io.FileOutputStream; |
| 19 |
import java.io.IOException; |
21 |
import java.io.IOException; |
| 20 |
import java.io.InputStream; |
22 |
import java.io.InputStream; |
| 21 |
import java.io.InputStreamReader; |
23 |
import java.io.InputStreamReader; |
|
|
24 |
import java.io.OutputStream; |
| 22 |
import java.net.URL; |
25 |
import java.net.URL; |
| 23 |
import java.net.URLConnection; |
26 |
import java.net.URLConnection; |
| 24 |
import java.util.Dictionary; |
27 |
import java.util.Dictionary; |
|
Lines 36-44
import org.osgi.service.url.URLStreamHandlerService;
Link Here
|
| 36 |
import org.eclipse.gemini.web.core.InstallationOptions; |
39 |
import org.eclipse.gemini.web.core.InstallationOptions; |
| 37 |
import org.eclipse.gemini.web.core.WebBundleManifestTransformer; |
40 |
import org.eclipse.gemini.web.core.WebBundleManifestTransformer; |
| 38 |
import org.eclipse.gemini.web.internal.WebContainerUtils; |
41 |
import org.eclipse.gemini.web.internal.WebContainerUtils; |
|
|
42 |
import org.eclipse.gemini.web.internal.url.DirTransformer.DirTransformerCallback; |
| 43 |
import org.eclipse.virgo.util.io.IOUtils; |
| 39 |
import org.eclipse.virgo.util.io.JarTransformer; |
44 |
import org.eclipse.virgo.util.io.JarTransformer; |
| 40 |
import org.eclipse.virgo.util.io.JarTransformingURLConnection; |
45 |
import org.eclipse.virgo.util.io.JarTransformingURLConnection; |
| 41 |
import org.eclipse.virgo.util.io.JarTransformer.JarTransformerCallback; |
46 |
import org.eclipse.virgo.util.io.JarTransformer.JarTransformerCallback; |
|
|
47 |
import org.eclipse.virgo.util.io.PathReference; |
| 42 |
import org.eclipse.virgo.util.osgi.manifest.BundleManifest; |
48 |
import org.eclipse.virgo.util.osgi.manifest.BundleManifest; |
| 43 |
import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory; |
49 |
import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory; |
| 44 |
|
50 |
|
|
Lines 50-56
import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory;
Link Here
|
| 50 |
* @see WebBundleManifestTransformer |
56 |
* @see WebBundleManifestTransformer |
| 51 |
*/ |
57 |
*/ |
| 52 |
public final class WebBundleUrlStreamHandlerService extends AbstractURLStreamHandlerService { |
58 |
public final class WebBundleUrlStreamHandlerService extends AbstractURLStreamHandlerService { |
| 53 |
|
59 |
private static final String FILE_PROTOCOL = "file"; |
|
|
60 |
|
| 54 |
private final WebBundleManifestTransformer transformer; |
61 |
private final WebBundleManifestTransformer transformer; |
| 55 |
|
62 |
|
| 56 |
public WebBundleUrlStreamHandlerService(WebBundleManifestTransformer transformer) { |
63 |
public WebBundleUrlStreamHandlerService(WebBundleManifestTransformer transformer) { |
|
Lines 61-73
public final class WebBundleUrlStreamHandlerService extends AbstractURLStreamHan
Link Here
|
| 61 |
public URLConnection openConnection(URL u) throws IOException { |
68 |
public URLConnection openConnection(URL u) throws IOException { |
| 62 |
WebBundleUrl url = new WebBundleUrl(u); |
69 |
WebBundleUrl url = new WebBundleUrl(u); |
| 63 |
URL actualUrl = new URL(url.getLocation()); |
70 |
URL actualUrl = new URL(url.getLocation()); |
| 64 |
|
71 |
|
| 65 |
JarTransformer jarTransformer = new JarTransformer(new Callback(actualUrl, url, this.transformer)); |
72 |
if (FILE_PROTOCOL.equals(actualUrl.getProtocol()) && new File(actualUrl.getPath()).isDirectory()) { |
| 66 |
return new JarTransformingURLConnection(actualUrl, jarTransformer, true); |
73 |
DirTransformer dirTransformer = new DirTransformer(new Callback(actualUrl, url, this.transformer)); |
|
|
74 |
return new DirTransformingURLConnection(actualUrl, dirTransformer, true); |
| 75 |
} else { |
| 76 |
JarTransformer jarTransformer = new JarTransformer(new Callback(actualUrl, url, this.transformer)); |
| 77 |
return new JarTransformingURLConnection(actualUrl, jarTransformer, true); |
| 78 |
} |
| 67 |
} |
79 |
} |
| 68 |
|
80 |
|
| 69 |
private static final class Callback implements JarTransformerCallback { |
81 |
private static final class Callback implements JarTransformerCallback, DirTransformerCallback { |
| 70 |
|
82 |
private static final String META_INF = "META-INF"; |
|
|
83 |
private static final String MANIFEST_MF = "MANIFEST.MF"; |
| 84 |
|
| 71 |
private final WebBundleManifestTransformer transformer; |
85 |
private final WebBundleManifestTransformer transformer; |
| 72 |
|
86 |
|
| 73 |
private final URL sourceURL; |
87 |
private final URL sourceURL; |
|
Lines 83-99
public final class WebBundleUrlStreamHandlerService extends AbstractURLStreamHan
Link Here
|
| 83 |
public boolean transformEntry(String entryName, InputStream is, JarOutputStream jos) throws IOException { |
97 |
public boolean transformEntry(String entryName, InputStream is, JarOutputStream jos) throws IOException { |
| 84 |
if (JarFile.MANIFEST_NAME.equals(entryName)) { |
98 |
if (JarFile.MANIFEST_NAME.equals(entryName)) { |
| 85 |
jos.putNextEntry(new ZipEntry(entryName)); |
99 |
jos.putNextEntry(new ZipEntry(entryName)); |
| 86 |
InputStreamReader reader = new InputStreamReader(is); |
100 |
transformManifest(is, jos); |
| 87 |
BundleManifest manifest = BundleManifestFactory.createBundleManifest(reader); |
|
|
| 88 |
InstallationOptions options = new InstallationOptions(this.webBundleUrl.getOptions()); |
| 89 |
if (manifest.getHeader(WebContainerUtils.HEADER_SPRINGSOURCE_DEFAULT_WAB_HEADERS) != null) { |
| 90 |
options.setDefaultWABHeaders(true); |
| 91 |
} |
| 92 |
|
| 93 |
boolean webBundle = WebContainerUtils.isWebApplicationBundle(manifest); |
| 94 |
this.transformer.transform(manifest, sourceURL, options, webBundle); |
| 95 |
|
| 96 |
toManifest(manifest.toDictionary()).write(jos); |
| 97 |
jos.closeEntry(); |
101 |
jos.closeEntry(); |
| 98 |
return true; |
102 |
return true; |
| 99 |
} |
103 |
} |
|
Lines 102-111
public final class WebBundleUrlStreamHandlerService extends AbstractURLStreamHan
Link Here
|
| 102 |
return isSignatureFile(entryName); |
106 |
return isSignatureFile(entryName); |
| 103 |
} |
107 |
} |
| 104 |
|
108 |
|
|
|
109 |
private void transformManifest(InputStream inputStream, OutputStream outputStream) throws IOException { |
| 110 |
InputStreamReader reader = new InputStreamReader(inputStream); |
| 111 |
BundleManifest manifest = BundleManifestFactory.createBundleManifest(reader); |
| 112 |
InstallationOptions options = new InstallationOptions(this.webBundleUrl.getOptions()); |
| 113 |
if (manifest.getHeader(WebContainerUtils.HEADER_SPRINGSOURCE_DEFAULT_WAB_HEADERS) != null) { |
| 114 |
options.setDefaultWABHeaders(true); |
| 115 |
} |
| 116 |
|
| 117 |
boolean webBundle = WebContainerUtils.isWebApplicationBundle(manifest); |
| 118 |
this.transformer.transform(manifest, sourceURL, options, webBundle); |
| 119 |
|
| 120 |
toManifest(manifest.toDictionary()).write(outputStream); |
| 121 |
} |
| 122 |
|
| 105 |
private boolean isSignatureFile(String entryName) { |
123 |
private boolean isSignatureFile(String entryName) { |
| 106 |
String[] entryNameComponents = entryName.split("/"); |
124 |
String[] entryNameComponents = entryName.split("/"); |
| 107 |
if (entryNameComponents.length == 2) { |
125 |
if (entryNameComponents.length == 2) { |
| 108 |
if ("META-INF".equals(entryNameComponents[0])) { |
126 |
if (META_INF.equals(entryNameComponents[0])) { |
| 109 |
String entryFileName = entryNameComponents[1]; |
127 |
String entryFileName = entryNameComponents[1]; |
| 110 |
if (entryFileName.endsWith(".SF") || entryFileName.endsWith(".DSA") || entryFileName.endsWith(".RSA")) { |
128 |
if (entryFileName.endsWith(".SF") || entryFileName.endsWith(".DSA") || entryFileName.endsWith(".RSA")) { |
| 111 |
return true; |
129 |
return true; |
|
Lines 129-134
public final class WebBundleUrlStreamHandlerService extends AbstractURLStreamHan
Link Here
|
| 129 |
return manifest; |
147 |
return manifest; |
| 130 |
} |
148 |
} |
| 131 |
|
149 |
|
|
|
150 |
public boolean transformFile(InputStream inputStream, PathReference toFile) throws IOException { |
| 151 |
if (MANIFEST_MF.equals(toFile.getName()) && META_INF.equals(toFile.getParent().getName())) { |
| 152 |
toFile.getParent().createDirectory(); |
| 153 |
OutputStream outputStream = null; |
| 154 |
try { |
| 155 |
outputStream = new FileOutputStream(toFile.toFile()); |
| 156 |
transformManifest(inputStream, outputStream); |
| 157 |
} finally { |
| 158 |
IOUtils.closeQuietly(outputStream); |
| 159 |
} |
| 160 |
return true; |
| 161 |
} |
| 162 |
|
| 163 |
// Delete signature files. Should be generalized into another |
| 164 |
// transformer type. |
| 165 |
return isSignatureFile(toFile); |
| 166 |
} |
| 167 |
|
| 168 |
private boolean isSignatureFile(PathReference file) { |
| 169 |
if (META_INF.equals(file.getParent().getName())) { |
| 170 |
String fileName = file.getName(); |
| 171 |
if (fileName.endsWith(".SF") || fileName.endsWith(".DSA") || fileName.endsWith(".RSA")) { |
| 172 |
return true; |
| 173 |
} |
| 174 |
} |
| 175 |
return false; |
| 176 |
} |
| 177 |
|
| 132 |
} |
178 |
} |
| 133 |
|
179 |
|
| 134 |
} |
180 |
} |