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.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.ArrayTrie;
|
import org.eclipse.jetty.util.ArrayTrie;
|
||||||
|
@ -201,79 +203,50 @@ public class MimeTypes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String resourceName = "org/eclipse/jetty/http/mime";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String resourceName = "org/eclipse/jetty/http/mime.properties";
|
ResourceBundle mimeBundle = ResourceBundle.getBundle(resourceName);
|
||||||
URL mimeTypesUrl = Loader.getResource(MimeTypes.class, resourceName);
|
mimeBundle.keySet().stream()
|
||||||
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)
|
.filter(x->x!=null)
|
||||||
.forEach(x->
|
.forEach(x->
|
||||||
__dftMimeMap.put(StringUtil.asciiToLowerCase(x), normalizeMimeType(mime.getProperty(x))));
|
__dftMimeMap.put(StringUtil.asciiToLowerCase(x), normalizeMimeType(mimeBundle.getString(x))));
|
||||||
|
|
||||||
if (__dftMimeMap.size()<mime.size())
|
|
||||||
{
|
|
||||||
LOG.warn("Encountered duplicate or null mime-type extension in resource: {}", mimeTypesUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (__dftMimeMap.size()==0)
|
if (__dftMimeMap.size()==0)
|
||||||
{
|
{
|
||||||
LOG.warn("Empty mime types declaration at {}", mimeTypesUrl);
|
LOG.warn("Empty mime types at {}", resourceName);
|
||||||
}
|
}
|
||||||
}
|
else if (__dftMimeMap.size()<mimeBundle.keySet().size())
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
{
|
||||||
LOG.warn(e.toString());
|
LOG.warn("Duplicate or null mime-type extension in resource: {}", resourceName);
|
||||||
LOG.debug(e);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try
|
catch (MissingResourceException e)
|
||||||
{
|
|
||||||
String resourceName = "org/eclipse/jetty/http/encoding.properties";
|
|
||||||
URL mimeTypesUrl = Loader.getResource(MimeTypes.class, resourceName);
|
|
||||||
if (mimeTypesUrl == null)
|
|
||||||
{
|
{
|
||||||
LOG.warn("Missing mime-type resource: {}", resourceName);
|
LOG.warn("Missing mime-type resource: {}", resourceName);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
try (InputStream in = mimeTypesUrl.openStream();
|
|
||||||
InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8))
|
|
||||||
{
|
|
||||||
Properties encoding = new Properties();
|
|
||||||
encoding.load(reader);
|
|
||||||
|
|
||||||
encoding.stringPropertyNames().stream()
|
resourceName = "org/eclipse/jetty/http/encoding";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResourceBundle encodingBundle = ResourceBundle.getBundle(resourceName);
|
||||||
|
encodingBundle.keySet().stream()
|
||||||
.filter(t->t!=null)
|
.filter(t->t!=null)
|
||||||
.forEach(t->__encodings.put(t, encoding.getProperty(t)));
|
.forEach(t->__encodings.put(t, encodingBundle.getString(t)));
|
||||||
|
|
||||||
if (__encodings.size()<encoding.size())
|
|
||||||
{
|
|
||||||
LOG.warn("Encountered null or duplicate encoding type in resource: {}", mimeTypesUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (__encodings.size()==0)
|
if (__encodings.size()==0)
|
||||||
{
|
{
|
||||||
LOG.warn("Empty mime types declaration at {}", mimeTypesUrl);
|
LOG.warn("Empty encodings at {}", resourceName);
|
||||||
}
|
}
|
||||||
}
|
else if (__encodings.size()<encodingBundle.keySet().size())
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
{
|
||||||
LOG.warn(e.toString());
|
LOG.warn("Null or duplicate encodings in resource: {}", resourceName);
|
||||||
LOG.debug(e);
|
}
|
||||||
|
}
|
||||||
|
catch (MissingResourceException e)
|
||||||
|
{
|
||||||
|
LOG.warn("Missing encoding resource: {}", resourceName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@
|
||||||
org.xml.sax.helpers,
|
org.xml.sax.helpers,
|
||||||
*
|
*
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
|
<Export-Package>com.acme.osgi</Export-Package>
|
||||||
<DynamicImport-Package>org.eclipse.jetty.*;version="[$(version;===;${parsedVersion.osgiVersion}),$(version;==+;${parsedVersion.osgiVersion}))"</DynamicImport-Package>
|
<DynamicImport-Package>org.eclipse.jetty.*;version="[$(version;===;${parsedVersion.osgiVersion}),$(version;==+;${parsedVersion.osgiVersion}))"</DynamicImport-Package>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -18,10 +18,18 @@
|
||||||
|
|
||||||
package com.acme.osgi;
|
package com.acme.osgi;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Dictionary;
|
import java.util.Dictionary;
|
||||||
import java.util.Hashtable;
|
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.server.handler.ContextHandler;
|
||||||
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.osgi.framework.BundleActivator;
|
import org.osgi.framework.BundleActivator;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
@ -34,6 +42,28 @@ import org.osgi.framework.BundleContext;
|
||||||
public class Activator implements BundleActivator
|
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
|
* @param context
|
||||||
|
@ -42,24 +72,9 @@ public class Activator implements BundleActivator
|
||||||
{
|
{
|
||||||
String serverName = "defaultJettyServer";
|
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
|
//Create a webapp context as a Service and target it at the Server created above
|
||||||
WebAppContext webapp = new WebAppContext();
|
WebAppContext webapp = new WebAppContext();
|
||||||
|
webapp.addServlet(new ServletHolder(new TestServlet()), "/mime");
|
||||||
Dictionary props = new Hashtable();
|
Dictionary props = new Hashtable();
|
||||||
props.put("war",".");
|
props.put("war",".");
|
||||||
props.put("contextPath","/acme");
|
props.put("contextPath","/acme");
|
||||||
|
|
|
@ -142,6 +142,11 @@ public class TestJettyOSGiBootWebAppAsService
|
||||||
|
|
||||||
String content = new String(response.getContent());
|
String content = new String(response.getContent());
|
||||||
assertTrue(content.indexOf("<h1>Test OSGi WebApp</h1>") != -1);
|
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
|
finally
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue