String charset = getRequestCharSet(); try { this.requestEntity = new StringRequestEntity( requestString, null, charset); } catch (UnsupportedEncodingException e) { this.requestEntity = new StringRequestEntity( requestString, null, null); } catch (UnsupportedEncodingException ignore) {
public <T> void updateNeutronNetwork(final String networkId, final NeutronNetworkWrapper newNetworkWrapper) throws NeutronRestApiException { try { String uri = NeutronNorthboundEnum.NETWORK_PARAM_URI.getUri(); uri = MessageFormat.format(uri, networkId); StringRequestEntity entity = new StringRequestEntity(gsonNeutronNetwork.toJson(newNetworkWrapper), JSON_CONTENT_TYPE, null); executePut(uri, entity); } catch (UnsupportedEncodingException e) { throw new NeutronRestApiException("Failed to encode json request body", e); } }
public <T> void updateNeutronPort(final String portId, final NeutronPortWrapper newPortWrapper) throws NeutronRestApiException { try { String uri = NeutronNorthboundEnum.PORTS_PARAM_URI.getUri(); uri = MessageFormat.format(uri, portId); StringRequestEntity entity = new StringRequestEntity(gsonNeutronPort.toJson(newPortWrapper), JSON_CONTENT_TYPE, null); executePut(uri, entity); } catch (UnsupportedEncodingException e) { throw new NeutronRestApiException("Failed to encode json request body", e); } }
@SuppressWarnings("unchecked") public <T> T createNeutronNetwork(final NeutronNetworkWrapper newNetworkWrapper) throws NeutronRestApiException { try { String uri = NeutronNorthboundEnum.NETWORKS_URI.getUri(); StringRequestEntity entity = new StringRequestEntity(gsonNeutronNetwork.toJson(newNetworkWrapper), JSON_CONTENT_TYPE, null); String bodystring = executePost(uri, entity); T result = (T) gsonNeutronNetwork.fromJson(bodystring, TypeToken.get(NeutronNetworkWrapper.class).getType()); return result; } catch (UnsupportedEncodingException e) { throw new NeutronRestApiException("Failed to encode json request body", e); } }
@SuppressWarnings("unchecked") public <T> T createNeutronPort(final NeutronPortWrapper newPortWrapper) throws NeutronRestApiException { try { String uri = NeutronNorthboundEnum.PORTS_URI.getUri(); StringRequestEntity entity = new StringRequestEntity(gsonNeutronPort.toJson(newPortWrapper), JSON_CONTENT_TYPE, null); String bodystring = executePost(uri, entity); T result = (T) gsonNeutronPort.fromJson(bodystring, TypeToken.get(NeutronPortWrapper.class).getType()); return result; } catch (UnsupportedEncodingException e) { throw new NeutronRestApiException("Failed to encode json request body", e); } }
StringRequestEntity requestEntity = new StringRequestEntity(postBody, "application/json", "UTF-8"); post.setRequestEntity(requestEntity);
@Override public void connect() throws ConnectionException { PostMethod post = new PostMethod(conn.getConnectUrl()); HttpClient httpClient = new HttpClient(); if (conn.getConnectUrl().toLowerCase().startsWith("https://")) { registerSsl(); } addPostHeaders(post); try { StringRequestEntity requestEntity = new StringRequestEntity("{}", "application/json", "UTF-8"); post.setRequestEntity(requestEntity); httpClient.executeMethod(post); if (post.getStatusCode() != 200 && post.getStatusCode() != 201) { logger.error("Connect failed with error code " + post.getStatusCode() + " and message:\n" + post.getResponseBodyAsString()); throw new ConnectionException("Connect failed, error code " + post.getStatusCode() + " and message: " + post.getResponseBodyAsString()); } } catch (HttpException e) { logger.error(e.getLocalizedMessage(), e); throw new ConnectionException(e.getLocalizedMessage()); } catch (IOException e) { logger.error(e.getLocalizedMessage(), e); throw new ConnectionException(e.getLocalizedMessage()); } }
@Override public void prepareRequest() throws Exception { PostMethod method = new PostMethod(URL); method.setRequestHeader(HEADER_NAME, HEADER_VALUE); RequestEntity body = new StringRequestEntity(PAYLOAD,CONTENT_TYPE,null); method.setRequestEntity(body); request = new Http3RequestAdapter(method); } }
public String call(String xml) { PostMethod post = new PostMethod(url); post.setRequestEntity(new StringRequestEntity(xml)); post.setRequestHeader("Content-type", "text/xml");
protected <T> String executeCreateObject(final T newObject, final String uri, final Map<String, String> parameters) throws BigSwitchBcfApiException { checkInvariants(); PostMethod pm = (PostMethod)createMethod("post", uri, _port); setHttpHeader(pm); try { pm.setRequestEntity(new StringRequestEntity(gson.toJson(newObject), CONTENT_JSON, null)); } catch (UnsupportedEncodingException e) { throw new BigSwitchBcfApiException("Failed to encode json request body", e); } executeMethod(pm); String hash = checkResponse(pm, "BigSwitch HTTP create failed: "); pm.releaseConnection(); return hash; }
protected <T> String executeUpdateObject(final T newObject, final String uri, final Map<String, String> parameters) throws BigSwitchBcfApiException, IllegalArgumentException{ checkInvariants(); PutMethod pm = (PutMethod)createMethod("put", uri, _port); setHttpHeader(pm); try { pm.setRequestEntity(new StringRequestEntity(gson.toJson(newObject), CONTENT_JSON, null)); } catch (UnsupportedEncodingException e) { throw new BigSwitchBcfApiException("Failed to encode json request body", e); } executeMethod(pm); String hash = checkResponse(pm, "BigSwitch HTTP update failed: "); pm.releaseConnection(); return hash; }
StringRequestEntity entity = new StringRequestEntity(xmlContents); post.setRequestEntity(entity); if (httpClient.executeMethod(post) != 200) {
public void setRequestContentAsString(String content) throws HTTPException { try { this.content = new StringRequestEntity(content, "application/text", "UTF-8"); } catch (UnsupportedEncodingException ue) { } }
public void setRequestContentAsString(String content) throws HTTPException { try { this.content = new StringRequestEntity(content,"application/text", "UTF-8"); } catch (UnsupportedEncodingException ue) {} }
String xml = "whatever.your.xml.is.here"; PostMethod post = new PostMethod(strURL); try { StringRequestEntity requestEntity = new StringRequestEntity(xml); post.setRequestEntity(requestEntity); ....
public void setRequestBody(String body) { try { requestBody = new StringRequestEntity(body, getContentType(), "UTF-8"); } catch (UnsupportedEncodingException e) {} // Can't occur } public void setRequestBody(byte[] body)
public RequestEntity getUndeployRequestEntity(String processId) throws DeploymentException { try { prepareUndeploySOAP(processId); return new StringRequestEntity(fContent); } catch (Exception e) { throw new DeploymentException( "Problem while creating SOAP request: " + e.getMessage(), e); } }
@Override public String postJson(String url, String body) throws RobotConnectionException { PostMethod method = new PostMethod(url); try { method.setRequestEntity(new StringRequestEntity(body, RobotConnection.JSON_CONTENT_TYPE, Charsets.UTF_8.name())); return fetch(url, method); } catch (IOException e) { String msg = "Robot fetch http failure: " + url + ": " + e; throw new RobotConnectionException(msg, e); } }
private void setRequestEntity(EntityEnclosingMethod request, AbstractQuery<?> query) { if (query.getBody() != null) { try { request.setRequestEntity(new StringRequestEntity(query.getBody(), "text/plain; charset=UTF-8", "UTF-8")); } catch (UnsupportedEncodingException e) { throw new ConnectionException("Unsupported encoding", e); } } }
private void writeCurrencyViaJson(String key, String description, int rank) throws IOException { EntityEnclosingMethod put = new PutMethod(restEndpoint + "/" + key); ObjectNode currency = MAPPER.createObjectNode(); currency.put(TYPE, getEntityName()); currency.put("description", description); currency.put("rank", rank); put.setRequestEntity(new StringRequestEntity(currency.toString(), "application/json", "UTF-8")); restClient.executeMethod(put); System.out.println(put.getResponseBodyAsString()); assertEquals(put.getStatusCode(), HttpStatus.SC_OK); }