本文整理汇总了Java中org.glassfish.grizzly.http.server.Response.finish方法的典型用法代码示例。如果您正苦于以下问题:Java Response.finish方法的具体用法?Java Response.finish怎么用?Java Response.finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.http.server.Response
的用法示例。
在下文中一共展示了Response.finish方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: service
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response)
throws Exception {
final String query = request.getQueryString();
String path = request.getPathInfo();
if (path == null) path = "/";
log.info("Checking path \"%s\" against %d redirects", path, redirects.size());
for (Redirect redirect: redirects) {
final String location = redirect.apply(path, query);
if (location != null) {
response.setStatus(redirect.status);
response.setHeader(Header.Location, location);
response.finish();
return;
}
}
response.setStatus(NOT_FOUND_404);
response.finish();
}
示例2: setResponse
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Writes data to response.
*
* @param response
* @param text
* @param status
* @param contentType
*/
protected void setResponse(final Response response, final String data, final int status,
final String contentType) {
response.setContentType(contentType);
response.setCharacterEncoding("utf-8");
response.setStatus(status);
final byte[] bytes = data.getBytes();
try {
response.setContentLength(bytes.length);
response.getWriter().write(data);
} catch (final IOException e) {
LOG.error("\n", e);
}
response.finish();
}
示例3: setResponse
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Writes data to response.
*
* @param response
* @param text
* @param status
* @param contentType
*/
protected void setResponse(final Response response, final String data, final int status,
final String contentType) {
response.setContentType(contentType);
response.setCharacterEncoding("utf-8");
response.setStatus(status);
final byte[] bytes = data.getBytes();
try {
response.setContentLength(bytes.length);
response.getWriter().write(data);
} catch (final IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
response.finish();
}
示例4: sendError
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void sendError(final Response response, final int status) {
try {
response.sendError(status);
} catch (final IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
response.finish();
}
示例5: Server
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
public Server(PropertiesConfiguration properties) throws IOException {
m_properties = properties;
m_httpServer = new HttpServer();
int port = properties.getInt(PROPERTY_PORT, DEFAULT_PORT);
String host = properties.getString(PROPERTY_HOST, DEFAULT_HOST);
final NetworkListener networkListener = new NetworkListener(
NET_LISTENER_NAME,
host,
port);
// Enable SSL on the listener
networkListener.setSecure(true);
networkListener.setSSLEngineConfig(makeSSLConfig(m_properties));
CompressionConfig compressionConfig =
networkListener.getCompressionConfig();
compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); // the mode
compressionConfig.setCompressionMinSize(100); // the min amount of bytes to compress
compressionConfig.setCompressableMimeTypes("text/plain", "text/html", "application/x-protobuf", "application/pdf"); // the mime types to compress
m_httpServer.addListener(networkListener);
// Create a concurrent, nonblocking, asynchronous, batching JPA-based store for persistence
// of request data. Async is OK, as persistence failures do not need to be handled by the client.
m_store = new JPABatchStore(ConfigurationConverter.getMap(m_properties));
m_batchPersister = new AsyncConcurrentBatchingProcessor<PersistEntityEvent>(
m_store,
PersistEntityEvent::new,
PersistEntityEvent::translate
);
final ServerConfiguration config = m_httpServer.getServerConfiguration();
config.setMaxPostSize(MAX_POST_SIZE);
AsyncPostHandler.ErrorHandler errorHandler =
(ByteBuffer postBytes, Response resp, Throwable t) -> {
LogManager.getLogger(this).warn("Invalid submission.", t);
resp.sendError(300);
resp.finish();
};
AsyncPostHandler certHandler =
new AsyncPostHandler(new CertificateHandler(m_batchPersister, CERT_TEMPLATE_PATH, errorHandler),
errorHandler);
AsyncPostHandler versionHandler =
new AsyncPostHandler(new VersionCheckHandler(m_batchPersister, properties), errorHandler);
config.addHttpHandler(certHandler, PATH_SUBMIT);
config.addHttpHandler(versionHandler, PATH_VERSION_CHECK);
}