本文整理了Java中org.eclipse.jetty.server.Response
类的一些代码示例,展示了Response
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response
类的具体详情如下:
包路径:org.eclipse.jetty.server.Response
类名称:Response
[英]Response provides the implementation for HttpServletResponse.
[中]Response提供了HttpServletResponse的实现。
代码示例来源:origin: neo4j/neo4j
@Override
public void log( Request request, Response response )
{
// Trying to replicate this logback pattern:
// %h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] "%r" %s %b "%i{Referer}" "%i{User-Agent}" %D
String remoteHost = swallowExceptions( request, HttpServletRequest::getRemoteHost );
String user = swallowExceptions( request, HttpServletRequest::getRemoteUser );
String requestURL = swallowExceptions( request, HttpServletRequest::getRequestURI ) + "?" +
swallowExceptions( request, HttpServletRequest::getQueryString );
int statusCode = response.getStatus();
long length = response.getContentLength();
String referer = swallowExceptions( request, r -> r.getHeader( "Referer" ) );
String userAgent = swallowExceptions( request, r -> r.getHeader( "User-Agent" ) );
long requestTimeStamp = request != null ? request.getTimeStamp() : -1;
long now = System.currentTimeMillis();
long serviceTime = requestTimeStamp < 0 ? -1 : now - requestTimeStamp;
log.info( "%s - %s [%tc] \"%s\" %s %s \"%s\" \"%s\" %s",
defaultString( remoteHost ),
defaultString( user ),
now,
defaultString( requestURL ),
statusCode,
length,
defaultString( referer ),
defaultString( userAgent ),
serviceTime );
}
代码示例来源:origin: gocd/gocd
@Override
public long getContentCount() {
return ((Response) servletResponse).getContentCount();
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotAddHstsHeaderWhenNotConfigured()
{
Customizer customizer = newCustomizer();
Request request = newRequest();
customize( customizer, request );
String hstsValue = request.getResponse().getHttpFields().get( STRICT_TRANSPORT_SECURITY );
assertNull( hstsValue );
}
代码示例来源:origin: jooby-project/jooby
@Override
protected void handshake(final Runnable handler) throws Exception {
/** Infinite timeout because the continuation is never resumed but only completed on close. */
req.getAsyncContext().setTimeout(0L);
/** Server sent events headers. */
rsp.setStatus(HttpServletResponse.SC_OK);
rsp.setHeader("Connection", "Close");
rsp.setContentType("text/event-stream; charset=utf-8");
rsp.flushBuffer();
HttpChannel channel = rsp.getHttpChannel();
Connector connector = channel.getConnector();
Executor executor = connector.getExecutor();
executor.execute(handler);
}
代码示例来源:origin: jersey/jersey
@Override
public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context)
throws ContainerException {
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
final int code = statusInfo.getStatusCode();
final String reason = statusInfo.getReasonPhrase() == null
? HttpStatus.getMessage(code) : statusInfo.getReasonPhrase();
response.setStatusWithReason(code, reason);
if (contentLength != -1 && contentLength < Integer.MAX_VALUE) {
response.setContentLength((int) contentLength);
}
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
for (final String value : e.getValue()) {
response.addHeader(e.getKey(), value);
}
}
try {
return response.getOutputStream();
} catch (final IOException ioe) {
throw new ContainerException("Error during writing out the response headers.", ioe);
}
}
代码示例来源:origin: org.eclipse.jetty/jetty-security
Request base_request = Request.getBaseRequest(request);
Response base_response = base_request.getResponse();
String uri = request.getRequestURI();
if (uri==null)
uri=URIUtil.SLASH;
return new DeferredAuthentication(this);
if (isLoginOrErrorPage(URIUtil.addPaths(request.getServletPath(),request.getPathInfo())) &&!DeferredAuthentication.isDeferred(response))
return new DeferredAuthentication(this);
LOG.debug("authenticated {}->{}",form_auth,nuri);
int redirectCode = (base_request.getHttpVersion().getVersion() < HttpVersion.HTTP_1_1.getVersion() ? HttpServletResponse.SC_MOVED_TEMPORARILY : HttpServletResponse.SC_SEE_OTHER);
base_response.sendRedirect(redirectCode, response.encodeRedirectURL(nuri));
return form_auth;
LOG.debug("auth failed {}->{}",username,_formErrorPage);
int redirectCode = (base_request.getHttpVersion().getVersion() < HttpVersion.HTTP_1_1.getVersion() ? HttpServletResponse.SC_MOVED_TEMPORARILY : HttpServletResponse.SC_SEE_OTHER);
base_response.sendRedirect(redirectCode, response.encodeRedirectURL(URIUtil.addPaths(request.getContextPath(),_formErrorPage)));
LOG.debug("challenge {}->{}",session.getId(),_formLoginPage);
int redirectCode = (base_request.getHttpVersion().getVersion() < HttpVersion.HTTP_1_1.getVersion() ? HttpServletResponse.SC_MOVED_TEMPORARILY : HttpServletResponse.SC_SEE_OTHER);
base_response.sendRedirect(redirectCode, response.encodeRedirectURL(URIUtil.addPaths(request.getContextPath(),_formLoginPage)));
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
String method = request.getMethod();
if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD))
connection.getRequest().setHandled(true);
return;
if (error_page!=null && request.getServletContext()!=null)
String old_error_page=(String)request.getAttribute(ERROR_PAGE);
if (old_error_page==null || !old_error_page.equals(error_page))
return;
LOG.warn("No error page "+error_page);
LOG.warn(Log.EXCEPTION, e);
return;
connection.getRequest().setHandled(true);
response.setContentType(MimeTypes.TEXT_HTML_8859_1);
if (_cacheControl!=null)
response.setHeader(HttpHeaders.CACHE_CONTROL, _cacheControl);
ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
handleErrorPage(request, writer, connection.getResponse().getStatus(), connection.getResponse().getReason());
writer.flush();
response.setContentLength(writer.size());
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
String method = request.getMethod();
if (!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method))
baseRequest.setHandled(true);
return;
if (error_page!=null && request.getServletContext()!=null)
String old_error_page=(String)request.getAttribute(ERROR_PAGE);
if (old_error_page==null || !old_error_page.equals(error_page))
return;
LOG.warn("No error page "+error_page);
if (LOG.isDebugEnabled())
LOG.debug("No Error Page mapping for request({} {}) (using default)",request.getMethod(),request.getRequestURI());
baseRequest.setHandled(true);
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(4096);
String reason = (response instanceof Response) ? ((Response) response).getReason() : null;
handleErrorPage(request, writer, response.getStatus(), reason);
writer.flush();
代码示例来源:origin: cdapio/cdap
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
String requestLine = request.getMethod() + " " + request.getRequestURI() + " " + request.getProtocol();
AuditLogEntry logEntry = new AuditLogEntry(requestLine, request.getRemoteUser(),
InetAddress.getByName(request.getRemoteAddr()).getHostAddress(),
Collections.<String, String>emptyMap());
logEntry.setResponse(response.getStatus(), ((Response) response).getContentCount());
logger.trace(logEntry.toString());
}
}
代码示例来源:origin: org.apache.maven.wagon/wagon-provider-test
@Override
public void handle( String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response ) throws IOException, ServletException
{
String method = request.getMethod();
super.handle( target, baseRequest, request, response );
handlerRequestResponses.add(
new HandlerRequestResponse( method, ( (Response) response ).getStatus(), request.getRequestURI() ) );
}
}
代码示例来源:origin: apache/jena
@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()) ;
response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store");
response.setHeader(HttpNames.hPragma, "no-cache");
int code = response.getStatus() ;
String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ;
response.getOutputStream().print(format("Error %d: %s\n", code, message)) ;
}
}
代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
baseRequest.setHandled(true);
String method = request.getMethod();
if(!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method))
return;
response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
if (_cacheControl!=null)
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
String reason=(response instanceof Response)?((Response)response).getReason():null;
handleErrorPage(request, writer, response.getStatus(), reason);
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server
public void handleAsync(HttpChannel connection) throws IOException, ServletException
{
final HttpChannelState state = connection.getRequest().getHttpChannelState();
final AsyncContextEvent event = state.getAsyncContextEvent();
final Request baseRequest=connection.getRequest();
final String path=event.getPath();
if (path!=null)
{
// this is a dispatch with a path
ServletContext context=event.getServletContext();
String query=baseRequest.getQueryString();
baseRequest.setURIPathQuery(URIUtil.addPaths(context==null?null:context.getContextPath(), path));
HttpURI uri = baseRequest.getHttpURI();
baseRequest.setPathInfo(uri.getDecodedPath());
if (uri.getQuery()!=null)
baseRequest.mergeQueryParameters(query,uri.getQuery(), true); //we have to assume dispatch path and query are UTF8
}
final String target=baseRequest.getPathInfo();
final HttpServletRequest request=(HttpServletRequest)event.getSuppliedRequest();
final HttpServletResponse response=(HttpServletResponse)event.getSuppliedResponse();
if (LOG.isDebugEnabled())
{
LOG.debug(request.getDispatcherType()+" "+request.getMethod()+" "+target+" on "+connection);
handle(target, baseRequest, request, response);
LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
}
else
handle(target, baseRequest, request, response);
}
代码示例来源:origin: Nextdoor/bender
public void handleAsync(HttpChannel<?> connection) throws IOException, ServletException
{
final HttpChannelState state = connection.getRequest().getHttpChannelState();
final AsyncContextEvent event = state.getAsyncContextEvent();
final Request baseRequest=connection.getRequest();
final String path=event.getPath();
if (path!=null)
{
// this is a dispatch with a path
ServletContext context=event.getServletContext();
HttpURI uri = new HttpURI(URIUtil.addPaths(context==null?null:context.getContextPath(), path));
baseRequest.setUri(uri);
baseRequest.setRequestURI(null);
baseRequest.setPathInfo(uri.getDecodedPath());
if (uri.getQuery()!=null)
baseRequest.mergeQueryParameters(uri.getQuery(), true); //we have to assume dispatch path and query are UTF8
}
final String target=baseRequest.getPathInfo();
final HttpServletRequest request=(HttpServletRequest)event.getSuppliedRequest();
final HttpServletResponse response=(HttpServletResponse)event.getSuppliedResponse();
if (LOG.isDebugEnabled())
{
LOG.debug(request.getDispatcherType()+" "+request.getMethod()+" "+target+" on "+connection);
handle(target, baseRequest, request, response);
LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
}
else
handle(target, baseRequest, request, response);
}
代码示例来源:origin: org.eclipse.jetty/server
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
connection.getRequest().setHandled(true);
String method = request.getMethod();
if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD))
return;
response.setContentType(MimeTypes.TEXT_HTML_8859_1);
if (_cacheControl!=null)
response.setHeader(HttpHeaders.CACHE_CONTROL, _cacheControl);
ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
handleErrorPage(request, writer, connection.getResponse().getStatus(), connection.getResponse().getReason());
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-server
public void handleAsync(AbstractHttpConnection connection) throws IOException, ServletException
{
final AsyncContinuation async = connection.getRequest().getAsyncContinuation();
final AsyncContinuation.AsyncEventState state = async.getAsyncEventState();
final Request baseRequest=connection.getRequest();
final String path=state.getPath();
if (path!=null)
{
// this is a dispatch with a path
final String contextPath=state.getServletContext().getContextPath();
HttpURI uri = new HttpURI(URIUtil.addPaths(contextPath,path));
baseRequest.setUri(uri);
baseRequest.setRequestURI(null);
baseRequest.setPathInfo(baseRequest.getRequestURI());
if (uri.getQuery()!=null)
baseRequest.mergeQueryString(uri.getQuery()); //we have to assume dispatch path and query are UTF8
}
final String target=baseRequest.getPathInfo();
final HttpServletRequest request=(HttpServletRequest)async.getRequest();
final HttpServletResponse response=(HttpServletResponse)async.getResponse();
if (LOG.isDebugEnabled())
{
LOG.debug("REQUEST "+target+" on "+connection);
handle(target, baseRequest, request, response);
LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
}
else
handle(target, baseRequest, request, response);
}
代码示例来源:origin: org.fabric3/fabric3-jetty
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (!request.isSecure()) {
baseRequest.getResponse().sendRedirect("https://" + baseRequest.getServerName() + ":" + httpsPort + baseRequest.getPathInfo());
baseRequest.setHandled(true);
} else {
getHandler().handle(target, baseRequest, request, response);
}
}
}
代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9
return true;
HttpConfiguration httpConfig = HttpChannel.getCurrentHttpChannel().getHttpConfiguration();
if (request.isSecure())
return true;
String url = httpConfig.getSecureScheme() + "://" + request.getServerName() + ":" + httpConfig.getSecurePort()
+ request.getRequestURI();
if (request.getQueryString() != null)
url += "?" + request.getQueryString();
response.setContentLength(0);
response.sendRedirect(url);
response.sendError(HttpStatus.FORBIDDEN_403,"!Secure");
request.setHandled(true);
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public void handle(AbstractHttpConnection connection) throws IOException, ServletException
{
final String target=connection.getRequest().getPathInfo();
final Request request=connection.getRequest();
final Response response=connection.getResponse();
if (LOG.isDebugEnabled())
{
LOG.debug("REQUEST "+target+" on "+connection);
handle(target, request, request, response);
LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()+" handled="+request.isHandled());
}
else
handle(target, request, request, response);
}
代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9
public void handleAsync(HttpChannel<?> connection) throws IOException, ServletException
{
final HttpChannelState async = connection.getRequest().getHttpChannelState();
final HttpChannelState.AsyncEventState state = async.getAsyncEventState();
final Request baseRequest=connection.getRequest();
final String path=state.getPath();
if (path!=null)
{
// this is a dispatch with a path
ServletContext context=state.getServletContext();
HttpURI uri = new HttpURI(context==null?path:URIUtil.addPaths(context.getContextPath(),path));
baseRequest.setUri(uri);
baseRequest.setRequestURI(null);
baseRequest.setPathInfo(baseRequest.getRequestURI());
if (uri.getQuery()!=null)
baseRequest.mergeQueryString(uri.getQuery()); //we have to assume dispatch path and query are UTF8
}
final String target=baseRequest.getPathInfo();
final HttpServletRequest request=(HttpServletRequest)async.getRequest();
final HttpServletResponse response=(HttpServletResponse)async.getResponse();
if (LOG.isDebugEnabled())
{
LOG.debug("REQUEST "+target+" on "+connection);
handle(target, baseRequest, request, response);
LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
}
else
handle(target, baseRequest, request, response);
}
内容来源于网络,如有侵权,请联系作者删除!