List of usage examples for org.apache.http.client.methods HttpPut setEntity
public void setEntity(final HttpEntity entity)
From source file:io.logspace.agent.hq.HqClient.java
public void uploadCapabilities(AgentControllerCapabilities capabilities) throws IOException { HttpPut httpPut = new HttpPut(this.baseUrl + "/api/capabilities/" + this.agentControllerId); httpPut.setEntity(toJSonEntity(capabilities)); httpPut.addHeader("logspace.space-token", this.spaceToken); this.httpClient.execute(httpPut, new UploadCapabilitiesResponseHandler()); }
From source file:com.nominanuda.hyperapi.HyperApiWsSkeltonTest.java
@Test public void testFoo() throws Exception { HyperApiWsSkelton skelton = new HyperApiWsSkelton(); skelton.setApi(TestHyperApi.class); skelton.setService(new TestHyperApi() { public DataObject putFoo(String bar, String baz, DataObject foo) { return foo; }//from ww w . j a va2s.c o m }); skelton.setRequestUriPrefix("/mytest"); HttpPut request = new HttpPut("/mytest/foo/BAR?baz=BAZ"); DataObject foo = new DataObjectImpl(); foo.put("foo", "FOO"); request.setEntity(new StringEntity(new DataStructHelper().toJsonString(foo), ContentType.create(HttpProtocol.CT_APPLICATION_JSON, HttpProtocol.CS_UTF_8))); HttpResponse response = skelton.handle(request); DataStruct result = new JSONParser().parse(new InputStreamReader(response.getEntity().getContent())); Assert.assertEquals("FOO", ((DataObject) result).get("foo")); }
From source file:org.envirocar.app.dao.remote.RemoteUserDAO.java
@Override public void updateUser(User user) throws UserUpdateException, UnauthorizedException { HttpPut put = new HttpPut(ECApplication.BASE_URL + "/users/" + user.getUsername()); try {// w ww .j av a 2 s . co m put.setEntity(new StringEntity(user.toJson())); super.executePayloadRequest(put); } catch (UnsupportedEncodingException e) { throw new UserUpdateException(e); } catch (JSONException e) { throw new UserUpdateException(e); } catch (NotConnectedException e) { throw new UserUpdateException(e); } catch (ResourceConflictException e) { throw new UserUpdateException(e); } }
From source file:com.urbancode.ud.client.ProcessClient.java
public void setProcessRequestProperty(String processId, String name, String value, boolean isSecure) throws IOException, JSONException { if (StringUtils.isEmpty(processId)) { throw new IOException("processId was not supplied"); }/* w w w .j a va2 s. co m*/ if (StringUtils.isEmpty(name)) { throw new IOException("name was not supplied"); } String uri = url + "/rest/process/request/" + encodePath(processId) + "/saveProperties"; JSONArray props = new JSONArray(); props.put(createNewPropertyJSON(name, value, isSecure)); HttpPut method = new HttpPut(uri); method.setEntity(getStringEntity(props)); invokeMethod(method); }
From source file:org.flowable.admin.service.engine.EventSubscriptionService.java
public void triggerExecutionEvent(ServerConfig serverConfig, String eventType, String eventName, String executionId) {// ww w . ja v a 2 s . c o m ObjectNode node = JsonNodeFactory.instance.objectNode(); if ("message".equals(eventType)) { node.put("action", "messageEventReceived"); node.put("messageName", eventName); } else if ("signal".equals(eventType)) { node.put("action", "signalEventReceived"); node.put("signalName", eventName); } else { throw new FlowableServiceException("Unsupported event type " + eventType); } HttpPut put = clientUtil.createPut("runtime/executions/" + executionId, serverConfig); put.setEntity(clientUtil.createStringEntity(node)); clientUtil.executeRequest(put, serverConfig); }
From source file:org.privatenotes.sync.web.AnonymousConnection.java
@Override public String put(String uri, String data) throws UnknownHostException { // Prepare a request object HttpPut httpPut = new HttpPut(uri); try {// ww w. j a va 2 s . co m // The default http content charset is ISO-8859-1, JSON requires UTF-8 httpPut.setEntity(new StringEntity(data, "UTF-8")); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); return null; } httpPut.setHeader("Content-Type", "application/json"); HttpResponse response = execute(httpPut); return parseResponse(response); }
From source file:org.energy_home.jemma.utils.rest.RestClient.java
public HttpResponse put(URI uri, HttpEntity entity) throws ClientProtocolException, IOException { HttpPut request = new HttpPut(uri); request.setEntity(entity); return send(request); }
From source file:com.activiti.service.activiti.ProcessDefinitionService.java
public JsonNode updateProcessDefinitionCategory(ServerConfig serverConfig, String definitionId, String category) {/*from ww w . ja v a 2s. c om*/ ObjectNode updateCall = objectMapper.createObjectNode(); updateCall.put("category", category); URIBuilder builder = clientUtil.createUriBuilder("repository/process-definitions/" + definitionId); HttpPut put = clientUtil.createPut(builder, serverConfig); put.setEntity(clientUtil.createStringEntity(updateCall)); return clientUtil.executeRequest(put, serverConfig); }
From source file:org.apache.manifoldcf.scriptengine.PUTCommand.java
/** Parse and execute. Parsing begins right after the command name, and should stop before the trailing semicolon. *@param sp is the script parser to use to help in the parsing. *@param currentStream is the current token stream. *@return true to send a break signal, false otherwise. *//* ww w . ja va2s. c om*/ public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream) throws ScriptException { VariableReference result = sp.evaluateExpression(currentStream); if (result == null) sp.syntaxError(currentStream, "Missing result expression"); Token t = currentStream.peek(); if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("=")) sp.syntaxError(currentStream, "Missing '=' sign"); currentStream.skip(); VariableReference send = sp.evaluateExpression(currentStream); if (send == null) sp.syntaxError(currentStream, "Missing send expression"); t = currentStream.peek(); if (t == null || t.getToken() == null || !t.getToken().equals("to")) sp.syntaxError(currentStream, "Missing 'to'"); currentStream.skip(); VariableReference url = sp.evaluateExpression(currentStream); if (url == null) sp.syntaxError(currentStream, "Missing URL expression"); // Perform the actual PUT. String urlString = sp.resolveMustExist(currentStream, url).getStringValue(); Configuration configuration = sp.resolveMustExist(currentStream, send).getConfigurationValue(); try { String json = configuration.toJSON(); HttpClient client = sp.getHttpClient(); HttpPut method = new HttpPut(urlString); try { method.setEntity(new StringEntity(json, ContentType.create("text/plain", StandardCharsets.UTF_8))); HttpResponse httpResponse = client.execute(method); int resultCode = httpResponse.getStatusLine().getStatusCode(); String resultJSON = sp.convertToString(httpResponse); result.setReference(new VariableResult(resultCode, resultJSON)); return false; } finally { //method.releaseConnection(); } } catch (ManifoldCFException e) { throw new ScriptException(e.getMessage(), e); } catch (IOException e) { throw new ScriptException(e.getMessage(), e); } }
From source file:com.jaeksoft.searchlib.remote.UriWriteStream.java
public UriWriteStream(URI uri, File file) throws IOException { HttpPut httpPut = new HttpPut(uri.toASCIIString()); httpPut.setConfig(requestConfig);/* w w w .j a v a 2s. c o m*/ FileEntity fre = new FileEntity(file, ContentType.DEFAULT_BINARY); httpPut.setEntity(fre); execute(httpPut); }