Package com.complexible.common.web

Examples of com.complexible.common.web.Response


      }
    };
  }

  private <T> T executeSPARQLQuery(String theQuery, Class<T> clazz) throws QueryException {
    Response aResponse = null;
 
    try {
      aResponse = createSPARQLQueryRequest(theQuery).execute();

      if (aResponse.hasErrorCode()) {
        throw responseToException(theQuery, aResponse);
      }
      else {
        try {
          if (Boolean.class.equals(clazz)) {
            return (T) parseBooleanResult(aResponse);
          }
          else {
            return (T) parseTupleResult(aResponse);
          }
        }
        catch (Exception e) {
          throw new QueryException("Could not parse SPARQL-XML results", e);
        }
      }
    }
    catch (IOException e) {
      throw new QueryException(e);
    }
    finally {
      if (aResponse != null) {
        try {
          aResponse.close();
        }
        catch (IOException e) {
          System.err.println("There was an error while closing the http connection: " + e.getMessage());
        }
      }
View Full Code Here


    ParameterList aParams = new ParameterList()
        .add(PARAM_QUERY, theQuery);

    Request aQueryRequest;
    Response aResponse = null;
    try {

      if (mUseGetForQueries) {
        aQueryRequest = aRes.initGet()
            .addHeader(HttpHeaders.Accept.getName(), RDFFormat.TURTLE.getDefaultMIMEType())
            .setParameters(aParams);
      }
      else {
        aQueryRequest = aRes.initPost()
            .addHeader(HttpHeaders.ContentType.getName(), MimeTypes.FormUrlEncoded.getMimeType())
            .addHeader(HttpHeaders.Accept.getName(), RDFFormat.TURTLE.getDefaultMIMEType())
            .setBody(aParams.getURLEncoded());
      }

      aResponse = aQueryRequest.execute();

      if (aResponse.hasErrorCode()) {
        throw responseToException(theQuery, aResponse);
      }
      else {
        try {
          return GraphIO.readGraph(aResponse.getContent(), RDFFormat.TURTLE);
        }
        catch (RDFParseException e) {
          throw new QueryException("Error while parsing rdf/xml-formatted query results", e);
        }
      }
    }
    catch (IOException e) {
      throw new QueryException(e);
    }
    finally {
      if (aResponse != null) {
        try {
          aResponse.close();
        }
        catch (IOException e) {
          System.err.println("There was an error while closing the http connection: " + e.getMessage());
        }
      }
View Full Code Here

TOP

Related Classes of com.complexible.common.web.Response

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.