Example usage for javax.xml.ws.http HTTPException printStackTrace

List of usage examples for javax.xml.ws.http HTTPException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.ws.http HTTPException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:org.esgf.solr.proxy.SolrProxyController.java

private String relay(HttpServletRequest request, HttpServletResponse response) {
    System.out.println("--TIME MEASUREMENT FOR LOADING RESULTS--");

    long beginTime = System.nanoTime();

    String queryString = request.getQueryString();
    LOG.debug("queryString=" + queryString);
    String requestUri = request.getRequestURI();
    LOG.debug("requestUri=" + requestUri);

    String urlString = solrURL + "select?" + queryString + "&wt=json";

    String responseBody = null;//from  ww  w  .j  a v  a 2 s.com

    // create an http client
    HttpClient client = new HttpClient();

    // create a method instance
    GetMethod method = new GetMethod(urlString);

    // custom retry
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
    try {
        // execute the method
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + method.getStatusLine());

        }

        // read the response
        responseBody = method.getResponseBodyAsString();

    } catch (HTTPException e) {
        LOG.error("Fatal protocol violation");
        e.printStackTrace();
    } catch (IOException e) {
        LOG.error("Fatal transport error");
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }

    LOG.debug("Solr URL = " + urlString);
    //LOG.debug("responseBody = " + responseBody);

    long endTime = System.nanoTime();

    System.out.println("\tTotal Time: " + ((int) (endTime - beginTime)) + "ns");

    System.out.println("-----------------------------------------");

    return responseBody;
}

From source file:org.esgf.legacydatacart.LegacyOldFileTemplateController.java

/** (String id)
 * This method extracts all file records for a given dataset id and assembles them in json format
 * /*from  www  . j av a2s .  c o  m*/
 * @param id        Dataset Id
 * @return          Solr response for all files given the dataset id
 */

private static String getResponseBody(String queryString, String dataset_id) {

    //System.out.println("In getResponseBody");

    String responseBody = null;

    // create an http client
    HttpClient client = new HttpClient();

    //attact the dataset id to the query string
    GetMethod method = null;
    String combinedQueryStr = "";

    combinedQueryStr += queryString + "&fq=dataset_id:" + dataset_id + "&wt=json";
    method = new GetMethod(solrURL);

    method.setQueryString(combinedQueryStr);

    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
    try {
        // execute the method
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + method.getStatusLine());

        }

        // read the response
        responseBody = method.getResponseBodyAsString();
    } catch (HTTPException e) {
        LOG.error("Fatal protocol violation");
        e.printStackTrace();
    } catch (IOException e) {
        LOG.error("Fatal transport error");
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }

    return responseBody;
}

From source file:org.esgf.legacydatacart.LegacyOldFileTemplateController.java

private static String querySolrForFiles(String queryString, String dataset_id) {

    String marker = "\"response\":";

    String responseBody = null;/*from   w w  w .  j a  va 2  s  . c  o m*/

    // create an http client
    HttpClient client = new HttpClient();

    //attact the dataset id to the query string
    GetMethod method = new GetMethod(searchAPIURL);

    //add the dataset to the query string
    queryString += "&dataset_id=" + dataset_id;

    method.setQueryString(queryString);

    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    try {
        // execute the method
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + method.getStatusLine());

        }

        // read the response
        responseBody = method.getResponseBodyAsString();
    } catch (HTTPException e) {
        LOG.error("Fatal protocol violation");
        e.printStackTrace();
    } catch (IOException e) {
        LOG.error("Fatal transport error");
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }

    //just get the important part of the response (i.e. leave off the header and the facet info)
    int start = responseBody.lastIndexOf(marker) + marker.length();
    int end = responseBody.length();
    String responseString = responseBody.substring(start, end);

    return responseString;
}

From source file:org.esgf.legacydatacart.LegacyOldFileTemplateController.java

/**
 * /*w  w  w . j  av a  2  s  . com*/
 * @param queryString
 * @param dataset_id
 * @return
 */
private static String getResponseBodyUsingSearchAPI(String queryString, String dataset_id) {

    String responseBody = null;
    System.out.println("In getResponseBodyUsingSearchAPI");
    System.out.println("\tDatasetId: " + dataset_id + "\n\tqueryString: " + queryString);

    // create an http client
    HttpClient client = new HttpClient();

    //attact the dataset id to the query string
    GetMethod method = null;

    method = new GetMethod(searchAPIURL);

    //add distributed search to the query string
    //queryString += "&distrib=false";

    //add the dataset to the query string
    queryString += "&dataset_id=" + dataset_id;//replica=false";//"&dataset_id=" + "a";//dataset_id;

    //take this out
    queryString = "format=application%2Fsolr%2Bjson&type=File&shards=localhost:8983/solr&variable=hus&dataset_id=obs4MIPs.NASA-JPL.AIRS.mon.v1:esg-datanode.jpl.nasa.gov";

    System.out.println("\nResponse Body QueryString: " + queryString + "\n");

    method.setQueryString(queryString);

    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    try {
        // execute the method
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + method.getStatusLine());

        }

        // read the response
        responseBody = method.getResponseBodyAsString();
    } catch (HTTPException e) {
        LOG.error("Fatal protocol violation");
        e.printStackTrace();
    } catch (IOException e) {
        LOG.error("Fatal transport error");
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }

    //System.out.println("-----RESPONSEBODY-----");
    //System.out.println(responseBody.substring(startCharIndex, endCharIndex));
    //System.out.println("-----END RESPONSEBODY-----");

    return responseBody;
}