本文整理汇总了Java中org.eclipse.jetty.http.MimeTypes类的典型用法代码示例。如果您正苦于以下问题:Java MimeTypes类的具体用法?Java MimeTypes怎么用?Java MimeTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MimeTypes类属于org.eclipse.jetty.http包,在下文中一共展示了MimeTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildServletContext
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
/** Build a ServletContextHandler. */
private static ServletContextHandler buildServletContext(String contextPath) {
if ( contextPath == null || contextPath.isEmpty() )
contextPath = "/" ;
else if ( !contextPath.startsWith("/") )
contextPath = "/" + contextPath ;
ServletContextHandler context = new ServletContextHandler() ;
context.setDisplayName("PatchLogServer") ;
MimeTypes mt = new MimeTypes();
addMimeType(mt, Lang.TTL);
addMimeType(mt, Lang.NT);
addMimeType(mt, Lang.TRIG);
addMimeType(mt, Lang.NQ);
addMimeType(mt, Lang.RDFXML);
context.setMimeTypes(mt);
ErrorHandler eh = new HttpErrorHandler();
context.setErrorHandler(eh) ;
return context ;
}
示例2: sendErrorAsync
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
/**
* Async version of {@link org.eclipse.jetty.server.Response#sendError(int, String)}.
*/
private void sendErrorAsync(int statusCode, String reasonPhrase) {
servletResponse.setHeader(HttpHeaders.Names.EXPIRES, null);
servletResponse.setHeader(HttpHeaders.Names.LAST_MODIFIED, null);
servletResponse.setHeader(HttpHeaders.Names.CACHE_CONTROL, null);
servletResponse.setHeader(HttpHeaders.Names.CONTENT_TYPE, null);
servletResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, null);
setStatus(servletResponse, statusCode, Optional.of(reasonPhrase));
// If we are allowed to have a body
if (statusCode != HttpServletResponse.SC_NO_CONTENT &&
statusCode != HttpServletResponse.SC_NOT_MODIFIED &&
statusCode != HttpServletResponse.SC_PARTIAL_CONTENT &&
statusCode >= HttpServletResponse.SC_OK) {
servletResponse.setHeader(HttpHeaders.Names.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
servletResponse.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.toString());
byte[] errorContent = errorResponseContentCreator
.createErrorContent(servletRequest.getRequestURI(), statusCode, Optional.ofNullable(reasonPhrase));
servletResponse.setContentLength(errorContent.length);
servletOutputStreamWriter.sendErrorContentAndCloseAsync(ByteBuffer.wrap(errorContent));
} else {
servletResponse.setContentLength(0);
servletOutputStreamWriter.close();
}
}
示例3: handle
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
baseRequest.setHandled(true);
String method = request.getMethod();
if (!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD)) {
return;
}
response.setContentType(MimeTypes.TEXT_PLAIN_8859_1);
response.setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(4096);
handleErrorPage(request, writer, baseRequest.getResponse().getStatus(), baseRequest.getResponse().getReason());
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
}
示例4: handle
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
String method = request.getMethod();
if ( !method.equals(HttpMethod.GET.asString())
&& !method.equals(HttpMethod.POST.asString())
&& !method.equals(HttpMethod.HEAD.asString()) )
return ;
response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ;
ServletOps.setNoCache(response) ;
ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024) ;
try ( Writer writer = IO.asUTF8(bytes) ) {
String reason=(response instanceof Response)?((Response)response).getReason():null;
handleErrorPage(request, writer, response.getStatus(), reason) ;
writer.flush();
response.setContentLength(bytes.size()) ;
// Copy :-(
response.getOutputStream().write(bytes.toByteArray()) ;
}
}
示例5: AssetServlet
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
/**
* Creates a new {@code AssetServlet} that serves static assets loaded from {@code resourceURL}
* (typically a file: or jar: URL). The assets are served at URIs rooted at {@code uriPath}. For
* example, given a {@code resourceURL} of {@code "file:/data/assets"} and a {@code uriPath} of
* {@code "/js"}, an {@code AssetServlet} would serve the contents of {@code
* /data/assets/example.js} in response to a request for {@code /js/example.js}. If a directory
* is requested and {@code indexFile} is defined, then {@code AssetServlet} will attempt to
* serve a file with that name in that directory. If a directory is requested and {@code
* indexFile} is null, it will serve a 404.
*
* @param resourcePathToUriPathMapping A mapping from base URL's from which assets are loaded to
* the URI path fragment in which the requests for that asset
* are rooted
* @param indexFile the filename to use when directories are requested, or null
* to serve no indexes
* @param defaultCharset the default character set
* @param spec the CacheBuilderSpec to use
* @param overrides the path overrides
* @param mimeTypes the mimeType overrides
*/
public AssetServlet(Iterable<Map.Entry<String, String>> resourcePathToUriPathMapping,
String indexFile,
Charset defaultCharset,
CacheBuilderSpec spec,
Iterable<Map.Entry<String, String>> overrides,
Iterable<Map.Entry<String, String>> mimeTypes) {
this.defaultCharset = defaultCharset;
AssetLoader loader = new AssetLoader(resourcePathToUriPathMapping, indexFile, overrides);
CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.from(spec);
// Don't add the weigher if we are using maximumSize instead of maximumWeight.
if (spec.toParsableString().contains("maximumWeight=")) {
cacheBuilder.weigher(new AssetSizeWeigher());
}
this.cache = cacheBuilder.build(loader);
this.cacheSpec = spec;
this.mimeTypes = new MimeTypes();
this.setMimeTypes(mimeTypes);
}
示例6: WandoraWebAppServer
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
public WandoraWebAppServer(Wandora wandora){
this.wandora=wandora;
jettyServer=new Server();
Options options=wandora.getOptions();
readOptions(options);
requestHandler=new JettyHandler();
mimeTypes=new MimeTypes();
webApps=new HashMap<String,WandoraWebApp>();
ArrayList<WandoraWebApp> apps=scanWebApps();
for(WandoraWebApp app : apps){
webApps.put(app.getName(),app);
}
}
示例7: mediaTypesAndExpectedStatuses
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
@DataProvider
public Object[][] mediaTypesAndExpectedStatuses() {
return new Object[][] { new Object[] { MediaType.ALL_VALUE, MockMvcResultMatchers.status().isOk() },
{ MediaType.APPLICATION_JSON_VALUE, MockMvcResultMatchers.status().isOk() },
{ MimeTypes.Type.APPLICATION_JSON_UTF_8.toString(), MockMvcResultMatchers.status().isOk() },
{ MediaType.APPLICATION_JSON_VALUE + ", application/*+json", MockMvcResultMatchers.status().isOk() },
{ MediaType.TEXT_PLAIN_VALUE, MockMvcResultMatchers.status().isOk() },
{ MimeTypes.Type.TEXT_PLAIN_UTF_8.toString(), MockMvcResultMatchers.status().isOk() },
{ "text/*+plain, " + MediaType.TEXT_PLAIN_VALUE, MockMvcResultMatchers.status().isOk() },
{ "fake/type, " + MediaType.TEXT_PLAIN_VALUE, MockMvcResultMatchers.status().isOk() },
{ "fake/type", MockMvcResultMatchers.status().isNotAcceptable() } };
}
示例8: handle
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
connection.getRequest().setHandled(true);
response.setContentType(MimeTypes.TEXT_PLAIN_8859_1);
ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
writer.write(request.getAttribute(Dispatcher.ERROR_STATUS_CODE) + " " +
request.getAttribute(Dispatcher.ERROR_MESSAGE) + " " +
request.getAttribute(Dispatcher.ERROR_REQUEST_URI));
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
}
示例9: getMimeTypeConfiguration
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
/**
* Create a configuration object that adds mime type mappings.
* @return a configuration object for adding mime type mappings
*/
private Configuration getMimeTypeConfiguration() {
return new AbstractConfiguration() {
@Override
public void configure(WebAppContext context) throws Exception {
MimeTypes mimeTypes = context.getMimeTypes();
for (MimeMappings.Mapping mapping : getMimeMappings()) {
mimeTypes.addMimeMapping(mapping.getExtension(),
mapping.getMimeType());
}
}
};
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:JettyEmbeddedServletContainerFactory.java
示例10: writeFile
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
protected Object writeFile(String suggestedFilename, CSVSerializer extractor, Response response) throws Exception {
response.type(MimeTypes.Type.TEXT_PLAIN.name());
response.header("Content-disposition", "attachment; filename="+suggestedFilename);
StringWriter bodyWriter = new StringWriter();
CsvPreference csvPreference = CsvPreference.EXCEL_PREFERENCE;
CsvListWriter csvWriter = new CsvListWriter(bodyWriter, csvPreference);
csvWriter.write("sep=" + Character.toString((char) csvPreference.getDelimiterChar()));
extractor.accept(csvWriter);
csvWriter.flush();
return bodyWriter.toString();
}
示例11: getMimeTypeConfiguration
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
/**
* Create a configuration object that adds mime type mappings.
* @return a configuration object for adding mime type mappings
*/
private Configuration getMimeTypeConfiguration() {
return new AbstractConfiguration() {
@Override
public void configure(WebAppContext context) throws Exception {
MimeTypes mimeTypes = context.getMimeTypes();
for (MimeMappings.Mapping mapping : getMimeMappings()) {
mimeTypes.addMimeMapping(mapping.getExtension(),
mapping.getMimeType());
}
}
};
}
示例12: servesCharset
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
@Test
public void servesCharset() throws Exception {
response = makeRequest(DUMMY_SERVLET + "example.txt");
assertThat(response.getStatus())
.isEqualTo(200);
assertThat(MimeTypes.CACHE.get(response.get(HttpHeader.CONTENT_TYPE)))
.isEqualTo(MimeTypes.Type.TEXT_PLAIN_UTF_8);
response = makeRequest(NOCHARSET_SERVLET + "example.txt");
assertThat(response.getStatus())
.isEqualTo(200);
assertThat(response.get(HttpHeader.CONTENT_TYPE))
.isEqualTo(MimeTypes.Type.TEXT_PLAIN.toString());
}
开发者ID:dropwizard-bundles,项目名称:dropwizard-configurable-assets-bundle,代码行数:15,代码来源:AssetServletTest.java
示例13: guessesMimeTypes
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
@Test
public void guessesMimeTypes() throws Exception {
response = makeRequest();
assertThat(response.getStatus())
.isEqualTo(200);
assertThat(MimeTypes.CACHE.get(response.get(HttpHeader.CONTENT_TYPE)))
.isEqualTo(MimeTypes.Type.TEXT_PLAIN_UTF_8);
}
开发者ID:dropwizard-bundles,项目名称:dropwizard-configurable-assets-bundle,代码行数:9,代码来源:AssetServletTest.java
示例14: defaultsToHtml
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
@Test
public void defaultsToHtml() throws Exception {
response = makeRequest(DUMMY_SERVLET + "foo.bar");
assertThat(response.getStatus())
.isEqualTo(200);
assertThat(MimeTypes.CACHE.get(response.get(HttpHeader.CONTENT_TYPE)))
.isEqualTo(MimeTypes.Type.TEXT_HTML_UTF_8);
}
开发者ID:dropwizard-bundles,项目名称:dropwizard-configurable-assets-bundle,代码行数:9,代码来源:AssetServletTest.java
示例15: fetchTransform
import org.eclipse.jetty.http.MimeTypes; //导入依赖的package包/类
protected JSONArray fetchTransform(HttpRequestEntity request)
throws IOException {
String transformURI = getSingleParameter(TRANSFORM_PARAMETER,
request.getRequest());
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
try {
HttpGet get = new HttpGet(transformURI);
get.addHeader("Accept", "application/json");
client = HttpClients.createDefault();
response = performRequest(get, client);
HttpEntity responseEntity = response.getEntity();
if (responseEntity == null) {
// TODO proper error reporting
throw new IOException("Could not GET transform JSON from "
+ transformURI + ".");
}
String encoding = null;
if (responseEntity.getContentType() != null) {
encoding = MimeTypes.getCharsetFromContentType(responseEntity.getContentType().getValue());
}
String transform = IOUtils.toString(responseEntity.getContent(),
encoding == null ? "UTF-8" : encoding);
return ParsingUtilities.evaluateJsonStringToArray(transform);
} finally {
IOUtils.closeQuietly(response);
IOUtils.closeQuietly(client);
}
}