Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 11 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 209 additions and 120 deletions.
  1. +209 −120 webstart/src/main/java/org/jbundle/util/osgi/webstart/OsgiWebStartServlet.java
View
329 webstart/src/main/java/org/jbundle/util/osgi/webstart/OsgiWebStartServlet.java
@@ -17,9 +17,9 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
-import java.io.StringBufferInputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
@@ -159,17 +159,24 @@
Date lastBundleChange = null;
+ /**
+ * Status of the bundles for this jnlp
+ */
enum BundleChangeStatus {
- UNKNOWN,
- NONE,
- PARTIAL,
- ALL
+ UNKNOWN, // Unknown
+ NONE, // Cached bundle matches request
+ PARTIAL, // Jnlp was changed
+ ALL // Request is completely different from cached jnlp
};
- enum TagsToAdd {
- CACHEABLE_ONLY,
- UNIQUE_ONLY,
- ALL
+ /**
+ * XML Elements to change in the jnlp
+ */
+ enum ElementsToChange {
+ NONE, // Everything up-to-date
+ CACHEABLE, // Only add the cacheable tags
+ UNIQUE, // Only add the unique tags
+ ALL // Add all the tags
};
/**
@@ -196,6 +203,7 @@ public OsgiWebStartServlet(Object context, String servicePid, Dictionary<String,
public void init(Object context, String servicePid, Dictionary<String, String> properties) {
super.init(context, servicePid, properties);
+ lastBundleChange = new Date();
listener = new BundleChangeListener(this);
this.getBundleContext().addBundleListener(listener);
}
@@ -270,24 +278,26 @@ public boolean makeJnlp(HttpServletRequest request, HttpServletResponse response
response.setContentType(JNLP_MIME_TYPE);
try {
- IBindingFactory jc = BindingDirectory.getFactory(Jnlp.class);
- Jnlp jnlp = null;
-
StringBuilder sbBase = new StringBuilder();
StringBuilder sbUnique = new StringBuilder();
- boolean containsUniqueParams = this.getJnlpCacheFilenames(request, sbBase, sbUnique);
+ this.getJnlpCacheFilenames(request, sbBase, sbUnique);
File jnlpBaseCacheFile = getBundleContext().getDataFile(sbBase.toString());
- File jnlpUniqueCacheFile = containsUniqueParams ? getBundleContext().getDataFile(sbUnique.toString()) : null;
+ removeCacheFileIfStale(request, jnlpBaseCacheFile);
+ File jnlpUniqueCacheFile = getBundleContext().getDataFile(sbUnique.toString());
+ removeCacheFileIfStale(request, jnlpUniqueCacheFile);
- if (sendCacheIfCurrent(request, response, containsUniqueParams ? jnlpUniqueCacheFile : jnlpBaseCacheFile))
- return true; // Returned the cached jnlp or a cache up-to-date response
+ if (jnlpUniqueCacheFile.exists())
+ if (sendJnlpCacheIfCurrent(request, response, jnlpUniqueCacheFile))
+ return true; // Returned the cached jnlp or a 'http cache up-to-date' response
+ IBindingFactory jc = BindingDirectory.getFactory(Jnlp.class);
IMarshallingContext marshaller = jc.createMarshallingContext();
marshaller.setIndent(4);
+ Jnlp jnlp = null;
- BundleChangeStatus bundleStatus = BundleChangeStatus.UNKNOWN;
- TagsToAdd tagsToCache = containsUniqueParams ? TagsToAdd.CACHEABLE_ONLY : TagsToAdd.ALL; // If no unique tags, cache everything
+ BundleChangeStatus bundleChangeStatus = BundleChangeStatus.UNKNOWN;
+ // First step, create or read the cacheable elements.
if (jnlpBaseCacheFile.exists())
{ // Start from the cache file
InputStream inStream = new FileInputStream(jnlpBaseCacheFile);
@@ -295,20 +305,21 @@ public boolean makeJnlp(HttpServletRequest request, HttpServletResponse response
jnlp = (Jnlp)unmarshaller.unmarshalDocument(inStream, OUTPUT_ENCODING);
inStream.close();
- if (this.isCurrent(request, jnlpBaseCacheFile))
+ ElementsToChange elementsToChange = getCacheElementsToChange(request, jnlpBaseCacheFile);
+ if (elementsToChange == ElementsToChange.NONE)
{
- bundleStatus = BundleChangeStatus.NONE; // Cacheable section is already up-to-date
+ bundleChangeStatus = BundleChangeStatus.NONE; // Cacheable section is already up-to-date
}
else
{
- bundleStatus = setupJnlp(jnlp, request, response, false, tagsToCache); // Compare with the current jnlp file
- if (bundleStatus == BundleChangeStatus.PARTIAL)
- setupJnlp(jnlp, request, response, true, tagsToCache); // Something changed, need to rescan everything
+ bundleChangeStatus = setupJnlp(jnlp, request, response, false, elementsToChange); // Compare with the current jnlp file
+ if (bundleChangeStatus == BundleChangeStatus.PARTIAL)
+ setupJnlp(jnlp, request, response, true, elementsToChange); // Something changed, need to rescan everything
}
- jnlp.setCodebase(getCodebase(request)); // codebase is ALWAYS the source
+ jnlp.setCodebase(getJnlpCodebase(request)); // codebase is ALWAYS the source
}
else
- {
+ { // Start from scratch
if (getRequestParam(request, TEMPLATE, null) != null)
{ // Start from the template file
URL url = context.getResource(getRequestParam(request, TEMPLATE, null));
@@ -319,32 +330,27 @@ public boolean makeJnlp(HttpServletRequest request, HttpServletResponse response
}
else
jnlp = new Jnlp(); // Start from an empty file
- bundleStatus = setupJnlp(jnlp, request, response, true, tagsToCache); // Create the base jnlp file
+ bundleChangeStatus = setupJnlp(jnlp, request, response, true, ElementsToChange.CACHEABLE); // Create the base jnlp file
}
- if (bundleStatus == BundleChangeStatus.UNKNOWN) {
+ if (bundleChangeStatus == BundleChangeStatus.UNKNOWN) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); // Return a 'file not found' error
return true;
}
- if ((bundleStatus == BundleChangeStatus.PARTIAL) || (bundleStatus == BundleChangeStatus.ALL))
+ if ((bundleChangeStatus == BundleChangeStatus.PARTIAL) || (bundleChangeStatus == BundleChangeStatus.ALL))
this.cacheThisJnlp(marshaller, jnlp, jnlpBaseCacheFile); // Template changed, re-cache it
- if (!containsUniqueParams)
- if (bundleStatus == BundleChangeStatus.NONE)
- if (checkCacheAndSend(request, response, jnlpBaseCacheFile, true))
+ // Next step, create/read the unique elements
+ if (bundleChangeStatus == BundleChangeStatus.NONE)
+ if (jnlpUniqueCacheFile.exists())
+ if (checkCacheAndSend(request, response, jnlpUniqueCacheFile, true, true))
return true; // Returned the cached jnlp or a cache up-to-date response
-
- if (containsUniqueParams)
- {
- setupJnlp(jnlp, request, response, false, TagsToAdd.UNIQUE_ONLY); // Add the unique params - this is fast
- if (bundleStatus == BundleChangeStatus.NONE)
- {
- if (!jnlpUniqueCacheFile.exists())
- bundleStatus = BundleChangeStatus.ALL; // No cache file means create the cache file
- }
- if ((bundleStatus == BundleChangeStatus.PARTIAL) || (bundleStatus == BundleChangeStatus.ALL))
- cacheThisJnlp(marshaller, jnlp, jnlpUniqueCacheFile);
- }
+ setupJnlp(jnlp, request, response, false, ElementsToChange.UNIQUE); // Add the unique params - this is fast
+ if (bundleChangeStatus == BundleChangeStatus.NONE)
+ if (!jnlpUniqueCacheFile.exists())
+ bundleChangeStatus = BundleChangeStatus.ALL; // No unique cache file means create the unique cache file
+ if ((bundleChangeStatus == BundleChangeStatus.PARTIAL) || (bundleChangeStatus == BundleChangeStatus.ALL))
+ cacheThisJnlp(marshaller, jnlp, jnlpUniqueCacheFile);
Date lastModified = new Date(jnlpBaseCacheFile.lastModified());
response.addHeader(LAST_MODIFIED, getHttpDate(lastModified));
@@ -353,14 +359,7 @@ public boolean makeJnlp(HttpServletRequest request, HttpServletResponse response
marshaller.marshalDocument(jnlp, OUTPUT_ENCODING, null, writer);
if (DEBUG)
- {
- writer = new StringWriter();
- marshaller.marshalDocument(jnlp, OUTPUT_ENCODING, null, writer);
- String string = ((StringWriter)writer).toString();
- System.out.println(string);
- }
-
- lastBundleChange = lastModified; // Use this cached file until bundles change
+ debugWriteJnlp(marshaller, jnlp);
return true;
} catch (JiBXException e) {
@@ -386,11 +385,27 @@ public void cacheThisJnlp(IMarshallingContext marshaller, Jnlp jnlp, File file)
/**
* If there have not been any bundle changes, return the cached jnlp file.
* @param request
+ * @param file to check
+ * @return true if removed (stale)
+ */
+ public boolean removeCacheFileIfStale(HttpServletRequest request, File file) throws IOException
+ {
+ if (!file.exists())
+ return true;
+ Date lastModified = new Date(file.lastModified());
+ if ((lastBundleChange == null)
+ || (lastBundleChange.after(lastModified)))
+ return file.delete();
+ return false; // File is not stale
+ }
+ /**
+ * If there have not been any bundle changes, return the cached jnlp file.
+ * @param request
* @param response
- * @return
+ * @return true if send a response
* @throws IOException
*/
- public boolean sendCacheIfCurrent(HttpServletRequest request, HttpServletResponse response, File file) throws IOException
+ public boolean sendJnlpCacheIfCurrent(HttpServletRequest request, HttpServletResponse response, File file) throws IOException
{
if (!file.exists())
return false;
@@ -398,21 +413,21 @@ public boolean sendCacheIfCurrent(HttpServletRequest request, HttpServletRespons
if ((lastBundleChange == null)
|| (lastBundleChange.after(lastModified)))
return false;
- return checkCacheAndSend(request, response, file, false);
+ return checkCacheAndSend(request, response, file, false, true);
}
/**
- * Return http response that the cache is up-to-date.
+ * Return http response that the cache file is up-to-date.
* @param request
* @param response
* @return
* @throws IOException
*/
- public boolean checkCacheAndSend(HttpServletRequest request, HttpServletResponse response, File file, boolean checkFileDate) throws IOException
+ public boolean checkCacheAndSend(HttpServletRequest request, HttpServletResponse response, File file, boolean checkFileDate, boolean jnlpFile) throws IOException
{
if ((file == null) || (!file.exists()))
return false; // Error - cache doesn't exist
- if (this.isCurrent(request, file))
+ if (getCacheElementsToChange(request, file) == ElementsToChange.NONE)
{ // Not modified since last time
response.setHeader(LAST_MODIFIED, request.getHeader(IF_MODIFIED_SINCE));
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
@@ -422,48 +437,65 @@ public boolean checkCacheAndSend(HttpServletRequest request, HttpServletResponse
Date lastModified = new Date(file.lastModified());
response.addHeader(LAST_MODIFIED, getHttpDate(lastModified));
- String newCodebase = fixCodebase(request, file);
- InputStream inStream = null;
- if (newCodebase != null)
- inStream = new StringBufferInputStream(newCodebase);
+ String newCodebase = null;
+ if (jnlpFile)
+ newCodebase = fixCodebase(request, file);
+ if (newCodebase == null)
+ {
+ InputStream inStream = new FileInputStream(file); // If they want it again, send them my cached copy
+ OutputStream writer = response.getOutputStream();
+ copyStream(inStream, writer, true); // Ignore errors, as browsers do weird things
+ inStream.close();
+// writer.close(); // Don't close http connection
+ if (DEBUG)
+ if (jnlpFile)
+ debugWriteStream(new FileInputStream(file));
+ }
else
- inStream = new FileInputStream(file); // If they want it again, send them my cached copy
- OutputStream writer = response.getOutputStream();
- copyStream(inStream, writer, true); // Ignore errors, as browsers do weird things
- inStream.close();
- writer.close();
+ {
+ Reader inStream = new StringReader(newCodebase);
+ Writer writer = response.getWriter();
+ copyStream(inStream, writer, true); // Ignore errors, as browsers do weird things
+ inStream.close();
+// writer.close(); // Don't close http connection
+ if (DEBUG)
+ debugWriteStream(new StringReader(newCodebase));
+ }
if (checkFileDate)
{
if ((lastBundleChange != null)
&& (lastBundleChange.after(lastModified)))
- file.setLastModified(lastBundleChange.getTime()); // Make sure this file is up-to-date for the next checkBundleChanges call
- return true; // Returned the cached jnlp or a cache up-to-date response
+ file.setLastModified(lastBundleChange.getTime()); // Make sure this file is up-to-date for the next checkBundleChanges call
+ return true; // I returned the cached jnlp or a cache up-to-date response
}
return true; // Success - I returned the cached copy
}
/**
- * Return http response that the cache is up-to-date.
+ * Is the cache file up-to-date.
* @param request
- * @param response
- * @return
- * @throws IOException
+ * @param file
+ * @return CURRENT - Same as last http request, UNCHANGED since last request (from other client?), DIRTY - changed
*/
- public boolean isCurrent(HttpServletRequest request, File file)
+ public ElementsToChange getCacheElementsToChange(HttpServletRequest request, File jnlpBaseCacheFile)
{
- if ((file == null) || (!file.exists()))
- return false; // Error - cache doesn't exist
+ if ((jnlpBaseCacheFile == null) || (!jnlpBaseCacheFile.exists()))
+ return ElementsToChange.CACHEABLE; // Cache doesn't exist
+ Date lastModified = new Date(jnlpBaseCacheFile.lastModified());
String requestIfModifiedSince = request.getHeader(IF_MODIFIED_SINCE);
- Date lastModified = new Date(file.lastModified());
try {
- if (requestIfModifiedSince!=null) {
+ if (requestIfModifiedSince != null)
+ {
Date requestDate = getDateFromHttpDate(requestIfModifiedSince);
- if (!requestDate.before(lastModified))
- return true; // Not modified since last time
+ if (!requestDate.before(lastModified))
+ return ElementsToChange.NONE; // Not modified since last time
}
} catch (ParseException e) {
// Fall through
}
- return false;
+ if ((lastBundleChange == null)
+ || (lastBundleChange.after(lastModified)))
+ return ElementsToChange.NONE; // Bundles haven't changed since jnlp was last set up
+ return ElementsToChange.CACHEABLE; // Jnlp file has definitely changed
}
/**
* Does this cached file contain the same codebase?
@@ -473,10 +505,10 @@ public boolean isCurrent(HttpServletRequest request, File file)
* @param file
* @return
*/
- String CODEBASE_NAME = "codebase=\"";
+ String CODEBASE_NAME = CODEBASE + "=\"";
public String fixCodebase(HttpServletRequest request, File file)
{
- String requestCodebase = getCodebase(request);
+ String requestCodebase = getJnlpCodebase(request);
try {
// If they want it again, send them my cached copy
Reader inStream = new FileReader(file);
@@ -524,14 +556,12 @@ public boolean isMainJnlp(HttpServletRequest request)
* @param request
* @param sbBase Returns the cache file name of using just the component parameters
* @param dbUnique Returns the cache file name of using all the parameters
- * @return
*/
@SuppressWarnings("unchecked")
- protected boolean getJnlpCacheFilenames(HttpServletRequest request, StringBuilder sbBase, StringBuilder sbUnique)
+ protected void getJnlpCacheFilenames(HttpServletRequest request, StringBuilder sbBase, StringBuilder sbUnique)
{
- boolean containsUniqueParams = false;
// sb.append(getCodebase(request)); // Don't use the codebase
- sbBase.append(getHref(request)).append('/'); // Do use the base url
+ // sbBase.append(getHref(request)).append('/'); // Don't use the base url
// sb.append(request.getQueryString());
Enumeration<String> e = request.getParameterNames();
while (e.hasMoreElements())
@@ -539,32 +569,44 @@ protected boolean getJnlpCacheFilenames(HttpServletRequest request, StringBuilde
String paramName = e.nextElement();
if (isCachableParam(paramName))
sbBase.append('&').append(paramName).append('=').append(request.getParameter(paramName));
- else
- containsUniqueParams = true;
sbUnique.append('&').append(paramName).append('=').append(request.getParameter(paramName));
}
String mainPackage = ClassFinderActivator.getPackageName(this.getRequestParam(request, MAIN_CLASS, null), false);
if (mainPackage == null)
mainPackage = ClassFinderActivator.getPackageName(this.getRequestParam(request, APPLET_CLASS, null), false);
if (mainPackage != null)
- sbBase.append("mainPackage").append(mainPackage);
- String hash = Integer.toString(sbBase.toString().hashCode()).replace('-', 'a');
- sbBase.delete(0, sbBase.length());
- sbBase.append(BASE_CACHE_FILE_PREFIX).append(hash).append(".jnlp");
- hash = Integer.toString(sbUnique.toString().hashCode()).replace('-', 'a');
- sbUnique.delete(0, sbUnique.length());
- sbUnique.append(UNIQUE_CACHE_FILE_PREFIX).append(hash).append(".jnlp");
- return containsUniqueParams;
+ {
+ sbBase.append('&').append("mainPackage").append('=').append(mainPackage);
+ sbUnique.append('&').append("mainPackage").append('=').append(mainPackage);
+ }
+ getHashFileName(sbBase, BASE_CACHE_FILE_PREFIX);
+ getHashFileName(sbUnique, UNIQUE_CACHE_FILE_PREFIX);
+ }
+ /**
+ * Calculate the cache file name from this url.
+ */
+ StringBuilder getHashFileName(StringBuilder sbURL, String filePrefix)
+ {
+ String hash = Integer.toString(sbURL.toString().hashCode()).replace('-', 'a');
+ sbURL.delete(0, sbURL.length());
+ sbURL.append(filePrefix).append(hash).append(".jnlp");
+ return sbURL;
}
/**
* Populate the Jnlp xml.
- * @param jnlp
- * @param request
+ * @param jnlp The jnlp to modify
+ * @param request The http request
+ * @param response The http response
* @param forceScanBundle Scan the bundle for package names even if the cache is current
+ * @param elementsToChange Which xml elements should I change?
+ * @param baseCacheFileStatus The current cache file status
+ * @return How much have I changed this jnlp?
*/
- protected BundleChangeStatus setupJnlp(Jnlp jnlp, HttpServletRequest request, HttpServletResponse response, boolean forceScanBundle, TagsToAdd cachableParamsOnly)
+ protected BundleChangeStatus setupJnlp(Jnlp jnlp, HttpServletRequest request, HttpServletResponse response, boolean forceScanBundle, ElementsToChange elementsToChange)
{
BundleChangeStatus bundleChangeStatus = BundleChangeStatus.UNKNOWN;
+ if (elementsToChange == ElementsToChange.NONE)
+ bundleChangeStatus = BundleChangeStatus.NONE; // Don't re-cache the jnlp if I'm not changing base info
String mainClass = getRequestParam(request, MAIN_CLASS, null);
if (mainClass == null)
@@ -580,19 +622,20 @@ protected BundleChangeStatus setupJnlp(Jnlp jnlp, HttpServletRequest request, Ht
getResource(jnlp, true); // Clear the resource entries and create a new one
Bundle bundle = null;
- if ((cachableParamsOnly == TagsToAdd.CACHEABLE_ONLY) || (cachableParamsOnly == TagsToAdd.ALL))
+ if ((elementsToChange == ElementsToChange.CACHEABLE) || (elementsToChange == ElementsToChange.ALL))
{ // base params
String version = getRequestParam(request, VERSION, null);
+
bundle = findBundle(packageName, version);
if (bundle == null)
return BundleChangeStatus.UNKNOWN;
-
+
setCachableInformation(jnlp, bundle, request);
}
- if ((cachableParamsOnly == TagsToAdd.UNIQUE_ONLY) || (cachableParamsOnly == TagsToAdd.ALL))
+ if ((elementsToChange == ElementsToChange.UNIQUE) || (elementsToChange == ElementsToChange.ALL))
{ // Unique params
- jnlp.setCodebase(getCodebase(request));
+ jnlp.setCodebase(getJnlpCodebase(request));
jnlp.setHref(getHref(request) + '?' + request.getQueryString());
jnlp.setSpec("1.0+");
@@ -606,7 +649,7 @@ protected BundleChangeStatus setupJnlp(Jnlp jnlp, HttpServletRequest request, Ht
addProperties(request, response, jnlp);
}
- if ((cachableParamsOnly == TagsToAdd.CACHEABLE_ONLY) || (cachableParamsOnly == TagsToAdd.ALL))
+ if ((elementsToChange == ElementsToChange.CACHEABLE) || (elementsToChange == ElementsToChange.ALL))
{ // base params
String pathToJars = getPathToJars(request);
Set<Bundle> bundles = new HashSet<Bundle>(); // Initial empty Bundle list
@@ -628,7 +671,7 @@ protected BundleChangeStatus setupJnlp(Jnlp jnlp, HttpServletRequest request, Ht
bundleChangeStatus = addComponents(request, response, jnlp, components, bundles, bundleChangeStatus, pathToJars);
}
- if ((cachableParamsOnly == TagsToAdd.UNIQUE_ONLY) || (cachableParamsOnly == TagsToAdd.ALL))
+ if ((elementsToChange == ElementsToChange.UNIQUE) || (elementsToChange == ElementsToChange.ALL))
{ // Unique params
if (getRequestParam(request, MAIN_CLASS, null) != null)
setApplicationDesc(jnlp, mainClass, request);
@@ -637,6 +680,7 @@ else if (getRequestParam(request, APPLET_CLASS, null) != null)
else
setComponentDesc(jnlp, request);
}
+
return bundleChangeStatus;
}
@@ -647,13 +691,12 @@ else if (getRequestParam(request, APPLET_CLASS, null) != null)
* @param request
* @return
*/
- private String getCodebase(HttpServletRequest request)
+ private String getJnlpCodebase(HttpServletRequest request)
{
String urlprefix = getUrlPrefix(request);
- String servletPath = request.getServletPath();
String codebase = this.getRequestParam(request, CODEBASE, null);
if ((codebase == null) || (codebase.length() == 0))
- return urlprefix + servletPath; // If they don't have a codebase, jars are served relative to the servlet path
+ codebase = "/";
return urlprefix + codebase;
}
@@ -671,7 +714,7 @@ private String getHref(HttpServletRequest request)
return "";
String codebase = this.getRequestParam(request, CODEBASE, null);
if ((codebase == null) || (codebase.length() == 0))
- return ""; // If they don't have a codebase, jars are served relative to the servlet path
+ codebase = "/";
return getRelativePath(respath, codebase);
}
/**
@@ -703,6 +746,8 @@ private String getPathToJars(HttpServletRequest request)
*/
private String getRelativePath(String servletPath, String rootPathToFix)
{
+ if (rootPathToFix == null)
+ return "";
if (servletPath.startsWith(rootPathToFix))
rootPathToFix = servletPath.substring(rootPathToFix.length());
if (rootPathToFix.startsWith("/"))
@@ -1480,7 +1525,7 @@ public boolean sendDataFile(HttpServletRequest request, HttpServletResponse resp
// response.sendError(HttpServletResponse.SC_NOT_FOUND); // Return a 'file not found' error
return false;
}
- return this.checkCacheAndSend(request, response, file, false);
+ return this.checkCacheAndSend(request, response, file, false, false);
}
public static final String DEFAULT_APPLET_PATH = "/docs/applet.html";
@@ -1594,10 +1639,11 @@ public BundleContext getBundleContext()
private Properties cachedProperties = null;
/**
- *
+ * If a properties file is specified, modify the request object to return those properties
+ * @param request
* @param propertiesFile
*/
- public synchronized HttpServletRequest readIfPropertiesFile(HttpServletRequest request, String propertiesPath, boolean returnPropertiesPathAsQuery)
+ public synchronized HttpServletRequest readIfPropertiesFile(HttpServletRequest request, String propertiesPath, boolean propertiesOnly)
{
if (propertiesPath == null)
return request;
@@ -1607,7 +1653,7 @@ public synchronized HttpServletRequest readIfPropertiesFile(HttpServletRequest r
{ // Same as last time, use same properties
if (request instanceof HttpServletRequestWithProperties)
request = (HttpServletRequest)((HttpServletRequestWithProperties)request).getRequest();
- return new HttpServletRequestWithProperties(request, cachedProperties, returnPropertiesPathAsQuery ? propertiesPath : null);
+ return new HttpServletRequestWithProperties(request, cachedProperties, propertiesOnly ? propertiesPath : null, propertiesOnly);
}
URL url = null;
@@ -1648,7 +1694,7 @@ public synchronized HttpServletRequest readIfPropertiesFile(HttpServletRequest r
cachedPropertiesPath = propertiesPath;
if (request instanceof HttpServletRequestWithProperties)
request = (HttpServletRequest)((HttpServletRequestWithProperties)request).getRequest();
- return new HttpServletRequestWithProperties(request, cachedProperties, returnPropertiesPathAsQuery ? propertiesPath : null);
+ return new HttpServletRequestWithProperties(request, cachedProperties, propertiesOnly ? propertiesPath : null, propertiesOnly);
}
/**
* Add all the dependent bundles (of this bundle) to the jar and package list.
@@ -1744,6 +1790,10 @@ public BundleChangeStatus addComponents(HttpServletRequest request, HttpServletR
Choice choice = this.getResource(jnlp, false);
Extension extension = new Extension();
extension.setName(comp);
+ String codebase = request.getParameter(CODEBASE);
+ if (codebase == null)
+ codebase = "/";
+ bundlePath = bundlePath + '&' + CODEBASE + '=' + codebase;
extension.setHref(bundlePath);
choice.setExtension(extension);
}
@@ -1933,11 +1983,12 @@ public String getBufferString()
boolean propertiesOnly = false; // Only return properties values, not request properties
String propertiesPath = null;
- public HttpServletRequestWithProperties(HttpServletRequest request, Properties properties, String propertiesPath)
+ public HttpServletRequestWithProperties(HttpServletRequest request, Properties properties, String propertiesPath, boolean propertiesOnly)
{
super(request);
this.properties = properties;
this.propertiesPath = propertiesPath;
+ this.propertiesOnly = propertiesOnly;
}
/**
* The default behavior of this method is to return getParameter(String name)
@@ -1947,7 +1998,7 @@ public HttpServletRequestWithProperties(HttpServletRequest request, Properties p
public String getParameter(String name) {
String value = null;
if (!propertiesOnly)
- value = super.getParameter(name);
+ value = super.getParameter(name);
if (PROPERTIES_FILE.equals(name))
if (propertiesPath != null)
if (propertiesPath.equals(value))
@@ -1963,13 +2014,33 @@ public String getParameter(String name) {
public String getQueryString() {
String queryString = super.getQueryString();
if (propertiesPath != null)
- return PROPERTIES_FILE + '=' + propertiesPath;
+ queryString = PROPERTIES_FILE + '=' + propertiesPath;
+ String codebase = properties.getProperty(CODEBASE);
+ if (codebase != null)
+ if (!queryString.contains(CODEBASE_NAME))
+ queryString = queryString + '&' + CODEBASE + '=' + codebase;
return queryString;
}
/**
- * The default behavior of this method is to return getParameterNames()
- * on the wrapped request object.
+ * Returns the part of this request's URL that calls the servlet.
+ * @return a <code>String</code> containing
+ */
+ public String getServletPath()
+ {
+ return super.getServletPath();
+ }
+ /**
+ * Returns the part of this request's URL from the protocol name up to the query string
+ * @return a <code>String</code> containing
*/
+ public String getRequestURI()
+ {
+ return super.getRequestURI();
+ }
+ /**
+ * The default behavior of this method is to return getParameterNames()
+ * on the wrapped request object.
+ */
public Enumeration<String> getParameterNames() {
Enumeration<?> names = super.getParameterNames();
Hashtable<String, String[]> map = new Hashtable<String, String[]>();
@@ -1990,13 +2061,31 @@ public String getQueryString() {
map.remove(PROPERTIES_FILE); // Don't return the name of my properties file - no recursion
return map.keys();
}
- public void setPropertiesOnly(boolean propertiesOnly)
+ public boolean setPropertiesOnly(boolean propertiesOnly)
{
+ boolean oldProperties = this.propertiesOnly;
this.propertiesOnly = propertiesOnly;
+ return oldProperties;
}
public String getPropertiesPath()
{
return propertiesPath;
}
}
+ public void debugWriteJnlp(IMarshallingContext marshaller, Jnlp jnlp) throws JiBXException
+ {
+ Writer writer = new StringWriter();
+ marshaller.marshalDocument(jnlp, OUTPUT_ENCODING, null, writer);
+ String string = ((StringWriter)writer).toString();
+ System.out.println(string);
+ }
+ public void debugWriteStream(InputStream inStream) throws IOException
+ {
+ copyStream(inStream, System.out, true); // Ignore errors, as browsers do weird things
+ }
+ public void debugWriteStream(Reader inStream) throws IOException
+ {
+ Writer writer = new OutputStreamWriter(System.out);
+ copyStream(inStream, writer, true); // Ignore errors, as browsers do weird things
+ }
}

No commit comments for this range

Something went wrong with that request. Please try again.