本文整理了Java中javax.ws.rs.core.Request.getMethod
方法的一些代码示例,展示了Request.getMethod
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getMethod
方法的具体详情如下:
包路径:javax.ws.rs.core.Request
类名称:Request
方法名:getMethod
[英]Get the request method, e.g. GET, POST, etc.
[中]获取请求方法,例如Get、POST等。
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
// answer OPTIONS requests early so we don't have jersey produce WADL responses for them (we only use them for CORS preflight)
if ("options".equalsIgnoreCase(requestContext.getRequest().getMethod())) {
final Response.ResponseBuilder options = Response.noContent();
String origin = requestContext.getHeaders().getFirst("Origin");
if (origin != null && !origin.isEmpty()) {
options.header("Access-Control-Allow-Origin", origin);
options.header("Access-Control-Allow-Credentials", true);
options.header("Access-Control-Allow-Headers",
"Authorization, Content-Type, X-Graylog-No-Session-Extension, X-Requested-With, X-Requested-By");
options.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
// In order to avoid redoing the preflight thingy for every request, see http://stackoverflow.com/a/12021982/1088469
options.header("Access-Control-Max-Age", "600"); // 10 minutes seems to be the maximum allowable value
requestContext.abortWith(options.build());
}
}
}
}
代码示例来源:origin: jersey/jersey
public SparklinesResource(
@QueryParam("d") final IntegerList data,
@DefaultValue("0,100") @QueryParam("limits") final Interval limits,
@Context final Request request,
@Context final UriInfo ui) {
if (data == null) {
throw new WebApplicationException(400);
}
this.data = data;
this.limits = limits;
if (!limits.contains(data)) {
throw new WebApplicationException(400);
}
this.tag = computeEntityTag(ui.getRequestUri());
if ("GET".equals(request.getMethod())) {
final Response.ResponseBuilder rb = request.evaluatePreconditions(tag);
if (rb != null) {
throw new WebApplicationException(rb.build());
}
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
// we have already added the necessary headers for OPTIONS requests below
if ("options".equalsIgnoreCase(requestContext.getRequest().getMethod())) {
if(Response.Status.Family.familyOf(responseContext.getStatus()) == Response.Status.Family.SUCCESSFUL) {
return;
}
responseContext.setStatus(Response.Status.NO_CONTENT.getStatusCode());
responseContext.setEntity("");
}
String origin = requestContext.getHeaders().getFirst("Origin");
if (origin != null && !origin.isEmpty()) {
responseContext.getHeaders().add("Access-Control-Allow-Origin", origin);
responseContext.getHeaders().add("Access-Control-Allow-Credentials", true);
responseContext.getHeaders().add("Access-Control-Allow-Headers", "Authorization, Content-Type, X-Graylog-No-Session-Extension, X-Requested-With, X-Requested-By");
responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
// In order to avoid redoing the preflight thingy for every request, see http://stackoverflow.com/a/12021982/1088469
responseContext.getHeaders().add("Access-Control-Max-Age", "600"); // 10 minutes seems to be the maximum allowable value
}
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
@Override
public Response apply(ContainerRequestContext data) {
Map<String, Object> arguments = new HashMap<>();
if (this.readBody) {
arguments.putAll(extractBodyArguments(data));
}
arguments.putAll(extractPathParameters(data));
arguments.putAll(extractQueryParameters(data));
try {
Object response = this.operation.invoke(new InvocationContext(
new JerseySecurityContext(data.getSecurityContext()), arguments));
return convertToJaxRsResponse(response, data.getRequest().getMethod());
}
catch (InvalidEndpointRequestException ex) {
return Response.status(Status.BAD_REQUEST).build();
}
}
代码示例来源:origin: org.ow2.xlcloud/rest-utils
/** {@inheritDoc} */
@Override
public String getHttpMethod() {
return request.getMethod();
}
代码示例来源:origin: org.opendaylight.controller/sal-rest-connector
protected boolean isPost() {
return POST.equals(request.getMethod());
}
}
代码示例来源:origin: apache/cxf
public String getMethod() {
return get().getMethod();
}
代码示例来源:origin: org.apache.openejb/openejb-core
public String getMethod() {
return get().getMethod();
}
代码示例来源:origin: org.fcrepo/fcrepo-http-api
private void handleRequestDisallowedOnMemento() {
try {
addLinkAndOptionsHttpHeaders(resource());
} catch (final Exception ex) {
// Catch the exception to ensure status 405 for any requests on memento.
LOGGER.debug("Unable to add link and options headers for PATCH request to memento path {}: {}.",
externalPath, ex.getMessage());
}
LOGGER.info("Unable to handle {} request on a path containing {}. Path was: {}", request.getMethod(),
FedoraTypes.FCR_VERSIONS, externalPath);
}
代码示例来源:origin: oVirt/ovirt-engine
@Override
public Response toResponse(MappingException exception) {
log.error(
"Mapping exception while processing \"{}\" request for path \"{}\"",
request.getMethod(),
uriInfo.getPath()
);
log.error("Exception", exception);
final Fault fault = new Fault();
fault.setReason("Operation Failed");
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(fault).build();
}
}
代码示例来源:origin: org.talend.sdk.component/component-server-vault-proxy
public CompletionStage<Response> forward() {
WebTarget target = client.path(uriInfo.getPath());
for (final Map.Entry<String, List<String>> query : uriInfo.getQueryParameters().entrySet()) {
target = target.queryParam(query.getKey(), query.getValue().toArray(emptyObjectsArray));
}
final MultivaluedMap<String, String> requestHeaders = headers.getRequestHeaders();
final MediaType[] types = headers.getAcceptableMediaTypes().toArray(emptyMediaTypesArray);
final CompletionStageRxInvoker invoker =
target.request(types).headers(MultivaluedMap.class.cast(requestHeaders)).rx();
return decorate(invoker.method(request.getMethod()));
}
}
代码示例来源:origin: oVirt/ovirt-engine
@Override
public Response toResponse(MalformedIdException exception) {
log.error(
"Malformed id detected while processing \"{}\" request for path \"{}\"",
request.getMethod(),
uriInfo.getPath()
);
log.error("Exception", exception);
final Fault fault = new Fault();
fault.setReason("Operation failed");
fault.setDetail(exception.getCause().getMessage());
return Response.status(Status.BAD_REQUEST).entity(fault).build();
}
}
代码示例来源:origin: apache/cxf
@Override
public void filter(ContainerRequestContext rc) throws IOException {
if (HttpMethod.GET.equals(rc.getRequest().getMethod())) {
UriInfo ui = rc.getUriInfo();
String path = "/" + ui.getPath();
if (PATTERN.matcher(path).matches() && locator.exists(path)) {
rc.setRequestUri(URI.create("api-docs" + path));
}
}
}
}
代码示例来源:origin: oVirt/ovirt-engine
private Request mockRequest(String httpMethod) {
Request requestMock = mock(Request.class);
when(requestMock.getMethod()).thenReturn(httpMethod);
return requestMock;
}
代码示例来源:origin: org.apache.cxf/cxf-rt-rs-service-description-swagger-ui
@Override
public void filter(ContainerRequestContext rc) throws IOException {
if (HttpMethod.GET.equals(rc.getRequest().getMethod())) {
UriInfo ui = rc.getUriInfo();
String path = "/" + ui.getPath();
if (PATTERN.matcher(path).matches() && locator.exists(path)) {
rc.setRequestUri(URI.create("api-docs" + path));
}
}
}
}
代码示例来源:origin: apache/cxf
@Override
public void filter(ContainerRequestContext rc) throws IOException {
if (HttpMethod.GET.equals(rc.getRequest().getMethod())) {
UriInfo ui = rc.getUriInfo();
String path = ui.getPath();
int uiPathIndex = path.lastIndexOf("api-docs");
if (uiPathIndex >= 0) {
String resourcePath = uiPathIndex + 8 < path.length()
? path.substring(uiPathIndex + 8) : "";
rc.abortWith(uiService.getResource(ui, resourcePath));
}
}
}
}
代码示例来源:origin: org.apache.rave/rave-core-api
@Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
String method = containerRequestContext.getRequest().getMethod();
if (method.equals("POST") && containerResponseContext.getStatus() == Response.Status.OK.getStatusCode()) {
containerResponseContext.setStatus(Response.Status.CREATED.getStatusCode());
RestEntity entity = (RestEntity) containerResponseContext.getEntity();
String id = entity.getId();
containerResponseContext.getHeaders().add("Location",
containerRequestContext.getUriInfo().getAbsolutePathBuilder().path(id).build().toString());
}
//containerResponseContext.getHeaders().put("Location")
}
}
代码示例来源:origin: oVirt/ovirt-engine
public Fault getUsageMessage(UriInfo uriInfo, Request request)
throws ClassNotFoundException, IOException {
Fault fault = new Fault();
fault.setReason(RESPONSE);
fault.setDetail("For correct usage, see: " + getUsageLink(uriInfo, request.getMethod()));
return fault;
}
代码示例来源:origin: oVirt/ovirt-engine
public V3UsageMessage getUsageMessage(UriInfo uriInfo, Request request) throws ClassNotFoundException, IOException {
V3UsageMessage usage = new V3UsageMessage();
usage.setMessage(RESPONSE);
usage.setDetailedLink(findUsage(uriInfo, request.getMethod()));
return usage;
}
代码示例来源:origin: apache/cxf
@Path("{a:.*}")
@DefaultMethod
public Response handle() {
if (HttpMethod.GET.equals(request.getMethod())) {
String id = ui.getPathParameters().getFirst("id");
Book book = books.get(id);
return Response.ok(book, headers.getAcceptableMediaTypes().get(0)).build();
}
throw new NotAllowedException("GET");
}
public Book echo(Book book) {
内容来源于网络,如有侵权,请联系作者删除!