static HttpResponse executeRequest(ProtocolCommand command, String mimeType) {
    HttpClient client = ((ProtocolConnection)command.getConnection()).getHttpClient();
    URL url = ((ProtocolDataSource)command.getConnection().getDataSource()).getUrl();
    HttpUriRequest req;

    try {
      String params = "query=" + encode(command.getCommand());
      String u = url.toString() + "?" + params;
      if (u.length() > QUERY_LIMIT) {
        // POST connection
        try {
          req = new HttpPost(url.toURI());
        } catch (URISyntaxException e) {
          throw new SparqlException("Endpoint <" + url + "> not in an acceptable format", e);
        }
        ((HttpPost) req).setEntity((HttpEntity) new StringEntity(params));
      } else {
        // GET connection
        req = new HttpGet(u);
      }

      if (command.getTimeout() != Command.NO_TIMEOUT) {
        HttpParams reqParams = new BasicHttpParams();
        HttpConnectionParams.setSoTimeout(reqParams, (int) (command.getTimeout() * 1000));
        req.setParams(reqParams);
      }
      
      // Add Accept and Content-Type (for POST'ed queries) headers to the request.
      addHeaders(req, mimeType);
      
      // There's a small chance the request could be aborted before it's even executed, we'll have to live with that.
      command.setRequest(req);
      
      //dump(client, req);
      HttpResponse response = client.execute(req);
      StatusLine status = response.getStatusLine();
      int code = status.getStatusCode();
      
      // TODO the client doesn't handle redirects for posts; should we do that here?

      if (code >= SUCCESS_MIN && code <= SUCCESS_MAX) {
        return response;
      } else {
        throw new SparqlException("Unexpected status code in server response: " +
            status.getReasonPhrase() + "(" + code + ")");
      }
    } catch (UnsupportedEncodingException e) {
      throw new SparqlException("Unabled to encode data", e);
    } catch (ClientProtocolException cpe) {
      throw new SparqlException("Error in protocol", cpe);
    } catch (IOException e) {
      throw new SparqlException(e);
    }
  }
static HttpResponse executeRequest ( ProtocolCommand command , String mimeType ) { HttpClient client = ( ( ProtocolConnection ) command . getConnection ( ) ) . getHttpClient ( ) ; URL url = ( ( ProtocolDataSource ) command . getConnection ( ) . getDataSource ( ) ) . getUrl ( ) ; HttpUriRequest req ; try { String params = "query=" + encode ( command . getCommand ( ) ) ; String u = url . toString ( ) + "?" + params ; if ( u . length ( ) > QUERY_LIMIT ) { try { req = new HttpPost ( url . toURI ( ) ) ; } catch ( URISyntaxException e ) { throw new SparqlException ( "Endpoint <" + url + "> not in an acceptable format" , e ) ; } ( ( HttpPost ) req ) . setEntity ( ( HttpEntity ) new StringEntity ( params ) ) ; } else { req = new HttpGet ( u ) ; } if ( command . getTimeout ( ) != Command . NO_TIMEOUT ) { HttpParams reqParams = new BasicHttpParams ( ) ; HttpConnectionParams . setSoTimeout ( reqParams , ( int ) ( command . getTimeout ( ) * 1000 ) ) ; req . setParams ( reqParams ) ; } addHeaders ( req , mimeType ) ; command . setRequest ( req ) ; HttpResponse response = client . execute ( req ) ; StatusLine status = response . getStatusLine ( ) ; int code = status . getStatusCode ( ) ; if ( code >= SUCCESS_MIN && code <= SUCCESS_MAX ) { return response ; } else { throw new SparqlException ( "Unexpected status code in server response: " + status . getReasonPhrase ( ) + "(" + code + ")" ) ; } } catch ( UnsupportedEncodingException e ) { throw new SparqlException ( "Unabled to encode data" , e ) ; } catch ( ClientProtocolException cpe ) { throw new SparqlException ( "Error in protocol" , cpe ) ; } catch ( IOException e ) { throw new SparqlException ( e ) ; } }
Executes a SPARQL HTTP protocol request for the given command, and returns the response.
@param command The SPARQL protocol command.
@return The HTTP response.