本文整理匯總了Java中org.eclipse.jetty.server.Response類的典型用法代碼示例。如果您正苦於以下問題:Java Response類的具體用法?Java Response怎麽用?Java Response使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Response類屬於org.eclipse.jetty.server包,在下文中一共展示了Response類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: putHeaders
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
@Override
protected void putHeaders(HttpServletResponse response, HttpContent content, long contentLength) {
super.putHeaders(response, content, contentLength);
HttpFields fields = ((Response) response).getHttpFields();
if (requestHolder.get().getDispatcherType() == DispatcherType.ERROR) {
/*
* Do not cache error page and also makes sure that error page is not eligible for
* modification check. That is, error page will be always retrieved.
*/
fields.put(HttpHeader.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
} else if (requestHolder.get().getRequestURI().equals("/favicon.ico")) {
/*
* Make sure favicon request is cached. Otherwise, it will be requested for every
* page request.
*/
fields.put(HttpHeader.CACHE_CONTROL, "max-age=86400,public");
}
}
示例2: handle
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response_) throws IOException {
Response response = (Response) response_;
int code = response.getStatus();
String error = response.getReason() != null ? response.getReason() : "";
PrintWriter writer = response.getWriter();
if (request.getAttribute("jsonResponse") != null) {
response.setContentType("application/json; charset=utf-8");
Map<String, Object> map = new HashMap<>();
map.put("code", code);
map.put("error", error);
writer.println("" + new JSONObject(map));
} else {
response.setContentType("text/plain; charset=utf-8");
writer.println(code + " - " + error);
}
writer.flush();
baseRequest.setHandled(true);
}
示例3: stats
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
@Test
void stats() throws IOException, ServletException {
Request baseReq = mock(Request.class);
HttpChannelState s = new HttpChannelState(null){};
when(baseReq.getHttpChannelState()).thenReturn(s);
Response resp = mock(Response.class);
when(baseReq.getResponse()).thenReturn(resp);
when(resp.getContentCount()).thenReturn(772L);
handler.handle("/testUrl", baseReq, new MockHttpServletRequest(), new MockHttpServletResponse());
assertThat(registry.mustFind("jetty.requests").functionTimer().count()).isEqualTo(1L);
assertThat(registry.mustFind("jetty.responses.size").functionCounter().count()).isEqualTo(772.0);
}
示例4: putHeaders
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
protected void putHeaders(HttpServletResponse response, HttpContent content, long contentLength)
{
if (response instanceof Response)
{
Response r = (Response)response;
r.putHeaders(content, contentLength, _etags);
HttpFields f = r.getHttpFields();
if (_acceptRanges)
f.put(ACCEPT_RANGES);
if (_cacheControl != null)
f.put(_cacheControl);
}
else
{
Response.putHeaders(response, content, contentLength, _etags);
if (_acceptRanges)
response.setHeader(ACCEPT_RANGES.getName(), ACCEPT_RANGES.getValue());
if (_cacheControl != null)
response.setHeader(_cacheControl.getName(), _cacheControl.getValue());
}
}
示例5: handle
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
if ( request.getMethod().equals(METHOD_POST)) {
response.setContentType(WebContent.contentTypeTextPlain);
response.setCharacterEncoding(WebContent.charsetUTF8) ;
String reason=(response instanceof Response)?((Response)response).getReason():null;
String msg = String.format("%03d %s\n", response.getStatus(), reason) ;
response.getOutputStream().write(msg.getBytes(StandardCharsets.UTF_8)) ;
response.getOutputStream().flush() ;
baseRequest.setHandled(true);
return;
}
super.handle(target, baseRequest, request, response);
}
示例6: log
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
@Override
public void log(final Request request, final Response response) {
final AccessLogEntry accessLogEntryFromServletRequest = (AccessLogEntry) request.getAttribute(
JDiscHttpServlet.ATTRIBUTE_NAME_ACCESS_LOG_ENTRY);
final AccessLogEntry accessLogEntry;
if (accessLogEntryFromServletRequest != null) {
accessLogEntry = accessLogEntryFromServletRequest;
} else {
accessLogEntry = new AccessLogEntry();
populateAccessLogEntryFromHttpServletRequest(request, accessLogEntry);
}
final long startTime = request.getTimeStamp();
final long endTime = System.currentTimeMillis();
accessLogEntry.setTimeStamp(startTime);
accessLogEntry.setDurationBetweenRequestResponse(endTime - startTime);
accessLogEntry.setReturnedContentSize(response.getContentCount());
accessLogEntry.setStatusCode(response.getStatus());
accessLog.log(accessLogEntry);
}
示例7: validateRequest
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
@Override
public Authentication validateRequest(ServletRequest request, ServletResponse response, boolean mandatory) throws ServerAuthException {
Authentication result = super.validateRequest(request, response, mandatory);
if ((result == Authentication.UNAUTHENTICATED) &&
mandatory &&
!DeferredAuthentication.isDeferred((HttpServletResponse)response)) {
LOG.debug("SpengoAuthenticatorEx: unauthenticated -> forbidden");
try {
((HttpServletResponse)response).sendError(Response.SC_FORBIDDEN,
"negotiation failure");
}
catch (IOException ex) {
throw new ServerAuthException(ex);
}
result = Authentication.SEND_FAILURE;
}
return result;
}
示例8: handle
import org.eclipse.jetty.server.Response; //導入依賴的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()) ;
}
}
示例9: setup
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
@Before
public void setup() throws Exception {
// Create mock objects
mockLog4jContextFactory = mock(Log4jContextFactory.class);
whenNew(Log4jContextFactory.class).withNoArguments().thenReturn(mockLog4jContextFactory);
mockLoggerContext = mock(LoggerContext.class);
mockLogger = mock(Logger.class);
when(mockLog4jContextFactory.getContext(anyString(), any(ClassLoader.class), any(), anyBoolean(), any(URI.class), anyString())).thenReturn(mockLoggerContext);
when(mockLoggerContext.getRootLogger()).thenReturn(mockLogger);
mockRequest = mock(Request.class);
mockResponse = mock(Response.class);
mockAccessLog = mock(AccessLog.class);
whenNew(AccessLog.class).withArguments(mockRequest, mockResponse).thenReturn(mockAccessLog);
// Create actual objects
enabledSupplier = () -> true;
disabledSupplier = () -> false;
failedAccessLog = new TestLog4JAccessLog(NON_EXISTING_FILE_PATH, enabledSupplier);
String filePath = getClass().getClassLoader().getResource(ACCESS_CONFIG_FILE_PATH).getPath();
enabledAccessLog = new TestLog4JAccessLog(filePath, enabledSupplier);
disabledAccessLog = new TestLog4JAccessLog(filePath, disabledSupplier);
}
示例10: logExtended
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
protected void logExtended(Request request,
Response response,
Writer writer) throws IOException
{
String referer = request.getHeader(HttpHeaders.REFERER);
if (referer == null)
writer.write("\"-\" ");
else
{
writer.write('"');
writer.write(referer);
writer.write("\" ");
}
String agent = request.getHeader(HttpHeaders.USER_AGENT);
if (agent == null)
writer.write("\"-\" ");
else
{
writer.write('"');
writer.write(agent);
writer.write('"');
}
}
示例11: runRequest
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
/**
* Fire one request at the security handler (and by extension to the AuthServlet behind it).
*
* @param path The path to hit.
* @param request The request object to use.
* @param response The response object to use. Must be created by Mockito.mock()
* @return Any data written to response.getWriter()
* @throws IOException
* @throws ServletException
*/
private String runRequest(String path, Request request, Response response)
throws IOException, ServletException {
//request.setMethod(/*HttpMethod.GET,*/ "GET");
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path);
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
// request.setServerName(SERVER_NAME);
// request.setAuthority(SERVER_NAME,9999);
//// request.setPathInfo(path);
//// request.setURIPathQuery(path);
request.setDispatcherType(DispatcherType.REQUEST);
doReturn(response).when(request).getResponse();
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (PrintWriter writer = new PrintWriter(output)) {
when(response.getWriter()).thenReturn(writer);
securityHandler.handle(path, request, request, response);
}
return new String(output.toByteArray());
}
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:33,代碼來源:AppEngineAuthenticationTest.java
示例12: runRequest2
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
private String runRequest2(String path, Request request, Response response)
throws IOException, ServletException {
//request.setMethod(/*HttpMethod.GET,*/ "GET");
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path);
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
// request.setMetaData(metadata);
// request.setServerName(SERVER_NAME);
// request.setAuthority(SERVER_NAME,9999);
//// request.setPathInfo(path);
//// request.setURIPathQuery(path);
request.setDispatcherType(DispatcherType.REQUEST);
doReturn(response).when(request).getResponse();
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (PrintWriter writer = new PrintWriter(output)) {
when(response.getWriter()).thenReturn(writer);
securityHandler.handle(path, request, request, response);
}
return new String(output.toByteArray());
}
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:23,代碼來源:AppEngineAuthenticationTest.java
示例13: testUserRequired_NoUser
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
public void testUserRequired_NoUser() throws Exception {
String path = "/user/blah";
Request request = spy(new Request(null, null));
//request.setServerPort(9999);
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path);
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
// request.setAuthority(SERVER_NAME,9999);
Response response = mock(Response.class);
String output = runRequest(path, request, response);
// Verify that the servlet never was run (there is no output).
assertEquals("", output);
// Verify that the request was redirected to the login url.
String loginUrl = UserServiceFactory.getUserService()
.createLoginURL(String.format("http://%s%s", SERVER_NAME + ":9999", path));
verify(response).sendRedirect(loginUrl);
}
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:19,代碼來源:AppEngineAuthenticationTest.java
示例14: testUserRequired_PreserveQueryParams
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
public void testUserRequired_PreserveQueryParams() throws Exception {
String path = "/user/blah";
Request request = new Request(null, null);
// request.setServerPort(9999);
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path,"foo=baqr","foo=bar","foo=barff");
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
MultiMap<String> queryParameters = new MultiMap<> ();
queryParameters.add("ffo", "bar");
request.setQueryParameters(queryParameters);
request = spy(request);
/// request.setAuthority(SERVER_NAME,9999);
request.setQueryString("foo=bar");
Response response = mock(Response.class);
String output = runRequest2(path, request, response);
// Verify that the servlet never was run (there is no output).
assertEquals("", output);
// Verify that the request was redirected to the login url.
String loginUrl = UserServiceFactory.getUserService()
.createLoginURL(String.format("http://%s%s?foo=bar", SERVER_NAME + ":9999", path));
verify(response).sendRedirect(loginUrl);
}
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:26,代碼來源:AppEngineAuthenticationTest.java
示例15: testAdminRequired_NoUser
import org.eclipse.jetty.server.Response; //導入依賴的package包/類
public void testAdminRequired_NoUser() throws Exception {
String path = "/admin/blah";
Request request = spy(new Request(null, null));
//request.setServerPort(9999);
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path);
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
// request.setAuthority(SERVER_NAME,9999);
Response response = mock(Response.class);
String output = runRequest(path, request, response);
// Verify that the servlet never was run (there is no output).
assertEquals("", output);
// Verify that the request was redirected to the login url.
String loginUrl = UserServiceFactory.getUserService()
.createLoginURL(String.format("http://%s%s", SERVER_NAME + ":9999", path));
verify(response).sendRedirect(loginUrl);
}
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:19,代碼來源:AppEngineAuthenticationTest.java