Issue #797
This commit is contained in:
parent
d57a11668d
commit
4b920622d5
|
@ -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,50 @@ public class MimeTypes
|
|||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String resourceName = "org/eclipse/jetty/http/mime.properties";
|
||||
URL mimeTypesUrl = Loader.getResource(MimeTypes.class, resourceName);
|
||||
if (mimeTypesUrl == null)
|
||||
{
|
||||
LOG.warn("Missing mime-type resource: {}", resourceName);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
LOG.warn(e.toString());
|
||||
LOG.debug(e);
|
||||
}
|
||||
String resourceName = "org/eclipse/jetty/http/mime";
|
||||
|
||||
try
|
||||
{
|
||||
String resourceName = "org/eclipse/jetty/http/encoding.properties";
|
||||
URL mimeTypesUrl = Loader.getResource(MimeTypes.class, 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 encoding = new Properties();
|
||||
encoding.load(reader);
|
||||
|
||||
encoding.stringPropertyNames().stream()
|
||||
.filter(t->t!=null)
|
||||
.forEach(t->__encodings.put(t, encoding.getProperty(t)));
|
||||
LOG.warn("Duplicate or null mime-type extension in resource: {}", resourceName);
|
||||
}
|
||||
}
|
||||
catch (MissingResourceException e)
|
||||
{
|
||||
LOG.warn("Missing mime-type resource: {}", resourceName);
|
||||
}
|
||||
|
||||
if (__encodings.size()<encoding.size())
|
||||
{
|
||||
LOG.warn("Encountered null or duplicate encoding type in resource: {}", mimeTypesUrl);
|
||||
}
|
||||
}
|
||||
resourceName = "org/eclipse/jetty/http/encoding";
|
||||
try
|
||||
{
|
||||
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("Empty mime types declaration at {}", mimeTypesUrl);
|
||||
}
|
||||
if (__encodings.size()==0)
|
||||
{
|
||||
LOG.warn("Empty encodings at {}", resourceName);
|
||||
}
|
||||
else if (__encodings.size()<encodingBundle.keySet().size())
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@
|
|||
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>
|
||||
|
|
|
@ -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;
|
||||
|
@ -34,6 +42,28 @@ import org.osgi.framework.BundleContext;
|
|||
public class Activator implements BundleActivator
|
||||
{
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
|
@ -41,25 +71,10 @@ public class Activator implements BundleActivator
|
|||
public void start(BundleContext context) throws Exception
|
||||
{
|
||||
String serverName = "defaultJettyServer";
|
||||
|
||||
/* Uncomment to create a different server instance to deploy to. Also change
|
||||
* TestJettyOSGiBootWebAppAsService to use the port 9999
|
||||
|
||||
Server server = new Server();
|
||||
//do any setup on Server in here
|
||||
serverName = "fooServer";
|
||||
Dictionary serverProps = new Hashtable();
|
||||
//define the unique name of the server instance
|
||||
serverProps.put("managedServerName", serverName);
|
||||
serverProps.put("jetty.http.port", "9999");
|
||||
//let Jetty apply some configuration files to the Server instance
|
||||
serverProps.put("jetty.etc.config.urls", "file:/opt/jetty/etc/jetty.xml,file:/opt/jetty/etc/jetty-selector.xml,file:/opt/jetty/etc/jetty-deployer.xml");
|
||||
//register as an OSGi Service for Jetty to find
|
||||
context.registerService(Server.class.getName(), server, serverProps);
|
||||
*/
|
||||
|
||||
|
||||
//Create a webapp context as a Service and target it at the Server created above
|
||||
WebAppContext webapp = new WebAppContext();
|
||||
webapp.addServlet(new ServletHolder(new TestServlet()), "/mime");
|
||||
Dictionary props = new Hashtable();
|
||||
props.put("war",".");
|
||||
props.put("contextPath","/acme");
|
||||
|
|
|
@ -142,6 +142,11 @@ public class TestJettyOSGiBootWebAppAsService
|
|||
|
||||
String content = new String(response.getContent());
|
||||
assertTrue(content.indexOf("<h1>Test OSGi WebApp</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);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue