本文整理汇总了Java中org.glassfish.grizzly.http.server.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于org.glassfish.grizzly.http.server包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebServer
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
public WebServer(URI endpoint) throws IOException {
this.server = GrizzlyServerFactory.createHttpServer(endpoint, new HttpHandler() {
@Override
public void service(Request rqst, Response rspns) throws Exception {
rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found");
rspns.getWriter().write("404: not found");
}
});
WebappContext context = new WebappContext("WebappContext", BASE_PATH);
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
PackagesResourceConfig.class.getName());
StringJoiner sj = new StringJoiner(",");
for (String s : PACKAGES) {
sj.add(s);
}
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, sj.toString());
registration.addMapping(BASE_PATH);
context.deploy(server);
}
示例2: service
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@Override
public void service(Request request, Response resp) throws Exception {
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html");
Writer writer = resp.getWriter();
writer.write("<html><head><title>HtmlSocket</title></head><body>");
writer.write("<h3>HtmlSocket manger</h3><hr><ul>");
int count = 0;
MessageCenter sever = ctx.getMessageCenter();
Collection<ThreadMap> allsub = sever.getSubscribers();
for (ThreadMap subs : allsub) {
for (Map.Entry<Long, ISubscriber> item : subs.entrySet()) {
if (count++ < 20) {
ISubscriber value = item.getValue();
String topic = value.getTopic();
long id = value.getId();
writer.write(String.format("<li>ID:[%s],Topic:[%s]-[%s]</li>", id, topic, value));
}
}
}
writer.write("</ul><hr>");
writer.write(String.format("订阅者[%s]", count));
writer.write("</body></html>");
}
示例3: startManagementHttpServer
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
private void startManagementHttpServer() throws Exception {
final String httpManagementServerUrl = _properties.getProperty("managementurl", HTTP_MANAGEMENTSERVER_URL);
final ResourceConfig config = new ResourceConfig().register(RaqetService.class).register(new RaqetBinder(_raqetControll));
final CLStaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(this.getClass().getClassLoader(), "/static/");
_httpManagementServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(httpManagementServerUrl), config);
_httpManagementServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/gui/");
/* Redirect users to the GUI */
_httpManagementServer.getServerConfiguration().addHttpHandler(new HttpHandler() {
@Override
public void service(final Request request, final Response response) throws Exception {
response.sendRedirect("/gui/");
}
}, "/index.html");
_httpManagementServer.start();
}
示例4: GrizzlyServerHttpExchange
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public GrizzlyServerHttpExchange(Request request, Response response) {
this.request = request;
this.response = response;
request.getContext().getConnection().addCloseListener(new CloseListener<Closeable,
ICloseType>() {
@Override
public void onClosed(Closeable closeable, ICloseType type) throws
IOException {
closeActions.fire();
}
});
// To detect closed connection
// From https://github.com/GrizzlyNIO/grizzly-mirror/blob/2_3_17/modules/comet/src/main/java
// /org/glassfish/grizzly/comet/CometContext.java#L250
request.getInputBuffer().initiateAsyncronousDataReceiving();
response.suspend();
}
示例5: service
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
for (String parameterLabel : request.getParameterMap().keySet()) {
Matcher matcher;
// matcher = ANNOTATOR_PATTERN.matcher(parameterLabel);
// if (matcher.find()) {
// annotators.add(matcher.group(1));
// }
matcher = META_PATTERN.matcher(parameterLabel);
if (matcher.find()) {
String key = matcher.group(1);
meta.put(key, request.getParameter(parameterLabel));
}
}
if (meta.get("uri") == null || meta.get("uri").length() == 0) {
meta.put("uri", pipeline.getDefaultConfig().getProperty("default_uri"));
}
}
示例6: service
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
logger.debug("Starting service");
super.service(request, response);
String naf = request.getParameter("naf");
KAFDocument doc;
try {
doc = pipeline.parseFromString(naf);
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e);
}
// File temp = File.createTempFile("temp-file-name", ".tmp");
// logger.info("Created temp file " + temp.getAbsolutePath());
// doc.save(temp);
logger.trace(doc.toString());
writeOutput(response, "text/xml", doc.toString());
}
示例7: service
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
super.service(request, response);
String naf = request.getParameter("naf");
KAFDocument document = KAFDocument.createFromStream(new StringReader(naf));
NAFFilter filter = NAFFilter.builder().withSRLRoleLinking(false, false).withOpinionLinking(false, false).build();
RDFGenerator generator = RDFGenerator.DEFAULT;
Renderer renderer = Renderer.DEFAULT;
filter.filter(document);
final Model model = generator.generate(document, null);
StringWriter writer = new StringWriter();
renderer.renderAll(writer, document, model, null, null);
String res = writer.toString();
super.writeOutput(response, "text/html", res);
}
示例8: send404
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
private void send404(Response response) {
response.setStatus(HttpStatus.NOT_FOUND_404);
response.setContentType("image/png");
try (InputStream is = this.getClass().getResourceAsStream("/404.png");
OutputStream os = response.getOutputStream();) {
byte[] b = new byte[1024];
while (is.read(b) >= 0) {
os.write(b);
}
} catch (IOException e) {
logger.error(e);
}
}
示例9: send403
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
private void send403(Response response) {
response.setStatus(HttpStatus.FORBIDDEN_403);
response.setContentType("image/png");
try (InputStream is = this.getClass().getResourceAsStream("/403.png");
OutputStream os = response.getOutputStream();) {
byte[] b = new byte[1024];
while (is.read(b) >= 0) {
os.write(b);
}
} catch (IOException e) {
logger.error(e);
}
}
示例10: handlePost
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@Override
public void handlePost(ByteBuffer postBytes, Request req, Response resp)
throws IOException {
try {
ServerStatusQuery query = ServerStatusQuery.parseFrom(ByteString.copyFrom(postBytes));
m_processor.processEvent(new PersistEntityEvent(
new ServerStatusQueryData(query, req.getRemoteAddr(), req.getRequest().getHttpHeader().toString(), new Date().getTime())));
ServerStatusResponse.Builder response = ServerStatusResponse.newBuilder();
response.setServerDate(new Date().getTime());
response.setStatusCode(getStatusCode(query));
NIOOutputStream out = resp.getNIOOutputStream();
try {
resp.setContentType(PROTOBUF_CONTENT_TYPE);
response.build().writeTo(out);
} finally {
out.close();
}
} finally {
resp.resume();
}
}
示例11: 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();
}
示例12: writeResponseStatusAndHeaders
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@Override
public OutputStream writeResponseStatusAndHeaders(final long contentLength,
final ContainerResponse context)
throws ContainerException {
try {
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
if (statusInfo.getReasonPhrase() == null) {
grizzlyResponse.setStatus(statusInfo.getStatusCode());
} else {
grizzlyResponse.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
}
grizzlyResponse.setContentLengthLong(contentLength);
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
for (final String value : e.getValue()) {
grizzlyResponse.addHeader(e.getKey(), value);
}
}
return grizzlyResponse.getOutputStream();
} finally {
logger.debugLog("{0} - writeResponseStatusAndHeaders() called", name);
}
}
示例13: handle
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@Override
protected boolean handle(String uri, Request request, Response response)
throws Exception {
String mediaId = request.getParameter(PARAM_ID);
Media media = catalogue.getMedia(mediaId);
if (media != null && media.getFile() != null) {
logger.trace("Serving up media {}", media);
pickupContentType(response, media.getFile().getPath());
sendFile(response, media.getFile());
logger.trace("Served up media {}", media);
return true;
} else {
logger.trace("Couldn't find media as referenced in request {}", uri);
return false;
}
}
示例14: 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();
}
示例15: onRequestCompleteEvent
import org.glassfish.grizzly.http.server.Response; //导入依赖的package包/类
@Override
public void onRequestCompleteEvent(final HttpServerFilter arg0,
@SuppressWarnings("rawtypes") final Connection arg1, final Response arg2) {
String path = "";
try {
path = new URL(arg2.getRequest().getRequestURL().toString()).getPath();
} catch (final MalformedURLException e) {
LOG.error(e.getLocalizedMessage(), e);
}
path = path.replaceAll("/", " ").trim();
path = path.split(" ")[0];
if (allowedpaths.contains(path)) {
// TODO: store user infos
}
}