List of usage examples for org.apache.commons.httpclient.methods StringRequestEntity StringRequestEntity
public StringRequestEntity(String paramString1, String paramString2, String paramString3) throws UnsupportedEncodingException
From source file:org.apache.cloudstack.network.element.SspClient.java
public TenantPort createTenantPort(String tenantNetworkUuid) { TenantPort req = new TenantPort(); req.networkUuid = tenantNetworkUuid; req.attachmentType = "NoAttachment"; PostMethod method = postMethod;/*from ww w . j ava 2 s.co m*/ method.setPath("/ssp.v1/tenant-ports"); StringRequestEntity entity = null; try { entity = new StringRequestEntity(new Gson().toJson(req), "application/json", "UTF-8"); } catch (UnsupportedEncodingException e) { s_logger.error("failed creating http request body", e); return null; } method.setRequestEntity(entity); String response = executeMethod(method); if (response != null && method.getStatusCode() == HttpStatus.SC_CREATED) { return new Gson().fromJson(response, TenantPort.class); } return null; }
From source file:org.apache.cloudstack.network.element.SspClient.java
public TenantPort updateTenantVifBinding(String portUuid, String hypervisorIpAddress) { TenantPort req = new TenantPort(); if (hypervisorIpAddress != null) { req.attachmentType = "VifAttachment"; req.hypervisorIpAddress = hypervisorIpAddress; } else {// ww w . ja va2 s.c o m req.attachmentType = "NoAttachment"; } PutMethod method = putMethod; method.setPath("/ssp.v1/tenant-ports/" + portUuid); StringRequestEntity entity = null; try { entity = new StringRequestEntity(new Gson().toJson(req), "application/json", "UTF-8"); } catch (UnsupportedEncodingException e) { s_logger.error("failed creating http request body", e); return null; } method.setRequestEntity(entity); String response = executeMethod(method); if (response != null && method.getStatusCode() == HttpStatus.SC_OK) { return new Gson().fromJson(response, TenantPort.class); } return null; }
From source file:org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction.java
@SuppressWarnings("unchecked") public <T> T createNeutronNetwork(final NeutronNetworkWrapper newNetworkWrapper) throws NeutronRestApiException { try {// w w w .java 2 s .com 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); } }
From source file:org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction.java
public <T> void updateNeutronNetwork(final String networkId, final NeutronNetworkWrapper newNetworkWrapper) throws NeutronRestApiException { try {/*from w w w . ja v a 2 s. c o m*/ 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); } }
From source file:org.apache.cloudstack.network.opendaylight.api.resources.NeutronPortsNorthboundAction.java
@SuppressWarnings("unchecked") public <T> T createNeutronPort(final NeutronPortWrapper newPortWrapper) throws NeutronRestApiException { try {//from w w w.ja v a 2s . c o m 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); } }
From source file:org.apache.cloudstack.network.opendaylight.api.resources.NeutronPortsNorthboundAction.java
public <T> void updateNeutronPort(final String portId, final NeutronPortWrapper newPortWrapper) throws NeutronRestApiException { try {/*from ww w . j a v a2 s .c o m*/ 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); } }
From source file:org.apache.cloudstack.network.opendaylight.api.test.NeutronNetworkAdapterTest.java
@Test public void gsonNeutronNetworkMarshalingTest() throws NeutronRestApiException { NeutronNetwork network = new NeutronNetwork(); network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); network.setName("test_gre"); network.setNetworkType("test"); network.setSegmentationId(1001);/* w w w .j a va 2 s.c om*/ network.setShared(true); network.setTenantId("wilder"); NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper(); networkWrapper.setNetwork(network); StringRequestEntity entity; try { entity = new StringRequestEntity(gsonNeutronNetwork.toJson(networkWrapper), "application/json", null); String actual = entity.getContent(); Assert.assertEquals(jsonString, actual); } catch (UnsupportedEncodingException e) { Assert.fail(e.getMessage()); } }
From source file:org.apache.cloudstack.network.opendaylight.api.test.NeutronNodeAdapterTest.java
@Test public void gsonNeutronPortMarshalingTest() throws NeutronRestApiException { NeutronNode node = new NeutronNode("node-test", "test"); NeutronNodeWrapper nodeWrapper = new NeutronNodeWrapper(node); StringRequestEntity entity;//from w w w. j a v a2s . c o m try { entity = new StringRequestEntity(gsonNeutronNode.toJson(nodeWrapper), "application/json", null); String actual = entity.getContent(); Assert.assertEquals(jsonString, actual); } catch (UnsupportedEncodingException e) { Assert.fail(e.getMessage()); } }
From source file:org.apache.cloudstack.network.opendaylight.api.test.NeutronPortAdapterTest.java
@Test public void gsonNeutronPortMarshalingTest() throws NeutronRestApiException { NeutronPort port = new NeutronPort(); port.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); port.setName("test_gre"); port.setAdminStateUp(true);//from w ww . j a v a 2 s .c om port.setDeviceId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); port.setMacAddress("ca31aa7f-84c7-416d-bc00-1f84927367e0"); port.setNetworkId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); port.setStatus("ACTIVE"); port.setTenantId("wilder"); NeutronPortWrapper portWrapper = new NeutronPortWrapper(); portWrapper.setPort(port); StringRequestEntity entity; try { entity = new StringRequestEntity(gsonNeutronPort.toJson(portWrapper), "application/json", null); String actual = entity.getContent(); Assert.assertEquals(jsonString, actual); } catch (UnsupportedEncodingException e) { Assert.fail(e.getMessage()); } }
From source file:org.apache.cxf.systest.jaxrs.JAXRSAtomBookTest.java
private Entry addEntry(String endpointAddress) throws Exception { Entry e = createBookEntry(256, "AtomBook"); StringWriter w = new StringWriter(); e.writeTo(w);/* w w w.j a v a 2s. c o m*/ PostMethod post = new PostMethod(endpointAddress); post.setRequestEntity(new StringRequestEntity(w.toString(), "application/atom+xml", null)); HttpClient httpclient = new HttpClient(); String location = null; try { int result = httpclient.executeMethod(post); assertEquals(201, result); location = post.getResponseHeader("Location").getValue(); InputStream ins = post.getResponseBodyAsStream(); Document<Entry> entryDoc = abdera.getParser().parse(copyIn(ins)); assertEquals(entryDoc.getRoot().toString(), e.toString()); } finally { post.releaseConnection(); } Entry entry = getEntry(location, null); assertEquals(location, entry.getBaseUri().toString()); assertEquals("AtomBook", entry.getTitle()); return entry; }