List of usage examples for org.apache.http.client.fluent Request Put
public static Request Put(final String uri)
From source file:be.fedict.dcat.datagovbe.Drupal.java
/** * Prepare a POST or PUT action./*from w w w . j a v a 2 s . c o m*/ * * @param method POST or PUT * @param relpath relative path * @return */ private Request prepare(String method, String relpath) { String u = this.url.toString() + relpath; Request r = method.equals(Drupal.POST) ? Request.Post(u) : Request.Put(u); r.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()).setHeader(Drupal.X_TOKEN, token); if (proxy != null) { r.viaProxy(proxy); } return r; }
From source file:org.restheart.test.integration.GetAggreationIT.java
private void createTmpCollection() throws Exception { Response resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put tmp db", resp, HttpStatus.SC_CREATED); resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{descr:\"temp coll\"}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put tmp coll", resp, HttpStatus.SC_CREATED); }
From source file:org.mule.module.http.functional.listener.HttpListenerHttpMessagePropertiesTestCase.java
@Test public void putWithOldProtocol() throws Exception { final ImmutableMap<String, Object> queryParams = ImmutableMap.<String, Object>builder() .put(QUERY_PARAM_NAME, Arrays.asList(QUERY_PARAM_VALUE, QUERY_PARAM_VALUE)).build(); final String url = String.format("http://localhost:%s/?" + buildQueryString(queryParams), listenPort.getNumber());/*from w ww . j av a 2 s . com*/ Request.Put(url).version(HttpVersion.HTTP_1_0).connectTimeout(RECEIVE_TIMEOUT).execute(); final MuleMessage message = muleContext.getClient().request("vm://out", RECEIVE_TIMEOUT); assertThat(message.<String>getInboundProperty(HttpConstants.RequestProperties.HTTP_METHOD_PROPERTY), is("PUT")); assertThat(message.<String>getInboundProperty(HttpConstants.RequestProperties.HTTP_VERSION_PROPERTY), is(HttpProtocol.HTTP_1_0.asString())); }
From source file:photosharing.api.conx.CommentsDefinition.java
/** * updates a given comment/*from www .ja v a 2 s . c om*/ * * @param bearer * the accessToken * @param cid * the comment id * @param pid * the file id * @param uid * the library id * @param body * the text body * @param nonce * the nonce value * @param response * the response that is going to get the response */ public void updateComment(String bearer, String cid, String pid, String uid, String body, String nonce, HttpServletResponse response) { String apiUrl = getApiUrl() + "/userlibrary/" + uid + "/document/" + pid + "/comment/" + cid + "/entry"; try { JSONObject obj = new JSONObject(body); String comment = generateComment(obj.getString("comment")); // Generate the Request put = Request.Put(apiUrl); put.addHeader("Authorization", "Bearer " + bearer); put.addHeader("X-Update-Nonce", nonce); put.addHeader("Content-Type", "application/atom+xml"); ByteArrayEntity entity = new ByteArrayEntity(comment.getBytes("UTF-8")); put.body(entity); Executor exec = ExecutorUtil.getExecutor(); Response apiResponse = exec.execute(put); HttpResponse hr = apiResponse.returnResponse(); /** * Check the status codes */ int code = hr.getStatusLine().getStatusCode(); // Checks the status code for the response if (code == HttpStatus.SC_FORBIDDEN) { // Session is no longer valid or access token is expired response.setStatus(HttpStatus.SC_FORBIDDEN); } else if (code == HttpStatus.SC_UNAUTHORIZED) { // User is not authorized response.setStatus(HttpStatus.SC_UNAUTHORIZED); } else { // Default to 200 response.setStatus(HttpStatus.SC_OK); } } catch (IOException e) { response.setHeader("X-Application-Error", e.getClass().getName()); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); logger.severe("Issue with update comment" + e.toString()); } catch (JSONException e) { response.setHeader("X-Application-Error", e.getClass().getName()); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); logger.severe("Issue with update comments " + e.toString()); e.printStackTrace(); } }
From source file:org.eclipse.userstorage.internal.Session.java
public boolean updateBlob(String applicationToken, String key, final Map<String, String> properties, final InputStream in, ICredentialsProvider credentialsProvider) throws IOException, ConflictException { URI uri = StringUtil.newURI(service.getServiceURI(), "api/blob/" + applicationToken + "/" + key); return new RequestTemplate<Boolean>(uri) { @Override/*from w ww .j a v a2 s . c o m*/ protected Request prepareRequest() throws IOException { Request request = configureRequest(Request.Put(uri), uri); String eTag = properties.get(Blob.ETAG); if (DEBUG) { System.out.println("Updating etag = " + eTag); } if (!StringUtil.isEmpty(eTag)) { request.setHeader(IF_MATCH, "\"" + eTag + "\""); } body = JSONUtil.build(Collections.singletonMap("value", in)); request.bodyStream(body); return request; } @Override protected Boolean handleResponse(HttpResponse response, HttpEntity responseEntity) throws IOException { String eTag = getETag(response); int statusCode = getStatusCode("PUT", uri, response, OK, CREATED, CONFLICT); if (statusCode == CONFLICT) { StatusLine statusLine = response.getStatusLine(); throw new ConflictException("PUT", uri, getProtocolVersion(statusLine), statusLine.getReasonPhrase(), eTag); } if (eTag == null) { throw new ProtocolException("PUT", uri, getProtocolVersion(response.getStatusLine()), BAD_RESPONSE, "Bad Response : No ETag"); } if (DEBUG) { System.out.println("Updated etag = " + eTag); } properties.put(Blob.ETAG, eTag); return statusCode == CREATED; } }.send(credentialsProvider); }
From source file:eu.esdihumboldt.hale.io.geoserver.rest.AbstractResourceManager.java
/** * @see eu.esdihumboldt.hale.io.geoserver.rest.ResourceManager#update(java.util.Map) *//*from w w w. j a v a2 s. c o m*/ @Override public void update(Map<String, String> parameters) { checkResourceSet(); try { URI requestUri = buildRequestUri(getResourceURL(), parameters); ByteArrayEntity entity = new ByteArrayEntity(resource.asByteArray()); entity.setContentType(resource.contentType().getMimeType()); executor.execute(Request.Put(requestUri).body(entity)).handleResponse(new EmptyResponseHandler()); } catch (Exception e) { throw new ResourceException(e); } }
From source file:com.streamsets.stage.destination.waveanalytics.WaveAnalyticsTarget.java
private void runDataflow(String dataflowId) throws IOException { try {//from w w w . ja va 2 s. co m HttpResponse res = Request.Put(restEndpoint + String.format(startDataflow, dataflowId)) .addHeader("Authorization", "OAuth " + connection.getConfig().getSessionId()).execute() .returnResponse(); int statusCode = res.getStatusLine().getStatusCode(); String content = EntityUtils.toString(res.getEntity()); LOG.info("PUT dataflow with result {} content {}", statusCode, content); } catch (HttpResponseException e) { LOG.error("PUT dataflow with result {} {}", e.getStatusCode(), e.getMessage()); throw e; } }
From source file:com.softinstigate.restheart.integrationtest.SecurityIT.java
@Test public void testPutAsAdmin() throws Exception { try {//from w w w. j a v a 2 s. c om // *** PUT root Response resp = adminExecutor.execute(Request.Put(rootUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put root as admin", resp, HttpStatus.SC_METHOD_NOT_ALLOWED); // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db as admin", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1 as admin", resp, HttpStatus.SC_CREATED); // *** PUT doc1 resp = adminExecutor.execute(Request.Put(documentTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put doc1 as admin", resp, HttpStatus.SC_CREATED); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:com.helger.peppol.smpclient.SMPClient.java
/** * Saves a service meta data object. The ServiceGroupReference value is * ignored./*w ww .java 2 s. c om*/ * * @param aServiceMetadata * The service meta data object to save. * @param aCredentials * The user name and password to use as aCredentials. * @throws SMPClientException * in case something goes wrong * @throws SMPClientUnauthorizedException * The user name or password was not correct. * @throws SMPClientNotFoundException * A HTTP Not Found was received. This can happen if the service was * not found. * @throws SMPClientBadRequestException * The request was not well formed. */ public void saveServiceRegistration(@Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException { ValueEnforcer.notNull(aServiceMetadata, "ServiceMetadata"); ValueEnforcer.notNull(aServiceMetadata.getServiceInformation(), "ServiceMetadata.ServiceInformation"); ValueEnforcer.notNull(aServiceMetadata.getServiceInformation().getParticipantIdentifier(), "ServiceMetadata.ServiceInformation.ParticipantIdentifier"); ValueEnforcer.notNull(aServiceMetadata.getServiceInformation().getDocumentIdentifier(), "ServiceMetadata.ServiceInformation.DocumentIdentifier"); ValueEnforcer.notNull(aCredentials, "Credentials"); final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation(); final IParticipantIdentifier aServiceGroupID = aServiceInformation.getParticipantIdentifier(); final IDocumentTypeIdentifier aDocumentTypeID = aServiceInformation.getDocumentIdentifier(); try { final String sBody = new SMPMarshallerServiceMetadataType().getAsXMLString(aServiceMetadata); final Request aRequest = Request .Put(getSMPHostURI() + IdentifierHelper.getIdentifierURIPercentEncoded(aServiceGroupID) + "/services/" + IdentifierHelper.getIdentifierURIPercentEncoded(aDocumentTypeID)) .addHeader(CHTTPHeader.AUTHORIZATION, aCredentials.getRequestValue()) .bodyString(sBody, CONTENT_TYPE_TEXT_XML); executeRequest(aRequest).handleResponse(new SMPHttpResponseHandlerWriteOperations()); } catch (final Exception ex) { throw getConvertedException(ex); } }
From source file:de.elomagic.maven.http.HTTPMojo.java
private Request createRequestMethod() throws Exception { switch (method) { case DELETE://from w w w . ja v a 2 s.com return Request.Delete(url.toURI()); case GET: return Request.Get(url.toURI()); case HEAD: return Request.Head(url.toURI()); case POST: return Request.Post(url.toURI()); case PUT: return Request.Put(url.toURI()); } throw new Exception("Unsupported HTTP method \"" + method + "\"."); }