Java Code Examples for javax.ws.rs.core.Response#StatusType
The following examples show how to use
javax.ws.rs.core.Response#StatusType .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: raml-java-client-generator File: Exec.java License: Apache License 2.0 | 6 votes |
public void post(ExecPOSTBody body) { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); FormDataMultiPart multiPart = new FormDataMultiPart(); if (body.getFile()!= null) { multiPart.bodyPart(new FileDataBodyPart("file", body.getFile())); } if (body.getFrom()!= null) { multiPart.field("From", body.getFrom().toString()); } Response response = invocationBuilder.post(Entity.entity(multiPart, multiPart.getMediaType())); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new DataWeaveAPIException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } }
Example 2
Source Project: secure-data-service File: CustomStatus.java License: Apache License 2.0 | 6 votes |
private static Response.StatusType buildStatusType(final int code, final String reasonPhrase, final Status.Family family) { return new Response.StatusType() { @Override public int getStatusCode() { return code; } @Override public String getReasonPhrase() { return reasonPhrase; } @Override public Family getFamily() { return family; } }; }
Example 3
Source Project: jrestless File: FnRequestHandler.java License: Apache License 2.0 | 6 votes |
@Override public void writeResponse(Response.StatusType statusType, Map<String, List<String>> headers, OutputStream outputStream) throws IOException { // NOTE: This is a safe cast as it is set to a ByteArrayOutputStream by getEntityOutputStream // See JRestlessHandlerContainer class for more details String responseBody = ((ByteArrayOutputStream) outputStream).toString(StandardCharsets.UTF_8.name()); String contentType = headers .getOrDefault(HttpHeaders.CONTENT_TYPE, Collections.singletonList(DEFAULT_CONTENT_TYPE)) .get(0); Map<String, String> outHeaders = new HashMap<>(); headers.forEach((k, v) -> outHeaders.put(k, v.stream().collect(Collectors.joining(",")))); OutputEvent outputEvent = OutputEvent.fromBytes( responseBody.getBytes(StandardCharsets.UTF_8), statusType.getStatusCode(), contentType, Headers.fromMap(outHeaders)); response = new WrappedOutput(outputEvent, responseBody, statusType); }
Example 4
Source Project: smarthome File: JSONResponse.java License: Eclipse Public License 2.0 | 6 votes |
/** * create JSON Response */ @Override public Response toResponse(Exception e) { logger.debug("exception during REST Handling", e); Response.StatusType status = Response.Status.INTERNAL_SERVER_ERROR; // in case the Exception is a WebApplicationException, it already carries a Status if (e instanceof WebApplicationException) { status = ((WebApplicationException) e).getResponse().getStatusInfo(); } JsonElement ret = INSTANCE.createErrorJson(e.getMessage(), status, null, e); return INSTANCE.responseBuilder(status).entity(INSTANCE.gson.toJson(ret)).build(); }
Example 5
Source Project: msf4j File: MSF4JResponse.java License: Apache License 2.0 | 6 votes |
@Override public StatusType getStatusInfo() { return new Response.StatusType() { public Status.Family getFamily() { return Response.Status.Family.familyOf(MSF4JResponse.this.status); } public String getReasonPhrase() { Response.Status statusEnum = Response.Status.fromStatusCode(MSF4JResponse.this.status); return statusEnum != null ? statusEnum.getReasonPhrase() : ""; } public int getStatusCode() { return MSF4JResponse.this.status; } }; }
Example 6
Source Project: raml-java-client-generator File: Login.java License: Apache License 2.0 | 5 votes |
public MultiBodyResponse<multi_body.resource.cs.login.model.LoginPOSTResponseBody> post(InputStream body) { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE); Response response = invocationBuilder.post(javax.ws.rs.client.Entity.entity(body, javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE)); if (response.getStatusInfo().getFamily()!= javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new MultiBodyException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } MultiBodyResponse<multi_body.resource.cs.login.model.LoginPOSTResponseBody> apiResponse = new MultiBodyResponse<multi_body.resource.cs.login.model.LoginPOSTResponseBody>(response.readEntity(multi_body.resource.cs.login.model.LoginPOSTResponseBody.class), response.getStringHeaders(), response); return apiResponse; }
Example 7
Source Project: rulz File: HttpMatchersTest.java License: Apache License 2.0 | 5 votes |
@Test public void redirectionErrorMatcher() { Matcher<Response> redirectionMatcher = HttpMatchers.redirection(); Response response = mock(Response.class); Response.StatusType statusType = mock(Response.StatusType.class); when(response.getStatusInfo()).thenReturn(statusType); when(statusType.getFamily()).thenReturn(Response.Status.Family.REDIRECTION); assertThat(response, is(redirectionMatcher)); }
Example 8
Source Project: docker-maven-plugin File: BaseService.java License: Apache License 2.0 | 5 votes |
protected static void checkImageTargetingResponse(final String id, final Response.StatusType statusInfo) { if (statusInfo.getFamily() == Family.SUCCESSFUL) { // no error return; } switch (statusInfo.getStatusCode()) { case 404: throw new ImageNotFoundException(id); default: throw new DockerException(statusInfo.getReasonPhrase()); } }
Example 9
Source Project: raml-java-client-generator File: Rename.java License: Apache License 2.0 | 5 votes |
/** * Rename a project * */ public DesignCenterProjectsServicewithsubresourceonsamelineResponse<Void> put(Object body) { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); Response response = invocationBuilder.put(Entity.json(body)); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new DesignCenterProjectsServicewithsubresourceonsamelineException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } DesignCenterProjectsServicewithsubresourceonsamelineResponse<Void> apiResponse = new DesignCenterProjectsServicewithsubresourceonsamelineResponse<Void>(null, response.getStringHeaders(), response); return apiResponse; }
Example 10
Source Project: raml-java-client-generator File: Users.java License: Apache License 2.0 | 5 votes |
/** * Returns the list of all users * */ public List<UsersGETResponse> get() { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); Response response = invocationBuilder.get(); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } return response.readEntity(( new javax.ws.rs.core.GenericType<java.util.List<list.resource.users.model.UsersGETResponse>>() {})); }
Example 11
Source Project: raml-java-client-generator File: Api.java License: Apache License 2.0 | 5 votes |
/** * Returns the list of all users * */ public List<ApiGETResponse> get(String authorizationToken) { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); invocationBuilder.header("Authorization", ("Bearer "+ authorizationToken)); Response response = invocationBuilder.get(); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new CoreServicesAPIReferenceException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } return response.readEntity(( new javax.ws.rs.core.GenericType<java.util.List<oauth20.resource.api.model.ApiGETResponse>>() {})); }
Example 12
Source Project: raml-java-client-generator File: Login.java License: Apache License 2.0 | 5 votes |
public MultiBodyResponse<multi_body.resource.cs.login.model.LoginGETResponseBody> get() { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE); Response response = invocationBuilder.get(); if (response.getStatusInfo().getFamily()!= javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new MultiBodyException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } MultiBodyResponse<multi_body.resource.cs.login.model.LoginGETResponseBody> apiResponse = new MultiBodyResponse<multi_body.resource.cs.login.model.LoginGETResponseBody>(response.readEntity(multi_body.resource.cs.login.model.LoginGETResponseBody.class), response.getStringHeaders(), response); return apiResponse; }
Example 13
Source Project: raml-java-client-generator File: Login.java License: Apache License 2.0 | 5 votes |
public FooResponse<String> post() { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); Response response = invocationBuilder.post(null); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } FooResponse<String> apiResponse = new FooResponse<String>(((String) response.readEntity(Object.class)), response.getStringHeaders(), response); return apiResponse; }
Example 14
Source Project: raml-java-client-generator File: A.java License: Apache License 2.0 | 5 votes |
public same_path_multiple_times.resource.foo.a.model.AGETResponse get() { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); Response response = invocationBuilder.get(); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } return response.readEntity(same_path_multiple_times.resource.foo.a.model.AGETResponse.class); }
Example 15
Source Project: raml-java-client-generator File: Api.java License: Apache License 2.0 | 5 votes |
/** * Returns the list of all users * */ public CoreServicesAPIReferenceResponse<List<ApiGETResponseBody>> get(String authorizationToken) { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); invocationBuilder.header("Authorization", ("Bearer "+ authorizationToken)); Response response = invocationBuilder.get(); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new CoreServicesAPIReferenceException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } CoreServicesAPIReferenceResponse<List<ApiGETResponseBody>> apiResponse = new CoreServicesAPIReferenceResponse<List<ApiGETResponseBody>>(response.readEntity(( new javax.ws.rs.core.GenericType<java.util.List<oauth20.resource.api.model.ApiGETResponseBody>>() {})), response.getStringHeaders(), response); return apiResponse; }
Example 16
Source Project: raml-java-client-generator File: Login.java License: Apache License 2.0 | 5 votes |
public CoreServicesAPIReferenceResponse<Void> get() { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); Response response = invocationBuilder.get(); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new CoreServicesAPIReferenceException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } CoreServicesAPIReferenceResponse<Void> apiResponse = new CoreServicesAPIReferenceResponse<Void>(null, response.getStringHeaders(), response); return apiResponse; }
Example 17
Source Project: raml-java-client-generator File: Foo.java License: Apache License 2.0 | 5 votes |
public same_path_multiple_times.resource.foo.model.FooGETResponse get() { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); Response response = invocationBuilder.get(); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } return response.readEntity(same_path_multiple_times.resource.foo.model.FooGETResponse.class); }
Example 18
Source Project: smarthome File: JSONResponse.java License: Eclipse Public License 2.0 | 4 votes |
private Response createErrorResponse(Response.StatusType status, Object entity, String errormessage) { ResponseBuilder rp = responseBuilder(status); JsonElement errorJson = createErrorJson(errormessage, status, entity, null); rp.entity(errorJson); return rp.build(); }
Example 19
Source Project: cyberduck File: HttpComponentsConnector.java License: GNU General Public License v3.0 | 4 votes |
@Override public ClientResponse apply(final ClientRequest clientRequest) throws ProcessingException { final HttpUriRequest request = this.toUriHttpRequest(clientRequest); final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(clientRequest.getHeaders(), request); try { final CloseableHttpResponse response; response = client.execute(new HttpHost(request.getURI().getHost(), request.getURI().getPort(), request.getURI().getScheme()), request, new BasicHttpContext(context)); HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, clientRequest.getHeaders(), this.getClass().getName()); final Response.StatusType status = response.getStatusLine().getReasonPhrase() == null ? Statuses.from(response.getStatusLine().getStatusCode()) : Statuses.from(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); final ClientResponse responseContext = new ClientResponse(status, clientRequest); final List<URI> redirectLocations = context.getRedirectLocations(); if(redirectLocations != null && !redirectLocations.isEmpty()) { responseContext.setResolvedRequestUri(redirectLocations.get(redirectLocations.size() - 1)); } final Header[] respHeaders = response.getAllHeaders(); final MultivaluedMap<String, String> headers = responseContext.getHeaders(); for(final Header header : respHeaders) { final String headerName = header.getName(); List<String> list = headers.get(headerName); if(list == null) { list = new ArrayList<>(); } list.add(header.getValue()); headers.put(headerName, list); } final HttpEntity entity = response.getEntity(); if(entity != null) { if(headers.get(HttpHeaders.CONTENT_LENGTH) == null) { headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength())); } final Header contentEncoding = entity.getContentEncoding(); if(headers.get(HttpHeaders.CONTENT_ENCODING) == null && contentEncoding != null) { headers.add(HttpHeaders.CONTENT_ENCODING, contentEncoding.getValue()); } } responseContext.setEntityStream(this.toInputStream(response)); return responseContext; } catch(final Exception e) { throw new ProcessingException(e); } }
Example 20
Source Project: dremio-oss File: StatusExpectation.java License: Apache License 2.0 | 4 votes |
StatusExpectation(Response.StatusType status) { this.status = status; }