Java Code Examples for javax.ws.rs.core.Response#getStatusInfo()
The following examples show how to use
javax.ws.rs.core.Response#getStatusInfo() .
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 File: ImagesService.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
public void tagImage(final String imageId, final String nameAndTag) { ImageDescriptor descriptor = new ImageDescriptor(nameAndTag); WebTarget target = getServiceEndPoint() .path(imageId) .path("tag") .queryParam("repo", descriptor.getRegistryRepositoryAndImage()) .queryParam("force", 1); Optional<String> targetTag = descriptor.getTag(); if (targetTag.isPresent()) { target = target.queryParam("tag", targetTag.get()); } Response response = target.request() .accept(MediaType.APPLICATION_JSON_TYPE) .post(null); Response.StatusType statusInfo = response.getStatusInfo(); response.close(); checkImageTargetingResponse(imageId, statusInfo); }
Example 2
Source File: FileName.java From raml-java-client-generator with Apache License 2.0 | 6 votes |
/** * Creates or updates the given file * */ public void put(Object body, FileNamePUTHeader headers) { WebTarget target = this._client.target(getBaseUri()); final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); if (headers.getXBaseCommitId()!= null) { invocationBuilder.header("x-base-commit-id", headers.getXBaseCommitId()); } if (headers.getXCommitMessage()!= null) { invocationBuilder.header("x-commit-message", headers.getXCommitMessage()); } Response response = invocationBuilder.put(Entity.entity(body, "*/*")); if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { Response.StatusType statusInfo = response.getStatusInfo(); throw new SimpleApiException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } }
Example 3
Source File: RestServiceTestApplication.java From packt-java-ee-7-code-samples with GNU General Public License v2.0 | 5 votes |
private void bookSeats(Collection<SeatDto> seats) { for (SeatDto seat : seats) { try { final String idOfSeat = Integer.toString(seat.getId()); seatResource.path(idOfSeat).request().post(Entity.json(""), String.class); System.out.println(seat + " booked"); } catch (WebApplicationException e) { final Response response = e.getResponse(); StatusType statusInfo = response.getStatusInfo(); System.out.println(seat + " not booked (" + statusInfo.getReasonPhrase() + "): " + response.readEntity(JsonObject.class).getString("entity")); } } }
Example 4
Source File: Foo.java From raml-java-client-generator with Apache License 2.0 | 5 votes |
public FooResponse<same_path_multiple_times.resource.foo.model.FooGETResponseBody> 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); } FooResponse<same_path_multiple_times.resource.foo.model.FooGETResponseBody> apiResponse = new FooResponse<same_path_multiple_times.resource.foo.model.FooGETResponseBody>(response.readEntity(same_path_multiple_times.resource.foo.model.FooGETResponseBody.class), response.getStringHeaders(), response); return apiResponse; }
Example 5
Source File: Login.java From raml-java-client-generator with Apache License 2.0 | 5 votes |
public FooResponse<simple.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 FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } FooResponse<simple.resource.cs.login.model.LoginGETResponseBody> apiResponse = new FooResponse<simple.resource.cs.login.model.LoginGETResponseBody>(response.readEntity(simple.resource.cs.login.model.LoginGETResponseBody.class), response.getStringHeaders(), response); return apiResponse; }
Example 6
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @return response */ @SuppressWarnings("unchecked") public static Inflector<ContainerRequestContext, Response> grantPermitHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String subjectid = pathParam("subjectid", ctx); String resourcePath = pathParam(Config._TYPE, ctx); if (app != null) { Response resp = getEntity(ctx.getEntityStream(), List.class); if (resp.getStatusInfo() == Response.Status.OK) { List<String> permission = (List<String>) resp.getEntity(); Set<App.AllowedMethods> set = new HashSet<>(permission.size()); for (String perm : permission) { if (!StringUtils.isBlank(perm)) { App.AllowedMethods method = App.AllowedMethods.fromString(perm); if (method != null) { set.add(method); } } } if (!set.isEmpty()) { if (app.grantResourcePermission(subjectid, resourcePath, EnumSet.copyOf(set))) { app.update(); } return Response.ok(app.getAllResourcePermissions(subjectid)).build(); } else { return getStatusResponse(Response.Status.BAD_REQUEST, "No allowed methods specified."); } } else { return resp; } } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example 7
Source File: Api.java From raml-java-client-generator with 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<oauth_override.resource.api.model.ApiGETResponse>>() {})); }
Example 8
Source File: Login.java From raml-java-client-generator with Apache License 2.0 | 5 votes |
public FooResponse<List<AuthorizationJson>> 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<List<AuthorizationJson>> apiResponse = new FooResponse<List<AuthorizationJson>>(response.readEntity(( new javax.ws.rs.core.GenericType<java.util.List<java_8_dates.resource.cs.login.model.AuthorizationJson>>() {})), response.getStringHeaders(), response); return apiResponse; }
Example 9
Source File: Bar.java From raml-java-client-generator with Apache License 2.0 | 5 votes |
/** * SomeDescriptionValue * */ public recursive_type.model.Foo 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 LocationsException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } return response.readEntity(recursive_type.model.Foo.class); }
Example 10
Source File: Rename.java From raml-java-client-generator with Apache License 2.0 | 5 votes |
/** * Rename a project * */ public 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); } }
Example 11
Source File: Bar.java From raml-java-client-generator with Apache License 2.0 | 5 votes |
public FooResponse<Void> 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<Void> apiResponse = new FooResponse<Void>(null, response.getStringHeaders(), response); return apiResponse; }
Example 12
Source File: Foo.java From raml-java-client-generator with 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 13
Source File: Login.java From raml-java-client-generator with Apache License 2.0 | 5 votes |
public multi_body.resource.cs.login.model.LoginGETResponse 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); } return response.readEntity(multi_body.resource.cs.login.model.LoginGETResponse.class); }
Example 14
Source File: Test.java From raml-java-client-generator with Apache License 2.0 | 5 votes |
public MyapiResponse<type_decl.model.MyType> 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 MyapiException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); } MyapiResponse<type_decl.model.MyType> apiResponse = new MyapiResponse<type_decl.model.MyType>(response.readEntity(type_decl.model.MyType.class), response.getStringHeaders(), response); return apiResponse; }
Example 15
Source File: JaegerQueryAPI.java From syndesis with Apache License 2.0 | 5 votes |
public List<Trace> tracesForService(String service, int lookbackDays, int limit) { long now = System.currentTimeMillis(); long start = now - TimeUnit.DAYS.toMillis(lookbackDays); Response response = api.path("traces") .queryParam("end", now * 1009) // in ns .queryParam("start", start * 1000) // in ns .queryParam("limit", limit) .queryParam("lookback", lookbackDays + "d") .queryParam("service", service) .request(MediaType.APPLICATION_JSON) .get(); Response.StatusType status = response.getStatusInfo(); if (status.getFamily() != Response.Status.Family.SUCCESSFUL) { throw new WebApplicationException("HTTP " + status.getStatusCode() + ": " + response.readEntity(String.class), response); } if (response.getStatus() != Response.Status.NO_CONTENT.getStatusCode()) { String contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE); if (contentType == null || !contentType.startsWith(MediaType.APPLICATION_JSON)) { throw new WebApplicationException("Got unexpected content type: " + contentType + " with body: " + response.readEntity(String.class)); } return response.readEntity(Traces.class).data; // Use the following commented code instead if you want to peek at what the query API is returning... // byte[] bytes = response.readEntity(byte[].class); // String data = new String(bytes); // System.out.println(data); // Traces o = null; // try { // o = Json.reader().forType(Traces.class).readValue(data); // } catch (IOException e) { // throw new WebApplicationException(e); // } // return o.data; } return new ArrayList<>(); }
Example 16
Source File: FluentTestsHelper.java From keycloak with Apache License 2.0 | 5 votes |
protected String getCreatedId(Response response) { URI location = response.getLocation(); if (!response.getStatusInfo().equals(Response.Status.CREATED)) { Response.StatusType statusInfo = response.getStatusInfo(); throw new WebApplicationException("Create method returned status " + statusInfo.getReasonPhrase() + " (Code: " + statusInfo.getStatusCode() + "); expected status: Created (201)", response); } if (location == null) { return null; } String path = location.getPath(); return path.substring(path.lastIndexOf('/') + 1); }
Example 17
Source File: Login.java From raml-java-client-generator with 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 18
Source File: RestfulEnclaveClient.java From tessera with Apache License 2.0 | 5 votes |
private static void validateResponseIsOk(Response response) { if (response.getStatus() != 200) { Response.StatusType statusInfo = response.getStatusInfo(); String message = String.format( "Remote enclave instance threw an error %d %s", statusInfo.getStatusCode(), statusInfo.getReasonPhrase()); throw new EnclaveNotAvailableException(message); } }
Example 19
Source File: RestUtils.java From para with Apache License 2.0 | 4 votes |
/** * Batch create response as JSON. * @param app the current App object * @param is entity input stream * @return a status code 200 or 400 */ public static Response getBatchCreateResponse(final App app, InputStream is) { try (Metrics.Context context = Metrics.time(app == null ? null : app.getAppid(), RestUtils.class, "batch", "create")) { if (app != null) { final LinkedList<ParaObject> newObjects = new LinkedList<>(); Set<String> ids = new LinkedHashSet<>(); Response entityRes = getEntity(is, List.class); if (entityRes.getStatusInfo() == Response.Status.OK) { List<Map<String, Object>> items = (List<Map<String, Object>>) entityRes.getEntity(); for (Map<String, Object> object : items) { // can't create multiple apps in batch String type = (String) object.get(Config._TYPE); if (isNotAnApp(type)) { warnIfUserTypeDetected(type); ParaObject pobj = ParaObjectUtils.setAnnotatedFields(object); if (pobj != null && isValidObject(app, pobj)) { pobj.setAppid(app.getAppIdentifier()); setCreatorid(app, pobj); if (pobj.getId() != null && ids.contains(pobj.getId())) { logger.warn("Batch contains objects with duplicate ids. " + "Duplicate object {} might not be persisted!", pobj.getId()); } ids.add(pobj.getId()); newObjects.add(pobj); } } } Para.getDAO().createAll(app.getAppIdentifier(), newObjects); Para.asyncExecute(new Runnable() { public void run() { int typesCount = app.getDatatypes().size(); app.addDatatypes(newObjects.toArray(new ParaObject[0])); if (typesCount < app.getDatatypes().size()) { app.update(); } } }); } else { return entityRes; } return Response.ok(newObjects).build(); } else { return getStatusResponse(Response.Status.BAD_REQUEST); } } }
Example 20
Source File: MCRWorksPublisher.java From mycore with GNU General Public License v3.0 | 3 votes |
/** * If the response is not as expected and the request was not successful, * throws an exception with detailed error message from the ORCID REST API. * * @param response the response to the REST request * @param expectedStatus the status expected when request is successful * @throws MCRORCIDException if the ORCID API returned error information */ private void expect(Response response, Response.Status expectedStatus) throws IOException { StatusType status = response.getStatusInfo(); if (status.getStatusCode() != expectedStatus.getStatusCode()) { throw new MCRORCIDException(response); } }