本文整理汇总了Java中org.eclipse.jetty.http.HttpMethods类的典型用法代码示例。如果您正苦于以下问题:Java HttpMethods类的具体用法?Java HttpMethods怎么用?Java HttpMethods使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpMethods类属于org.eclipse.jetty.http包,在下文中一共展示了HttpMethods类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: handle
import org.eclipse.jetty.http.HttpMethods; //导入依赖的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();
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:PlainTextErrorHandler.java
示例2: doFilter
import org.eclipse.jetty.http.HttpMethods; //导入依赖的package包/类
@Test
public void doFilter() throws Exception {
HttpServletRequest req = mock(HttpServletRequest.class);
final String path = "/foo/bar/baz/bang/zilch/zip/nada";
when(req.getRequestURI()).thenReturn(path);
when(req.getMethod()).thenReturn(HttpMethods.GET);
HttpServletResponse res = mock(HttpServletResponse.class);
FilterChain c = mock(FilterChain.class);
String name = "foo";
FilterConfig cfg = mock(FilterConfig.class);
when(cfg.getInitParameter(MetricsFilter.METRIC_NAME_PARAM)).thenReturn(name);
when(cfg.getInitParameter(MetricsFilter.PATH_COMPONENT_PARAM)).thenReturn("0");
f.init(cfg);
f.doFilter(req, res, c);
verify(c).doFilter(req, res);
final Double sampleValue = CollectorRegistry.defaultRegistry.getSampleValue(name + "_count", new String[]{"path", "method"}, new String[]{path, HttpMethods.GET});
assertNotNull(sampleValue);
assertEquals(1, sampleValue, 0.0001);
}
开发者ID:prometheus,项目名称:client_java,代码行数:27,代码来源:MetricsFilterTest.java
示例3: isPreFlightRequest
import org.eclipse.jetty.http.HttpMethods; //导入依赖的package包/类
private static boolean isPreFlightRequest(Request request) {
if(HttpMethods.OPTIONS.equalsIgnoreCase(request.getMethod())) {
// If the origin does not match allowed the filter will skip anyway so don't bother checking it.
if(request.getHeader(ORIGIN_HEADER) != null &&
request.getHeader(CrossOriginFilter.ACCESS_CONTROL_REQUEST_METHOD_HEADER) != null) {
return true;
}
}
return false;
}
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:11,代码来源:CrossOriginConstraintSecurityHandler.java
示例4: testConstructor
import org.eclipse.jetty.http.HttpMethods; //导入依赖的package包/类
@Test
public void testConstructor() throws Exception {
HttpServletRequest req = mock(HttpServletRequest.class);
final String path = "/foo/bar/baz/bang";
when(req.getRequestURI()).thenReturn(path);
when(req.getMethod()).thenReturn(HttpMethods.POST);
FilterChain c = mock(FilterChain.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Thread.sleep(100);
return null;
}
}).when(c).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
MetricsFilter constructed = new MetricsFilter(
"foobar_baz_filter_duration_seconds",
"Help for my filter",
0,
null
);
constructed.init(mock(FilterConfig.class));
HttpServletResponse res = mock(HttpServletResponse.class);
constructed.doFilter(req, res, c);
final Double sum = CollectorRegistry.defaultRegistry.getSampleValue("foobar_baz_filter_duration_seconds_sum", new String[]{"path", "method"}, new String[]{path, HttpMethods.POST});
assertNotNull(sum);
assertEquals(0.1, sum, 0.01);
}
开发者ID:prometheus,项目名称:client_java,代码行数:32,代码来源:MetricsFilterTest.java
示例5: getEdmEntityContainerImpl
import org.eclipse.jetty.http.HttpMethods; //导入依赖的package包/类
@BeforeClass
public static void getEdmEntityContainerImpl() throws Exception {
EdmProvider edmProvider = mock(EdmProvider.class);
EdmImplProv edmImplProv = new EdmImplProv(edmProvider);
EntityContainerInfo containerInfo = new EntityContainerInfo().setName("Container");
when(edmProvider.getEntityContainerInfo("Container")).thenReturn(containerInfo);
edmEntityContainer = new EdmEntityContainerImplProv(edmImplProv, containerInfo);
EntitySet fooEntitySet = new EntitySet().setName("fooEntitySet");
when(edmProvider.getEntitySet("Container", "fooEntitySet")).thenReturn(fooEntitySet);
ReturnType fooReturnType = new ReturnType().setTypeName(EdmSimpleTypeKind.String.getFullQualifiedName()).setMultiplicity(EdmMultiplicity.ONE);
List<FunctionImportParameter> parameters = new ArrayList<FunctionImportParameter>();
FunctionImportParameter parameter = new FunctionImportParameter().setName("fooParameter1").setType(EdmSimpleTypeKind.String);
parameters.add(parameter);
parameter = new FunctionImportParameter().setName("fooParameter2").setType(EdmSimpleTypeKind.String);
parameters.add(parameter);
parameter = new FunctionImportParameter().setName("fooParameter3").setType(EdmSimpleTypeKind.String);
parameters.add(parameter);
FunctionImport functionImportFoo = new FunctionImport().setName("foo").setHttpMethod(HttpMethods.GET).setReturnType(fooReturnType).setEntitySet("fooEntitySet").setParameters(parameters);
when(edmProvider.getFunctionImport("Container", "foo")).thenReturn(functionImportFoo);
edmFunctionImport = new EdmFunctionImportImplProv(edmImplProv, functionImportFoo, edmEntityContainer);
FunctionImport functionImportBar = new FunctionImport().setName("bar").setHttpMethod(HttpMethods.GET);
when(edmProvider.getFunctionImport("Container", "bar")).thenReturn(functionImportBar);
edmFunctionImportWithoutParameters = new EdmFunctionImportImplProv(edmImplProv, functionImportBar, edmEntityContainer);
}
开发者ID:SAP,项目名称:cloud-odata-java,代码行数:34,代码来源:EdmFunctionImportImplProvTest.java
示例6: handle
import org.eclipse.jetty.http.HttpMethods; //导入依赖的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.HEAD) && !method.equals(HttpMethods.GET) &&
!method.equals(HttpMethods.POST) && !method.equals(PATCH_METHOD) && !method.equals(HttpMethods.PUT) &&
!method.equals(HttpMethods.DELETE)) {
return;
}
final String message;
final ErrorCode error;
final String note;
if(response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
message = "Path not found";
if (!request.getRequestURI().contains("/v1/")) {
note = "try including /v1/ in the path";
} else {
note = null;
}
error = ErrorCode.MALFORMED_REQUEST;
} else {
if (response instanceof Response) {
note = ((Response)response).getReason();
} else {
note = null;
}
message = HttpStatus.getMessage(response.getStatus());
error = ErrorCode.INTERNAL_ERROR;
}
response.setContentType(MediaType.APPLICATION_JSON);
response.setHeader(HttpHeaders.CACHE_CONTROL, getCacheControl());
StringBuilder builder = new StringBuilder();
RestResponseBuilder.formatJsonError(builder, error.getFormattedValue(), message, note);
builder.append('\n');
response.setContentLength(builder.length());
OutputStream out = response.getOutputStream();
out.write(builder.toString().getBytes());
out.close();
}
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:44,代码来源:JsonErrorHandler.java
示例7: handle
import org.eclipse.jetty.http.HttpMethods; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (!HttpMethods.GET.equals(request.getMethod())) {
response.sendError(HttpStatus.METHOD_NOT_ALLOWED_405);
baseRequest.setHandled(true);
return;
}
String pathInfo = StringUtils.stripStart(request.getPathInfo(), "/");
Uri contentUri = Uri.parse(CastServerUtil.decodeString(pathInfo));
if (CastServer.DUMP_REQUEST_HEADERS) {
StringBuilder reqlog = new StringBuilder();
reqlog.append("Serving artwork uri ").append(contentUri).append("\n Method ").append(request.getMethod());
for (Enumeration<String> names = request.getHeaderNames(); names.hasMoreElements();) {
String name = names.nextElement();
reqlog.append("\n HDR: ").append(name).append(":").append(request.getHeader(name));
}
Timber.v(reqlog.toString());
}
//TODO cast devices are smart enough to not requery on same url
//TODO need to implement more permanent etags
String etag = request.getHeader("if-none-match");
if (!StringUtils.isEmpty(etag)) {
if (contentUri.equals(mEtagCache.get(etag))) {
Timber.d("Already served artwork %s etag=%s", contentUri, etag);
response.setStatus(HttpStatus.NOT_MODIFIED_304);
response.flushBuffer();
baseRequest.setHandled(true);
return;
}
}
ParcelFileDescriptor pfd = mService.getAccessor().getArtwork(contentUri);
if (pfd == null) {
response.sendError(HttpStatus.NOT_FOUND_404);
baseRequest.setHandled(true);
return;
}
response.setStatus(HttpStatus.OK_200);
//will yield unique etags for this session TODO permanent etags
etag = UUID.randomUUID().toString();
mEtagCache.put(etag, contentUri);
response.setHeader("Etag", etag);
response.setContentType("image/*");
response.setContentLength((int)pfd.getStatSize());
AssetFileDescriptor afd = new AssetFileDescriptor(pfd, 0, pfd.getStatSize());
InputStream in = afd.createInputStream();
try {
//XXX out need not be closed
OutputStream out = response.getOutputStream();
IOUtils.copy(in, out);
out.flush();
baseRequest.setHandled(true);
} finally {
IOUtils.closeQuietly(in);
}
}
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:60,代码来源:ArtHandler.java
示例8: testBucketsAndName
import org.eclipse.jetty.http.HttpMethods; //导入依赖的package包/类
@Test
public void testBucketsAndName() throws Exception {
HttpServletRequest req = mock(HttpServletRequest.class);
final String path = "/foo/bar/baz/bang";
when(req.getRequestURI()).thenReturn(path);
when(req.getMethod()).thenReturn(HttpMethods.POST);
FilterChain c = mock(FilterChain.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Thread.sleep(100);
return null;
}
}).when(c).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
final String buckets = "0.01,0.05,0.1,0.15,0.25";
FilterConfig cfg = mock(FilterConfig.class);
when(cfg.getInitParameter(MetricsFilter.BUCKET_CONFIG_PARAM)).thenReturn(buckets);
when(cfg.getInitParameter(MetricsFilter.METRIC_NAME_PARAM)).thenReturn("foo");
HttpServletResponse res = mock(HttpServletResponse.class);
f.init(cfg);
f.doFilter(req, res, c);
final Double sum = CollectorRegistry.defaultRegistry.getSampleValue("foo_sum", new String[]{"path", "method"}, new String[]{"/foo", HttpMethods.POST});
assertEquals(0.1, sum, 0.01);
final Double le05 = CollectorRegistry.defaultRegistry.getSampleValue("foo_bucket", new String[]{"path", "method", "le"}, new String[]{"/foo", HttpMethods.POST, "0.05"});
assertNotNull(le05);
assertEquals(0, le05, 0.01);
final Double le15 = CollectorRegistry.defaultRegistry.getSampleValue("foo_bucket", new String[]{"path", "method", "le"}, new String[]{"/foo", HttpMethods.POST, "0.15"});
assertNotNull(le15);
assertEquals(1, le15, 0.01);
final Enumeration<Collector.MetricFamilySamples> samples = CollectorRegistry.defaultRegistry.metricFamilySamples();
Collector.MetricFamilySamples sample = null;
while(samples.hasMoreElements()) {
sample = samples.nextElement();
if (sample.name.equals("foo")) {
break;
}
}
assertNotNull(sample);
int count = 0;
for (Collector.MetricFamilySamples.Sample s : sample.samples) {
if (s.name.equals("foo_bucket")) {
count++;
}
}
// +1 because of the final le=+infinity bucket
assertEquals(buckets.split(",").length+1, count);
}
开发者ID:prometheus,项目名称:client_java,代码行数:59,代码来源:MetricsFilterTest.java
示例9: functionImport
import org.eclipse.jetty.http.HttpMethods; //导入依赖的package包/类
@Test
public void functionImport() throws Exception {
assertEquals("foo", edmFunctionImport.getName());
assertEquals(HttpMethods.GET, edmFunctionImport.getHttpMethod());
}
开发者ID:SAP,项目名称:cloud-odata-java,代码行数:7,代码来源:EdmFunctionImportImplProvTest.java
示例10: init
import org.eclipse.jetty.http.HttpMethods; //导入依赖的package包/类
@Test
public void init() throws Exception {
FilterConfig cfg = mock(FilterConfig.class);
when(cfg.getInitParameter(anyString())).thenReturn(null);
String metricName = "foo";
when(cfg.getInitParameter(MetricsFilter.METRIC_NAME_PARAM)).thenReturn(metricName);
when(cfg.getInitParameter(MetricsFilter.PATH_COMPONENT_PARAM)).thenReturn("4");
f.init(cfg);
assertEquals(f.pathComponents, 4);
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getRequestURI()).thenReturn("/foo/bar/baz/bang/zilch/zip/nada");
when(req.getMethod()).thenReturn(HttpMethods.GET);
HttpServletResponse res = mock(HttpServletResponse.class);
FilterChain c = mock(FilterChain.class);
f.doFilter(req, res, c);
verify(c).doFilter(req, res);
final Double sampleValue = CollectorRegistry.defaultRegistry.getSampleValue(metricName + "_count", new String[]{"path", "method"}, new String[]{"/foo/bar/baz/bang", HttpMethods.GET});
assertNotNull(sampleValue);
assertEquals(1, sampleValue, 0.0001);
}
开发者ID:prometheus,项目名称:client_java,代码行数:31,代码来源:MetricsFilterTest.java
注:本文中的org.eclipse.jetty.http.HttpMethods类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论