Java Code Examples for javax.ws.rs.client.Invocation.Builder#put()
The following examples show how to use
javax.ws.rs.client.Invocation.Builder#put() .
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: MCRWorksPublisher.java From mycore with GNU General Public License v3.0 | 5 votes |
void update(MCRWork work) throws IOException, SAXException { WebTarget target = orcid.getWebTarget().path("work").path(work.getPutCode()); Builder builder = buildInvocation(target); Document workXML = buildWorkXMLFrom(work.getObjectID()); workXML.getRootElement().setAttribute("put-code", work.getPutCode()); Entity<InputStream> input = buildRequestEntity(workXML); LOGGER.info("put (update) {} to {}", work.getObjectID(), target.getUri()); Response response = builder.put(input); expect(response, Response.Status.OK); }
Example 2
Source File: TRegisterResource.java From oxAuth with MIT License | 5 votes |
private UmaResourceResponse modifyResourceInternal(final Token p_pat, String umaRegisterResourcePath, final String p_rsId, final UmaResource resource) throws Exception { String path = umaRegisterResourcePath + "/" + p_rsId + "/"; Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + path).request(); request.header("Accept", UmaConstants.JSON_MEDIA_TYPE); request.header("Authorization", "Bearer " + p_pat.getAccessToken()); String json = null; try { // final String json = // ServerUtil.jsonMapperWithWrapRoot().writeValueAsString(resource); json = ServerUtil.createJsonMapper().writeValueAsString(resource); } catch (Exception e) { e.printStackTrace(); fail(); } Response response = request.put(Entity.json(json)); String entity = response.readEntity(String.class); BaseTest.showResponse("UMA : TRegisterResource.modifyResourceInternal() : ", response, entity); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Unexpected response code."); modifyStatus = TUma.readJsonValue(entity, UmaResourceResponse.class); UmaTestUtil.assert_(modifyStatus); return modifyStatus; }
Example 3
Source File: AzureRoleManager.java From cloudbreak with Apache License 2.0 | 5 votes |
@Retryable(value = InteractiveLoginException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000)) public void assignRole(String accessToken, String subscriptionId, String roleDefinitionId, String principalObjectId) throws InteractiveLoginException { Client client = ClientBuilder.newClient(); WebTarget resource = client.target(AZURE_MANAGEMENT); Builder request = resource.path("subscriptions/" + subscriptionId + "/providers/Microsoft.Authorization/roleAssignments/" + UUID.randomUUID()).queryParam("api-version", "2015-07-01").request(); request.accept(MediaType.APPLICATION_JSON); request.header("Authorization", "Bearer " + accessToken); JsonObject properties = new JsonObject(); properties.addProperty("roleDefinitionId", roleDefinitionId); properties.addProperty("principalId", principalObjectId); JsonObject jsonObject = new JsonObject(); jsonObject.add("properties", properties); try (Response response = request.put(Entity.entity(jsonObject.toString(), MediaType.APPLICATION_JSON))) { if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { String errorResponse = response.readEntity(String.class); LOGGER.info("Assign role request error - status code: {} - error message: {}", response.getStatus(), errorResponse); if (response.getStatusInfo().getStatusCode() == Status.FORBIDDEN.getStatusCode()) { throw new InteractiveLoginException("You don't have enough permissions to assign roles, please contact with your administrator"); } else { try { String errorMessage = new ObjectMapper().readTree(errorResponse).get("error").get("message").asText(); throw new InteractiveLoginException("Failed to assing role: " + errorMessage); } catch (IOException e) { throw new InteractiveLoginException("Failed to assing role (status " + response.getStatus() + "): " + errorResponse); } } } else { LOGGER.debug("Role assigned successfully. subscriptionId '{}', roleDefinitionId {}, principalObjectId {}", subscriptionId, roleDefinitionId, principalObjectId); } } }
Example 4
Source File: SimpleRestClient.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
private Response executeService(Map<String, Object> parameters, String serviceUrl, String userId, RequestTypeEnum type, String mediaType, Object data) throws Exception { logger.debug("IN"); MultivaluedMap<String, Object> myHeaders = new MultivaluedHashMap<String, Object>(); if (!serviceUrl.contains("http") && addServerUrl) { logger.debug("Adding the server URL"); if (serverUrl != null) { logger.debug("Executing the dataset from the core so use relative path to service"); serviceUrl = serverUrl + serviceUrl; } } Client client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault()).build(); logger.debug("Service URL to be invoked : " + serviceUrl); WebTarget target = client.target(serviceUrl); if (parameters != null) { Iterator<String> iter = parameters.keySet().iterator(); while (iter.hasNext()) { String param = iter.next(); LogMF.debug(logger, "Adding parameter [{0}] : [{1}]", param, parameters.get(param)); target = target.queryParam(param, parameters.get(param)); } } logger.debug("Media type : " + mediaType); Builder request = target.request(mediaType); logger.debug("adding headers"); addAuthorizations(request, userId, myHeaders); logger.debug("Call service"); Response response = null; // provide authentication exactly before of call authenticationProvider.provideAuthentication(request, target, myHeaders, data); if (type.equals(RequestTypeEnum.POST)) { response = request.post(Entity.json(data.toString())); } else if (type.equals(RequestTypeEnum.PUT)) { response = request.put(Entity.json(data.toString())); } else { response = request.get(); } logger.debug("Rest query status " + response.getStatus()); // logger.debug("Rest query status info "+response.getStatusInfo()); logger.debug("Rest query status getReasonPhrase " + response.getStatusInfo().getReasonPhrase()); logger.debug("OUT"); return response; }
Example 5
Source File: Connection.java From ecs-cf-service-broker with Apache License 2.0 | 4 votes |
protected Response makeRemoteCall(String method, UriBuilder uri, Object arg, String contentType) throws EcsManagementClientException { try { if (!isLoggedIn()) login(); logger.info("Making {} request to {}", method, uri); Client jerseyClient = buildJerseyClient(); Builder request = jerseyClient.target(uri) .register(LoggingFeature.class).request() .header("X-SDS-AUTH-TOKEN", authToken) .header("Accept", "application/xml"); Response response = null; if (GET.equals(method)) { response = request.get(); } else if (POST.equals(method) || PUT.equals(method)) { Entity<Object> objectEntity; if (XML.equals(contentType)) { objectEntity = Entity.xml(arg); } else if (JSON.equals(contentType)) { objectEntity = Entity.json(arg); } else { throw new EcsManagementClientException("Content type must be \"XML\" or \"JSON\""); } if (POST.equals(method)) { response = request.post(objectEntity); } else if (PUT.equals(method)) { response = request.put(objectEntity); } } else if (DELETE.equals(method)) { response = request.delete(); } else { throw new EcsManagementClientException( "Invalid request method: " + method); } if (response.getStatus() == 401 && authRetries < AUTH_RETRIES_MAX) { // attempt to re-authorize and retry up to _authMaxRetries_ times. authRetries += 1; this.authToken = null; response = makeRemoteCall(method, uri, arg, XML); } return response; } catch (Exception e) { logger.warn("Failed to make a call to {}: {}", uri, e.getMessage()); throw e; } }