Search in sources :

Example 41 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project cloudstack by apache.

the class NeutronNodeAdapterTest method gsonNeutronPortMarshalingTest.

@Test
public void gsonNeutronPortMarshalingTest() throws NeutronRestApiException {
    NeutronNode node = new NeutronNode("node-test", "test");
    NeutronNodeWrapper nodeWrapper = new NeutronNodeWrapper(node);
    StringRequestEntity entity;
    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());
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) NeutronNode(org.apache.cloudstack.network.opendaylight.api.model.NeutronNode) NeutronNodeWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 42 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project cloudstack by apache.

the class NeutronNetworkAdapterTest method gsonNeutronNetworkMarshalingTest.

@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);
    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());
    }
}
Also used : NeutronNetwork(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper) Test(org.junit.Test)

Example 43 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project cloudstack by apache.

the class NeutronPortAdapterTest method gsonNeutronPortMarshalingTest.

@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);
    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());
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) NeutronPort(org.apache.cloudstack.network.opendaylight.api.model.NeutronPort) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronPortWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper) Test(org.junit.Test)

Example 44 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project cloudstack by apache.

the class NeutronNetworksNorthboundAction method updateNeutronNetwork.

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);
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)

Example 45 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project cloudstack by apache.

the class NeutronPortsNorthboundAction method updateNeutronPort.

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);
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)

Aggregations

StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)102 PostMethod (org.apache.commons.httpclient.methods.PostMethod)63 HttpClient (org.apache.commons.httpclient.HttpClient)33 Test (org.junit.Test)23 PutMethod (org.apache.commons.httpclient.methods.PutMethod)19 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)18 IOException (java.io.IOException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 AuthRequestHandler (org.apache.commons.httpclient.server.AuthRequestHandler)12 HttpRequestHandlerChain (org.apache.commons.httpclient.server.HttpRequestHandlerChain)12 HttpServiceHandler (org.apache.commons.httpclient.server.HttpServiceHandler)12 Header (org.apache.commons.httpclient.Header)9 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)9 GetMethod (org.apache.commons.httpclient.methods.GetMethod)9 InputStream (java.io.InputStream)8 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)7 StringWriter (java.io.StringWriter)6 Map (java.util.Map)6 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)6 PutMethod (org.apache.jackrabbit.webdav.client.methods.PutMethod)6