Merge remote-tracking branch 'origin/jetty-9.3.x' into jetty-9.4.x

This commit is contained in:
Jan Bartel 2016-08-03 18:56:36 +10:00
commit 8f058d2b09
4 changed files with 64 additions and 61 deletions

View File

@ -30,7 +30,9 @@ import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import org.eclipse.jetty.util.ArrayTrie;
@ -201,79 +203,49 @@ public class MimeTypes
}
}
String resourceName = "org/eclipse/jetty/http/mime";
try
{
String resourceName = "org/eclipse/jetty/http/mime.properties";
URL mimeTypesUrl = Loader.getResource(resourceName);
if (mimeTypesUrl == null)
ResourceBundle mimeBundle = ResourceBundle.getBundle(resourceName);
mimeBundle.keySet().stream()
.filter(x->x!=null)
.forEach(x->
__dftMimeMap.put(StringUtil.asciiToLowerCase(x), normalizeMimeType(mimeBundle.getString(x))));
if (__dftMimeMap.size()==0)
{
LOG.warn("Missing mime-type resource: {}", resourceName);
LOG.warn("Empty mime types at {}", resourceName);
}
else
else if (__dftMimeMap.size()<mimeBundle.keySet().size())
{
try (InputStream in = mimeTypesUrl.openStream();
InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8))
{
Properties mime = new Properties();
mime.load(reader);
mime.stringPropertyNames().stream()
.filter(x->x!=null)
.forEach(x->
__dftMimeMap.put(StringUtil.asciiToLowerCase(x), normalizeMimeType(mime.getProperty(x))));
if (__dftMimeMap.size()<mime.size())
{
LOG.warn("Encountered duplicate or null mime-type extension in resource: {}", mimeTypesUrl);
}
}
if (__dftMimeMap.size()==0)
{
LOG.warn("Empty mime types declaration at {}", mimeTypesUrl);
}
}
LOG.warn("Duplicate or null mime-type extension in resource: {}", resourceName);
}
}
catch(IOException e)
catch (MissingResourceException e)
{
LOG.warn(e.toString());
LOG.debug(e);
LOG.warn("Missing mime-type resource: {}", resourceName);
}
resourceName = "org/eclipse/jetty/http/encoding";
try
{
String resourceName = "org/eclipse/jetty/http/encoding.properties";
URL mimeTypesUrl = Loader.getResource(resourceName);
if (mimeTypesUrl == null)
ResourceBundle encodingBundle = ResourceBundle.getBundle(resourceName);
encodingBundle.keySet().stream()
.filter(t->t!=null)
.forEach(t->__encodings.put(t, encodingBundle.getString(t)));
if (__encodings.size()==0)
{
LOG.warn("Missing mime-type resource: {}", resourceName);
LOG.warn("Empty encodings at {}", resourceName);
}
else
else if (__encodings.size()<encodingBundle.keySet().size())
{
try (InputStream in = mimeTypesUrl.openStream();
InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8))
{
Properties encoding = new Properties();
encoding.load(reader);
encoding.stringPropertyNames().stream()
.filter(t->t!=null)
.forEach(t->__encodings.put(t, encoding.getProperty(t)));
if (__encodings.size()<encoding.size())
{
LOG.warn("Encountered null or duplicate encoding type in resource: {}", mimeTypesUrl);
}
}
if (__encodings.size()==0)
{
LOG.warn("Empty mime types declaration at {}", mimeTypesUrl);
}
LOG.warn("Null or duplicate encodings in resource: {}", resourceName);
}
}
catch(IOException e)
catch (MissingResourceException e)
{
LOG.warn(e.toString());
LOG.debug(e);
LOG.warn("Missing encoding resource: {}", resourceName);
}
}

View File

@ -73,11 +73,11 @@
org.xml.sax.helpers,
*
</Import-Package>
<Export-Package>com.acme.osgi</Export-Package>
<DynamicImport-Package>org.eclipse.jetty.*;version="[$(version;===;${parsedVersion.osgiVersion}),$(version;==+;${parsedVersion.osgiVersion}))"</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -18,10 +18,18 @@
package com.acme.osgi;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Dictionary;
import java.util.Hashtable;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@ -37,6 +45,27 @@ public class Activator implements BundleActivator
private ServiceRegistration _srA;
private ServiceRegistration _srB;
public static class TestServlet extends HttpServlet
{
/**
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
//report the mimetype of a file
String mimetype = req.getServletContext().getMimeType("file.gz");
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.write("<html><body><p>MIMETYPE="+mimetype+"</p></body</html>");
writer.flush();
}
}
/**
*
@ -44,12 +73,9 @@ public class Activator implements BundleActivator
*/
public void start(BundleContext context) throws Exception
{
String serverName = "defaultJettyServer";
//Create webappA as a Service and target it at the default server
WebAppContext webapp = new WebAppContext();
webapp.addServlet(new ServletHolder(new TestServlet()), "/mime");
Dictionary props = new Hashtable();
props.put("war","webappA");
props.put("contextPath","/acme");

View File

@ -150,6 +150,11 @@ public class TestJettyOSGiBootWebAppAsService
String content = new String(response.getContent());
assertTrue(content.indexOf("<h1>Test OSGi WebAppA</h1>") != -1);
response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/acme/mime");
assertEquals(HttpStatus.OK_200, response.getStatus());
content = new String(response.getContent());
assertTrue(content.indexOf("MIMETYPE=application/gzip") != -1);
response = client.GET("http://127.0.0.1:" + "9999" + "/acme/index.html");
assertEquals(HttpStatus.OK_200, response.getStatus());
content = new String(response.getContent());