@Override public String toString() { return getCode() + " - " + getDescription(); }
@Override public HttpMethod getMethod() { return HttpMethod.from(method); }
/** * Build a {@link MediaType#APPLICATION_XML} entity. * @param <T> Payload type * @param payload Entity payload * @return RequestEntity */ static <T> RequestEntity<T> xml(T payload) { return new DefaultRequestEntity<>(MediaType.APPLICATION_XML.toString(), payload); }
public void httpHeaders() { // tag::httpheaders[] HttpMessage<String> message = getMessage(); Optional<String> value = message.getHeaderValue("HEADER_NAME"); // <1> Optional<Date> date = message.getDate(); // <2> Optional<URI> location = message.getLocation(); // <3> Optional<Long> length = message.getContentLength(); // <4> Optional<Locale> locale = message.getLocale(); // <5> List<Locale> locales = message.getLocales(); // <6> Optional<String[]> basicAuth = message.getAuthorizationBasicCredentials(); // <7> Optional<String> bearerAuth = message.getAuthorizationBearer(); // <8> // end::httpheaders[] }
/** * Get the response status as {@link HttpStatus} * @return the response HttpStatus * @throws InvalidHttpMessageException If the status code of the message does not corresponds to any of the * {@link HttpStatus} values */ default HttpStatus getStatus() { return HttpStatus.of(getStatusCode()) .orElseThrow(() -> new InvalidHttpMessageException("Unknown status code: " + getStatusCode())); }
/** * Constructor with status code * @param statusCode HTTP status code */ public HttpStatusCodeException(int statusCode) { super(HttpStatus.of(statusCode).map(s -> s.getCode() + " - " + s.getDescription()) .orElse("HTTP status code: " + statusCode)); this.statusCode = statusCode; }
/** * Get HttpMethod enum constant matching given <code>methodName</code> name * @param methodName Method name * @return Matching HttpMethod, or <code>null</code> if none match */ public static HttpMethod from(String methodName) { if (methodName != null) { for (HttpMethod value : values()) { if (methodName.equalsIgnoreCase(value.getMethodName())) { return value; } } } return null; }
public void httpResponse() { // tag::httpresponse[] HttpResponse<String> message = getResponseMessage(); int statusCode = message.getStatusCode(); // <1> HttpStatus status = message.getStatus(); // <2> // end::httpresponse[] }
/** * Returns the media type representation in the conventional HTTP header form, i.e. <code>type/subtype</code>. * @return Media type representation */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getType()).append('/').append(getSubtype()); if (getParameters() != null) { sb.append(';').append(getParameters()); } return sb.toString(); }
/** * Get HTTP response status associated with this exception as {@link HttpStatus}, if available and known. * @return Optional HTTP response status */ public Optional<HttpStatus> getStatus() { return HttpStatus.of(getStatusCode()); }
/** * Constructor * @param errorCode Error code * @param errorDescription Error description, i.e. a human-readable explanation of this error * @param errorURI Error URI that leads to further details about this error * @param httpStatus HTTP status code to represent error as a HTTP response */ public ErrorResponseException(String errorCode, String errorDescription, String errorURI, int httpStatus) { super(buildExceptionMessage(errorCode, errorDescription)); this.errorCode = errorCode; this.errorDescription = errorDescription; this.errorURI = errorURI; this.httpStatus = httpStatus; }
@Override public HttpMethod getMethod() { return HttpMethod.from(request.getMethod()); }
/** * Build a {@link MediaType#APPLICATION_JSON} entity. * @param <T> Payload type * @param payload Entity payload * @return RequestEntity */ static <T> RequestEntity<T> json(T payload) { return new DefaultRequestEntity<>(MediaType.APPLICATION_JSON.toString(), payload); }
@Override public HttpMethod getMethod() { return HttpMethod.from(request.getMethod()); }
/** * Build a {@link MediaType#APPLICATION_FORM_URLENCODED} entity * @param formData Form data name-value(s) map * @return RequestEntity */ static RequestEntity<Map<String, List<String>>> form(final Map<String, List<String>> formData) { return new DefaultRequestEntity<>(MediaType.APPLICATION_FORM_URLENCODED.toString(), formData); }
@Override public HttpMethod getMethod() { return HttpMethod.from(request.getMethod()); }
/** * Build a {@link MediaType#TEXT_PLAIN} entity. * @param <T> Payload type * @param payload Entity payload * @return RequestEntity */ static <T> RequestEntity<T> text(T payload) { return new DefaultRequestEntity<>(MediaType.TEXT_PLAIN.toString(), payload); }
@Override public HttpMethod getMethod() { return HttpMethod.from(request.getMethod()); }
@Override public HttpMethod getMethod() { return HttpMethod.from(request.getMethod()); }