private boolean isStatusWithLocation(int statusCode) { return statusCode == HttpStatus.CREATED.getCode() || statusCode == HttpStatus.MOVED_PERMANENTLY .getCode() || statusCode == HttpStatus.FOUND.getCode() || statusCode == HttpStatus.SEE_OTHER.getCode() || statusCode == HttpStatus.USE_PROXY.getCode() || statusCode == HttpStatus.TEMPORARY_REDIRECT.getCode(); }
/** * Duplicates this status with another status message. * * @param message new status message * @return new HttpStatus */ public HttpStatus duplicate(String message) { HttpStatus clone = clone(); clone.message = message; return clone; }
public int getStatusCode() { if (status == null) { return -1; } return HttpStatus.valueOfStatusLine(status).getCode(); }
/** * Get a Propstat instance contained within this response that has the * provided criteria, or create a new Propstat instance with the provided * information if no propstat already exists. * * @param status the Http status code of the propstat to retrieve * @param description the description of the propstat to retrieve * @param error the error of the propstat to retrieve. Note that when * searching for a matching propstat, errors are considered the * same only if both errors are null. * @return */ public Propstat getOrCreatePropstat(int status, String description, Error error) { Propstat propstat = getPropstat(status, description, error); if (propstat == null) { propstat = new Propstat(); propstat.setProp(new Prop()); propstat.setStatus(HttpStatus.valueOf(status).getStatusLine()); propstat.setResponsedescription(description); propstat.setError(error); getPropstat().add(propstat); } return propstat; }
@OPTIONS public Response getOptions() { return WebDAVUtils.getOptions(uriInfo); }
/** * Get a Propstat instance contained within this response that has the * provided criteria. * * @param status the Http status code of the propstat to retrieve * @param description the description of the propstat to retrieve * @param error the error of the propstat to retrieve. Note that when * searching for a matching propstat, errors are considered the * same only if both errors are null. * @return the Propstat instance if a match is found, or null if no * propstats matches all criteria */ public Propstat getPropstat(int status, String description, Error error) { // try to find an existing propstat for given status, error and // description for (Propstat propstat : getPropstat()) { Error pError = propstat.getError(); String pDescription = propstat.getResponsedescription(); int pStatus = HttpStatus.valueOfStatusLine(propstat.getStatus()).getCode(); // compare given propstat if (pStatus == status && pError == error && // ... do not compare // errors - only if both // are null (the same) ((pDescription == description) || (pDescription.equals(description)))) { return propstat; } } return null; }
/** * Provides a default response with two additional headers for WebDAV and MS * compatibility. * * @return */ @OPTIONS public Response getOptions(@Context UriInfo info) { return WebDAVUtils.getOptions(info); }
@Override public UriTemplateProcessor clone() { try { UriTemplateProcessor ret = (UriTemplateProcessor)super.clone(); return ret; } catch (CloneNotSupportedException e) { // can't happen throw new WebApplicationException(HttpStatus.INTERNAL_SERVER_ERROR.getCode()); } }
/** * Add the provided property to the correct propstat element with an Http * status of OK. * * @see {@link #setProperty(Object, int, String, Error)} */ public void setPropertyOk(Object property) { setProperty(property, HttpStatus.OK.getCode()); }
/** * Add the provided property to the correct propstat element with an Http * status of NOT FOUND. * * @see {@link #setProperty(Object, int, String, Error)} */ public void setPropertyNotFound(Object property) { setProperty(property, HttpStatus.NOT_FOUND.getCode()); }
response.setStatus(HttpStatus.BAD_REQUEST.getCode());
/** * This method does not perform a real unlock but returns a NO_CONTENT * response for compatibility with MS Windows. * * @return a response instance */ public static Response msCompatibilityUnlock() { Response response = RuntimeDelegate.getInstance().createResponseBuilder().status(HttpStatus.NO_CONTENT .getCode()).build(); return response; }
Response.status(HttpStatus.MULTI_STATUS.getCode()).entity(multistatus).build(); return httpResponse;
ResponseBuilder builder = Response.status(HttpStatus.METHOD_NOT_ALLOWED.getCode());
public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable { // first thing - proceed the chain chain.doChain(context); // check the search result. // if the request is HEAD and no method was found, try to find a GET // method // and discard the entity SearchResult searchResult = context.getAttribute(SearchResult.class); if (searchResult.isError() && searchResult.getError().getResponse().getStatus() == HttpStatus.METHOD_NOT_ALLOWED .getCode() && context.getHttpMethod().equalsIgnoreCase(HttpMethod.HEAD)) { logger .trace("No HEAD method so trying GET method while not sending the response entity"); //$NON-NLS-1$ context.setHttpMethod(HttpMethod.GET); HttpServletResponse originalResponse = context.getAttribute(HttpServletResponse.class); NoBodyResponse noBodyResponse = new NoBodyResponse(originalResponse); context.setAttribute(HttpServletResponse.class, noBodyResponse); context.setAttribute(HttpServletResponseWrapper.class, noBodyResponse); context.setAttribute(NoBodyResponse.class, noBodyResponse); context.getAttributes().put(ORIGINAL_RESPONSE_ATT_NAME, originalResponse); chain.doChain(context); } }
public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable { // first thing - proceed the chain chain.doChain(context); // check the search result. // if the request is OPTIONS and no method was found, generate the // response automatically SearchResult searchResult = context.getAttribute(SearchResult.class); if (searchResult.isError() && searchResult.getError().getResponse().getStatus() == HttpStatus.METHOD_NOT_ALLOWED .getCode() && context.getHttpMethod().equalsIgnoreCase(HttpMethodEx.OPTIONS)) { // get supported HTTP methods ResourceRegistry resourceRegistry = context.getAttribute(ResourceRegistry.class); Set<String> httpMethods = resourceRegistry.getOptions(searchResult.getResource()); logger .trace("Invoking OPTIONS request handled by runtime with {} resource and {} HTTP methods", //$NON-NLS-1$ searchResult.getResource(), httpMethods); if (httpMethods.size() > 0) { String allowHeader = HeaderUtils.buildOptionsHeader(httpMethods); // add 'Allow' header to the response context.getAttribute(HttpServletResponse.class).addHeader(HttpHeadersEx.ALLOW, allowHeader); // remove an error from the search result context.getAttribute(SearchResult.class).setError(null); // set result to no-content context.setResponseStatusCode(Response.Status.NO_CONTENT.getStatusCode()); context.setResponseEntity(null); } } }
Response.status(HttpStatus.MULTI_STATUS.getCode()).entity(multistatus).build(); return httpResponse;