Package org.apache.cloudstack.network.opendaylight.api

Examples of org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException


    public void executeMethod(final HttpMethodBase method) throws NeutronRestApiException {
        try {
            client.executeMethod(method);
        } catch (HttpException e) {
            method.releaseConnection();
            throw new NeutronRestApiException("API call to Neutron NVP Controller Failed", e);
        } catch (IOException e) {
            method.releaseConnection();
            throw new NeutronRestApiException("API call to Neutron NVP Controller Failed", e);
        }
    }
View Full Code Here


            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);
        }
    }
View Full Code Here

            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);
        }
    }
View Full Code Here

    public String executeGet(final String uri, final Map<String, String> parameters) throws NeutronRestApiException {
        try {
            validateCredentials();
        } catch (NeutronInvalidCredentialsException e) {
            throw new NeutronRestApiException("Invalid credentials!", e);
        }

        NeutronRestFactory factory = NeutronRestFactory.getInstance();

        NeutronRestApi neutronRestApi = factory.getNeutronApi(GetMethod.class);
        GetMethod getMethod = (GetMethod) neutronRestApi.createMethod(url, uri);

        try {
            getMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);

            String encodedCredentials = encodeCredentials();
            getMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials);

            if (parameters != null && !parameters.isEmpty()) {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size());
                for (Entry<String, String> e : parameters.entrySet()) {
                    nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));
                }
                getMethod.setQueryString(nameValuePairs.toArray(new NameValuePair[0]));
            }

            neutronRestApi.executeMethod(getMethod);

            if (getMethod.getStatusCode() != HttpStatus.SC_OK) {
                String errorMessage = responseToErrorMessage(getMethod);
                getMethod.releaseConnection();
                s_logger.error("Failed to retrieve object : " + errorMessage);
                throw new NeutronRestApiException("Failed to retrieve object : " + errorMessage);
            }

            return getMethod.getResponseBodyAsString();

        } catch (NeutronRestApiException e) {
            s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e);
            throw new NeutronRestApiException("API call to Neutron Controller Failed", e);
        } catch (IOException e) {
            throw new NeutronRestApiException(e);
        } finally {
            getMethod.releaseConnection();
        }
    }
View Full Code Here

    protected String executePost(final String uri, final StringRequestEntity entity) throws NeutronRestApiException {
        try {
            validateCredentials();
        } catch (NeutronInvalidCredentialsException e) {
            throw new NeutronRestApiException("Invalid credentials!", e);
        }

        NeutronRestFactory factory = NeutronRestFactory.getInstance();

        NeutronRestApi neutronRestApi = factory.getNeutronApi(PostMethod.class);
        PostMethod postMethod = (PostMethod) neutronRestApi.createMethod(url, uri);

        try {
            postMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
            postMethod.setRequestEntity(entity);

            String encodedCredentials = encodeCredentials();
            postMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials);

            neutronRestApi.executeMethod(postMethod);

            if (postMethod.getStatusCode() != HttpStatus.SC_CREATED) {
                String errorMessage = responseToErrorMessage(postMethod);
                postMethod.releaseConnection();
                s_logger.error("Failed to create object : " + errorMessage);
                throw new NeutronRestApiException("Failed to create object : " + errorMessage);
            }

            return postMethod.getResponseBodyAsString();
        } catch (NeutronRestApiException e) {
            s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e);
            throw new NeutronRestApiException("API call to Neutron Controller Failed", e);
        } catch (IOException e) {
            throw new NeutronRestApiException("Failed to load json response body", e);
        } finally {
            postMethod.releaseConnection();
        }
    }
View Full Code Here

    protected void executePut(final String uri, final StringRequestEntity entity) throws NeutronRestApiException {
        try {
            validateCredentials();
        } catch (NeutronInvalidCredentialsException e) {
            throw new NeutronRestApiException("Invalid credentials!", e);
        }

        NeutronRestFactory factory = NeutronRestFactory.getInstance();

        NeutronRestApi neutronRestApi = factory.getNeutronApi(PutMethod.class);
        PutMethod putMethod = (PutMethod) neutronRestApi.createMethod(url, uri);

        try {
            putMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
            putMethod.setRequestEntity(entity);

            String encodedCredentials = encodeCredentials();
            putMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials);

            neutronRestApi.executeMethod(putMethod);

            if (putMethod.getStatusCode() != HttpStatus.SC_OK) {
                String errorMessage = responseToErrorMessage(putMethod);
                putMethod.releaseConnection();
                s_logger.error("Failed to update object : " + errorMessage);
                throw new NeutronRestApiException("Failed to create object : " + errorMessage);
            }
        } catch (NeutronRestApiException e) {
            s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e);
            throw new NeutronRestApiException("API call to Neutron Controller Failed", e);
        } finally {
            putMethod.releaseConnection();
        }
    }
View Full Code Here

    protected String executePut(final String uri) throws NeutronRestApiException {
        try {
            validateCredentials();
        } catch (NeutronInvalidCredentialsException e) {
            throw new NeutronRestApiException("Invalid credentials!", e);
        }

        NeutronRestFactory factory = NeutronRestFactory.getInstance();

        NeutronRestApi neutronRestApi = factory.getNeutronApi(PutMethod.class);
        PutMethod putMethod = (PutMethod) neutronRestApi.createMethod(url, uri);

        try {
            String encodedCredentials = encodeCredentials();
            putMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials);

            neutronRestApi.executeMethod(putMethod);

            if (putMethod.getStatusCode() != HttpStatus.SC_OK) {
                String errorMessage = responseToErrorMessage(putMethod);
                putMethod.releaseConnection();
                s_logger.error("Failed to update object : " + errorMessage);
                throw new NeutronRestApiException("Failed to create object : " + errorMessage);
            }

            return putMethod.getResponseBodyAsString();
        } catch (NeutronRestApiException e) {
            s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e);
            throw new NeutronRestApiException("API call to Neutron Controller Failed", e);
        } catch (IOException e) {
            throw new NeutronRestApiException("Failed to load json response body", e);
        } finally {
            putMethod.releaseConnection();
        }
    }
View Full Code Here

    protected void executeDelete(final String uri) throws NeutronRestApiException {
        try {
            validateCredentials();
        } catch (NeutronInvalidCredentialsException e) {
            throw new NeutronRestApiException("Invalid credentials!", e);
        }

        NeutronRestFactory factory = NeutronRestFactory.getInstance();

        NeutronRestApi neutronRestApi = factory.getNeutronApi(DeleteMethod.class);
        DeleteMethod deleteMethod = (DeleteMethod) neutronRestApi.createMethod(url, uri);

        try {
            deleteMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);

            String encodedCredentials = encodeCredentials();
            deleteMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials);

            neutronRestApi.executeMethod(deleteMethod);

            if (deleteMethod.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
                String errorMessage = responseToErrorMessage(deleteMethod);
                deleteMethod.releaseConnection();
                s_logger.error("Failed to update object : " + errorMessage);
                throw new NeutronRestApiException("Failed to create object : " + errorMessage);
            }
        } catch (NeutronRestApiException e) {
            s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e);
            throw new NeutronRestApiException("API call to Neutron Controller Failed", e);
        } finally {
            deleteMethod.releaseConnection();
        }
    }
View Full Code Here

            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);
        }
    }
View Full Code Here

            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);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.