Example usage for org.apache.http.client HttpResponseException printStackTrace

List of usage examples for org.apache.http.client HttpResponseException printStackTrace

Introduction

In this page you can find the example usage for org.apache.http.client HttpResponseException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java

@Override
public int delete(Application obj) {
    HttpGetSimpleResp resp;/*from   w ww .java 2s. c  o  m*/
    int appResponse = -1;
    try {
        resp = WebServiceActions.doDelete(this.OM2MUrlBase + "applications/" + obj.getAppId(), headers);
        appResponse = resp.getStatusCode();
    } catch (HttpResponseException e) {
        LOGGER.error("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
    } catch (ConnectException e) {
        LOGGER.error(
                e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    return appResponse;
}

From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java

@Override
public Application get(String id) {
    Application appResponse = null;//from w ww  .  j ava2  s . co  m

    HttpGetSimpleResp resp;
    try {
        resp = WebServiceActions.doGet(this.OM2MUrlBase + "applications/" + id, headers);
        if (resp.getStatusCode() == 200)
            appResponse = (Application) JAXBMapper.XMLStringToObject(resp.getResult(), Application.class);
    } catch (HttpResponseException e) {
        LOGGER.error("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
    } catch (ConnectException e) {
        LOGGER.error(
                e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }

    return appResponse;
}

From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java

/**
 * Exist./* ww w .  j  a  va2 s .com*/
 * 
 * @param obj
 *            the obj
 * @return true, if successful
 */
@Override
public boolean exist(Application obj) {
    HttpGetSimpleResp resp;
    try {
        resp = WebServiceActions.doGet(this.OM2MUrlBase + "applications/" + obj.getAppId(), headers);
        if (resp.getStatusCode() == 200)
            return true;
    } catch (HttpResponseException e) {
        // LOGGER.warn("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
    } catch (ConnectException e) {
        LOGGER.error(
                e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    return false;
}

From source file:JenkinsHelper.java

public void runJob(String test, JSONObject repository, Map<String, String> params) throws Exception {
    String jobName = ConfigParser.parseConfigString(repository.getString("jobName"), test);

    try {/*from w ww  .  j a v a 2s.c o  m*/
        jenkins.getJob(jobName).build(params, crumbsFlag);
    } catch (HttpResponseException e) {
        System.out.println("Running job [" + jobName + "] with parameters failed, params sent:");
        System.out.println(params);
        e.printStackTrace();
    }
}

From source file:fr.lissi.belilif.om2m.oao.ContentInstanceManager.java

@Override
public int create(ContentInstance obj) {

    if (obj.getContainer() == null || obj.getContainer().getApplication().getAppId() == null) {
        LOGGER.error(//from   w  ww .  j  a v  a  2 s.c  om
                "you must specify the parent resource (parent Container) to create a ContentInstanceManager instance.");
        return -1;
    }

    LOGGER.info("Create ContentInstance '" + obj.getValueAsString() + "' for "
            + obj.getContainer().getApplication().getAppId() + "/" + obj.getContainer().getId());
    int resp = -1;
    try {
        resp = WebServiceActions.doPost(
                this.OM2MUrlBase + "applications/" + obj.getContainer().getApplication().getAppId()
                        + "/containers/" + obj.getContainer().getId() + "/contentInstances",
                obj.getValueAsString(), this.headers);

        LOGGER.info("ContentInstance creation in '" + obj.getContainer().getApplication().getAppId() + "/"
                + obj.getContainer().getId() + "' status : " + resp);
    } catch (HttpResponseException e) {
        resp = e.getStatusCode();
        LOGGER.info(e.getStatusCode() + " / " + e.getMessage());
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO ClientProtocolException
        e.printStackTrace();
    } catch (IOException e) {
        // TODO IOException
        e.printStackTrace();
    }
    return resp;
}

From source file:JenkinsHelper.java

public void runJob(String test, JSONObject repository) throws Exception {
    String jobName = ConfigParser.parseConfigString(repository.getString("jobName"), test);
    Map<String, String> params = new HashMap<>();
    if (repository.has("buildParams")) {
        JSONObject buildParams = repository.getJSONObject("buildParams");
        Iterator keys = buildParams.keys();
        while (keys.hasNext()) {
            String key = (String) keys.next();
            params.put(key, buildParams.getString(key));
        }/*from   w  w  w  .jav  a 2 s  .c o m*/
        System.out.println("Running job with parameters [" + jobName + "]");
        runJob(test, repository, params);
    } else {
        System.out.println("Running job without parameters [" + jobName + "]");
        try {
            jenkins.getJob(jobName).build(crumbsFlag);
        } catch (HttpResponseException e) {
            System.out.println("Running job [" + jobName
                    + "] without parameters failed, were there supposed to be parameters?");
            e.printStackTrace();
        }
    }
}

From source file:fr.lissi.belilif.om2m.oao.ContainerManager.java

/**
 * Exist.//from  w w  w.  ja  v a2 s  .  com
 *
 * @param obj
 *            the obj
 * @return true, if successful
 */
@Override
public boolean exist(Container obj) {
    if (obj.getApplication() == null || obj.getApplication().getAppId() == null) {
        LOGGER.error("you must specify the parent resource (parent Application) to manage containers.");
        return false;
    }

    HttpGetSimpleResp resp;
    try {
        resp = WebServiceActions.doGet(this.OM2MUrlBase + "applications/" + obj.getApplication().getAppId()
                + "/containers/" + obj.getId(), headers);
        if (resp.getStatusCode() == 200)
            return true;
    } catch (HttpResponseException e) {
        // LOGGER.warn("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
    } catch (ConnectException e) {
        LOGGER.error(
                e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    return false;
}

From source file:fr.lissi.belilif.om2m.oao.ContentInstanceManager.java

@Override
public int subscribe(ContentInstance obj, Subscription subscription) {
    LOGGER.info("Create : \n" + JAXBMapper.objectToXMLString(obj));
    int resp = -1;
    try {/*ww  w. j a  va 2  s. c  om*/
        resp = WebServiceActions.doPost(
                this.OM2MUrlBase + "applications/" + obj.getContainer().getApplication().getAppId()
                        + "/containers/" + JAXBMapper.objectToXMLString(subscription)
                        + "/contentInstances/subscriptions",
                "BODY-" + new String(obj.getContent().getValue()), this.headers); // ID pas content
    } catch (HttpResponseException e) {
        resp = e.getStatusCode();
        LOGGER.info(e.getStatusCode() + " / " + e.getMessage());
    } catch (ClientProtocolException e) {
        // TODO ClientProtocolException
        e.printStackTrace();
    } catch (IOException e) {
        // TODO IOException
        e.printStackTrace();
    }
    return resp;
}

From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java

@Override
public int create(Application obj) {
    String appInXML = JAXBMapper.objectToXMLString(obj);
    LOGGER.info("App to create : " + obj.getAppId());
    LOGGER.info(obj.getAppId() + " in OM2M XML strcuture : \n" + appInXML);
    // appeler le client REST avec le code XML correspondant
    int resp = -1;
    try {/*from w  ww.  jav a2 s  . c  o  m*/
        resp = WebServiceActions.doPost(this.OM2MUrlBase + "applications", appInXML, this.headers);
        LOGGER.info("Application '" + obj.getAppId() + "' creation status : " + resp);
    } catch (HttpResponseException e) {
        resp = e.getStatusCode();
        LOGGER.error("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage() + "\n"
                + "Unable to create the application '" + obj.getAppId() + "' with " + this.OM2MUrlBase
                + "applications");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
    } catch (ConnectException e) {
        LOGGER.error(
                e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    return resp;
}

From source file:fr.lissi.belilif.om2m.oao.ContainerManager.java

@Override
public int create(Container obj) {
    // verifier si le container existe avant d'en crer : laisser a au utilisateurs
    // Om2mManager om2mManager = Om2mManagersFactorty.getManager(Om2mManagersFactorty.CONTAINER_MANAGER);
    // OM2MContainerResponse respExist = (OM2MContainerResponse) om2mManager.get(obj);
    // if (respExist != null) {
    // LOGGER.info("Le container existe");
    // } // else System.out.println("Le container n'existe pas.");

    if (obj.getApplication() == null || obj.getApplication().getAppId() == null) {
        LOGGER.error("you must specify the parent resource (parent Application) to manage containers.");
        return -1;
    }//from  w  w w. j  ava2s.c  o m

    LOGGER.debug("Container to create in '" + obj.getApplication().getAppId() + "' : \n"
            + JAXBMapper.objectToXMLString(obj));
    LOGGER.info("Container to create in '" + obj.getApplication().getAppId() + "' : " + obj.getId());
    int resp = -1;
    try {
        resp = WebServiceActions.doPost(
                this.OM2MUrlBase + "applications/" + obj.getApplication().getAppId() + "/containers",
                JAXBMapper.objectToXMLString(obj), this.headers);
        LOGGER.info("Container '" + obj.getId() + "' creation in '" + obj.getId() + "' status : " + resp);
    } catch (HttpResponseException e) {
        resp = e.getStatusCode();
        LOGGER.error(e.getStatusCode() + " / " + e.getMessage() + ". " + this.OM2MUrlBase + "applications/"
                + obj.getApplication().getAppId() + "/containers");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
    } catch (ConnectException e) {
        LOGGER.error(
                e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    return resp;
}