Java 类org.apache.commons.httpclient.HttpException 实例源码

项目:lib-commons-httpclient    文件:ExpectContinueMethod.java   
/**
 * Sets the <tt>Expect</tt> header if it has not already been set, 
 * in addition to the "standard" set of headers.
 *
 * @param state the {@link HttpState state} information associated with this method
 * @param conn the {@link HttpConnection connection} used to execute
 *        this HTTP method
 *
 * @throws IOException if an I/O (transport) error occurs. Some transport exceptions
 *                     can be recovered from.
 * @throws HttpException  if a protocol exception occurs. Usually protocol exceptions 
 *                    cannot be recovered from.
 */
protected void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
    LOG.trace("enter ExpectContinueMethod.addRequestHeaders(HttpState, HttpConnection)");

    super.addRequestHeaders(state, conn);
    // If the request is being retried, the header may already be present
    boolean headerPresent = (getRequestHeader("Expect") != null);
    // See if the expect header should be sent
    // = HTTP/1.1 or higher
    // = request body present

    if (getParams().isParameterTrue(HttpMethodParams.USE_EXPECT_CONTINUE) 
    && getEffectiveVersion().greaterEquals(HttpVersion.HTTP_1_1) 
    && hasRequestContent())
    {
        if (!headerPresent) {
            setRequestHeader("Expect", "100-continue");
        }
    } else {
        if (headerPresent) {
            removeRequestHeader("Expect");
        }
    }
}
项目:alfresco-repository    文件:SolrQueryHTTPClient.java   
protected JSONResult postSolrQuery(HttpClient httpClient, String url, JSONObject body, SolrJsonProcessor<?> jsonProcessor, String spellCheckParams)
            throws UnsupportedEncodingException, IOException, HttpException, URIException,
            JSONException
{
    JSONObject json = postQuery(httpClient, url, body);
    if (spellCheckParams != null)
    {
        SpellCheckDecisionManager manager = new SpellCheckDecisionManager(json, url, body, spellCheckParams);
        if (manager.isCollate())
        {
            json = postQuery(httpClient, manager.getUrl(), body);
        }
        json.put("spellcheck", manager.getSpellCheckJsonValue());
    }

        JSONResult results = jsonProcessor.getResult(json);

        if (s_logger.isDebugEnabled())
        {
            s_logger.debug("Sent :" + url);
            s_logger.debug("   with: " + body.toString());
            s_logger.debug("Got: " + results.getNumberFound() + " in " + results.getQueryTime() + " ms");
        }

        return results;
}
项目:oscm    文件:RequestHandlerBase.java   
/**
 * Will write all request headers stored in the request to the method that
 * are not in the set of banned headers.
 * The Accept-Endocing header is also changed to allow compressed content
 * connection to the server even if the end client doesn't support that. 
 * A Via headers is created as well in compliance with the RFC.
 * 
 * @param method The HttpMethod used for this connection
 * @param request The incoming request
 * @throws HttpException 
 */
protected void setHeaders(HttpMethod method, HttpServletRequest request) throws HttpException {
    Enumeration headers = request.getHeaderNames();
    String connectionToken = request.getHeader("connection");

    while (headers.hasMoreElements()) {
        String name = (String) headers.nextElement();
        boolean isToken = (connectionToken != null && name.equalsIgnoreCase(connectionToken));

        if (!isToken && !bannedHeaders.contains(name.toLowerCase())) {
            Enumeration value = request.getHeaders(name);
            while (value.hasMoreElements()) {
                method.addRequestHeader(name, (String) value.nextElement());
            } 
        } 
    } 

    setProxySpecificHeaders(method, request);
}
项目:bibliometrics    文件:AuthorBuilder.java   
/**
   * retrieves the ScopusAuthorID for an author and puts it into the <code>PublicationAuthor</code> object
   * @throws HttpException thrown upon connecting to the source
* @throws JDOMException thrown upon parsing the source response
* @throws IOException thrown upon reading profiles from disc
* @throws SAXException thrown when parsing the files from disc
*/
  public void retrieveScopusAuthorID() throws HttpException, JDOMException, IOException, SAXException {
      ScopusConnector connection = new ScopusConnector();
      Element result = connection.retrieveScopusAuthorID(author).asXML().detachRootElement().clone();

      List<String> allIDs = new ArrayList<>();
      for (Element child : result.getChildren()) {
          if (result.getName().equals("error")) continue;
          if (child.getName().equals("entry")) {
              Element identifier = child.getChild("identifier",DC_NS);
              String value = identifier.getValue().replace("AUTHOR_ID:", "");
              allIDs.add(value);
          }
      }
      if (allIDs.size() == 1) {
          author.setScopusAuthorID(allIDs.get(0));
          LOGGER.info("found ScopusID: " + author.getScopusAuthorID());
      } else
          author.setScopusAuthorID(toBeChecked);
  }
项目:bibliometrics    文件:Institution.java   
public JSONObject createGeoJsonPoint() throws HttpException, JDOMException, IOException, SAXException {
    JSONObject geoJSONInd = new JSONObject();
    JSONObject geometry = new JSONObject();
    geometry.put("type", "Point");
    JSONArray coordinates = new JSONArray();
    coordinates.put(longitude).put(latitude);
    geometry.put("coordinates", coordinates);
    geoJSONInd.put("geometry", geometry);

    geoJSONInd.put("type", "Feature");
    JSONObject properties = new JSONObject();
    properties.put("name", city);
    geoJSONInd.put("properties", properties);
    String description = institution;
    if (!department.isEmpty())
        description = description + "<br />" + department;
    properties.put("popupContent", description);
    return geoJSONInd;
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:SlingPostProcessorTest.java   
@Test
public void processorsActive() throws HttpException, IOException {
    final PostMethod post = new PostMethod(testUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX);
    post.setFollowRedirects(false);
    post.setParameter("DummyModification", "true");

    try {
        T.getHttpClient().executeMethod(post);
        final String content = post.getResponseBodyAsString();
        final int i1 = content.indexOf("source:SlingPostProcessorOne");
        assertTrue("Expecting first processor to be present", i1 > 0);
        final int i2 = content.indexOf("source:SlingPostProcessorTwo");
        assertTrue("Expecting second processor to be present", i2 > 0);
        assertTrue("Expecting service ranking to put processor one first", i1 < i2);
    } finally {

        post.releaseConnection();
    }

}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UploadFileTest.java   
private void checkUploadedFileState(String urlOfFileNode) throws IOException,
        HttpException {
    final GetMethod get = new GetMethod(urlOfFileNode);
       final int status = httpClient.executeMethod(get);
       assertEquals(urlOfFileNode + " must be accessible after createNode",200,status);

       /*
       We should check the data, but nt:resources are not handled yet
       // compare data with local file (just length)
       final byte[] data = get.getResponseBody();
       assertEquals("size of file must be same", localFile.length(), data.length);
       */
       String data = get.getResponseBodyAsString();
       assertTrue("checking for content", data.contains("http://www.apache.org/licenses/LICENSE-2.0"));

       // download structure
       String json = getContent(urlOfFileNode + ".json", CONTENT_TYPE_JSON);
       // just check for some strings
       assertTrue("checking primary type", json.contains("\"jcr:primaryType\":\"nt:file\""));

       String content_json = getContent(urlOfFileNode + "/jcr:content.json", CONTENT_TYPE_JSON);
       // just check for some strings
       assertTrue("checking primary type", content_json.contains("\"jcr:primaryType\":\"nt:resource\""));
       assertTrue("checking mime type", content_json.contains("\"jcr:mimeType\":\"text/plain\""));
}
项目:openNaEF    文件:ExceptionUtils.java   
public static ExternalServiceException getExternalServiceException(Exception e) {
    if (e instanceof ExternalServiceException) {
        return (ExternalServiceException) e;
    } else if (e instanceof RemoteException) {
        if (isLocalProblem((RemoteException) e)) {
            return new ExternalServiceException("Communication with the server could not be started.", e);
        }
        return new ExternalServiceException("An error occurred on the external server side.", e);
    } else if (e instanceof RuntimeException) {
        return new ExternalServiceException("An unexpected error occurred in the server. [" + e.getMessage() + "]", e);
    } else if (e instanceof HttpException) {
        return new ExternalServiceException("Unexpected error occurred in HTTP communication with external server. [" + e.getMessage() + "]", e);
    } else if (e instanceof ConnectException) {
        return new ExternalServiceException("Could not connect to external server. [" + e.getMessage() + "]", e);
    } else if (e instanceof IOException) {
        return new ExternalServiceException("An unexpected error occurred in the I / O with the external server. [" + e.getMessage() + "]", e);
    }
    return new ExternalServiceException("An unexpected error occurred. Response=[" + e.getMessage() + "]", e);
}
项目:lib-commons-httpclient    文件:MultipartPostMethod.java   
/**
 * Adds a <tt>Content-Type</tt> request header.
 *
 * @param state current state of http requests
 * @param conn the connection to use for I/O
 *
 * @throws IOException if an I/O (transport) error occurs. Some transport exceptions
 *                     can be recovered from.
 * @throws HttpException  if a protocol exception occurs. Usually protocol exceptions 
 *                    cannot be recovered from.
 * 
 * @since 3.0
 */
protected void addContentTypeRequestHeader(HttpState state,
                                             HttpConnection conn)
throws IOException, HttpException {
    LOG.trace("enter EntityEnclosingMethod.addContentTypeRequestHeader("
              + "HttpState, HttpConnection)");

    if (!parameters.isEmpty()) {
        StringBuffer buffer = new StringBuffer(MULTIPART_FORM_CONTENT_TYPE);
        if (Part.getBoundary() != null) {
            buffer.append("; boundary=");
            buffer.append(Part.getBoundary());
        }
        setRequestHeader("Content-Type", buffer.toString());
    }
}
项目:lib-commons-httpclient    文件:EntityEnclosingMethod.java   
/**
 * Generates <tt>Content-Length</tt> or <tt>Transfer-Encoding: Chunked</tt>
 * request header, as long as no <tt>Content-Length</tt> request header
 * already exists.
 *
 * @param state current state of http requests
 * @param conn the connection to use for I/O
 *
 * @throws IOException when errors occur reading or writing to/from the
 *         connection
 * @throws HttpException when a recoverable error occurs
 */
protected void addContentLengthRequestHeader(HttpState state,
                                             HttpConnection conn)
throws IOException, HttpException {
    LOG.trace("enter EntityEnclosingMethod.addContentLengthRequestHeader("
              + "HttpState, HttpConnection)");

    if ((getRequestHeader("content-length") == null) 
        && (getRequestHeader("Transfer-Encoding") == null)) {
        long len = getRequestContentLength();
        if (len < 0) {
            if (getEffectiveVersion().greaterEquals(HttpVersion.HTTP_1_1)) {
                addRequestHeader("Transfer-Encoding", "chunked");
            } else {
                throw new ProtocolException(getEffectiveVersion() + 
                    " does not support chunk encoding");
            }
        } else {
            addRequestHeader("Content-Length", String.valueOf(len));
        }
    }
}
项目:scribe    文件:HTTPClient.java   
private static void createAccount() throws HttpException, IOException {

    File input = new File(testFolder + "Account.xml");
    PostMethod post =
        new PostMethod(cadURL + "/object/User?_type=xml&externalServiceType=FBMC&externalUsername=8x8webservice&externalPassword=E4qtjWZLYKre");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void updateAccount() throws HttpException, IOException {
  System.out.println("Sent HTTP PUT request to update Account");
  File input = new File(testFolder + "Account.xml");
  PutMethod put =
      new PutMethod(cadURL + "/object/User?_type=xml&externalServiceType=FBMC&externalUsername=8x8webservice&externalPassword=E4qtjWZLYKre");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createCustomer() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to add Customer");
  File input = new File(testFolder + "Customer.xml");
  PostMethod post = new PostMethod(cadURL + "/object/customer?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  post.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + post.getURI());
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());
  } finally {
    post.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void updateCustomer() throws HttpException, IOException {
  System.out.println("Sent HTTP PUT request to update Customer");
  File input = new File(testFolder + "Customer.xml");
  PutMethod put = new PutMethod(cadURL + "/object/customer?_type=xml");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + put.getURI());
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createLead() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to create Lead");
  File input = new File(testFolder + "Lead.xml");
  PostMethod post = new PostMethod(cadURL + "/object/lead?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  post.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + post.getURI());
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());
  } finally {
    post.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createContact() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to createContact");
  File input = new File(testFolder + "Contact.xml");
  PostMethod post = new PostMethod(cadURL + "/object/oltp?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  post.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + post.getURI());
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());
  } finally {
    post.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void updateContact() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to createContact");
  File input = new File(testFolder + "Contact.xml");
  PutMethod put = new PutMethod(cadURL + "/object/oltp?_type=xml");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + put.getURI());
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createFAQCatagory() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to createFAQCatagory");
  File input = new File(testFolder + "FAQCatagory.xml");
  PostMethod post = new PostMethod(cadURL + "/object/faqcategory?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  post.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + post.getURI());
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());
  } finally {
    post.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void readCustomers() throws HttpException, IOException {

    for (int i = 0; i < 1000; i++) {

      new Thread() {
        public void run() {
          GetMethod post = new GetMethod(cadURL + "/object/customer?_type=xml&tenant=dev1ten2");
          post.addRequestHeader("Content-Type", "application/xml");
          HttpClient httpclient = new HttpClient();
          try {

            try {
              System.out.println("URI: " + post.getURI());
              int result = httpclient.executeMethod(post);
              System.out.println("Response status code: " + result);
              System.out.println("Response body: " + post.getResponseBodyAsString());
            } catch (Exception exception) {
              System.err.println(exception);
            }
          } finally {
            post.releaseConnection();
          }
        }
      };
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createUser() throws HttpException, IOException {

    File input = new File(testFolder + "User.xml");
    PostMethod post = new PostMethod(cadURL + "/object/user?_type=xml&batch=dummy");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("hii");
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void updateUser() throws HttpException, IOException {

    File input = new File(testFolder + "User.xml");
    PutMethod put = new PutMethod(cadURL + "/object/user?_type=xml");
    put.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    put.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + put.getURI());
      int result = httpclient.executeMethod(put);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + put.getResponseBodyAsString());
    } finally {
      put.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createTask() throws HttpException, IOException {

    File input = new File(testFolder + "Task.xml");
    PostMethod post = new PostMethod(cadURL + "/object/task?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createSupportCase() throws HttpException, IOException {

    File input = new File(testFolder + "SupportCase.xml");
    PostMethod post = new PostMethod(cadURL + "/object/supportcase?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createPhoneCall() throws HttpException, IOException {

    File input = new File(testFolder + "PhoneCall.xml");
    PostMethod post = new PostMethod(cadURL + "/object/phonecall?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createOpportunity() throws HttpException, IOException {

    File input = new File(testFolder + "Opportunity.xml");
    PostMethod post = new PostMethod(cadURL + "/object/opportunity?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createIncident() throws HttpException, IOException {

    File input = new File(testFolder + "Incident.xml");
    PostMethod post = new PostMethod(cadURL + "/object/incident?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createCase() throws HttpException, IOException {

    File input = new File(testFolder + "Case.xml");
    PostMethod post = new PostMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void updateCase() throws HttpException, IOException {

    File input = new File(testFolder + "Case.xml");
    PutMethod post = new PutMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createFollowup() throws HttpException, IOException {

    File input = new File(testFolder + "Followup.xml");
    PostMethod post = new PostMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void updateFollowup() throws HttpException, IOException {

    File input = new File(testFolder + "Followup.xml");
    PutMethod post = new PutMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:document-management-system    文件:MailUtils.java   
/**
 * User tinyurl service as url shorter Depends on commons-httpclient:commons-httpclient:jar:3.0 because of
 * org.apache.jackrabbit:jackrabbit-webdav:jar:1.6.4
 */
public static String getTinyUrl(String fullUrl) throws HttpException, IOException {
    HttpClient httpclient = new HttpClient();

    // Prepare a request object
    HttpMethod method = new GetMethod("http://tinyurl.com/api-create.php");
    method.setQueryString(new NameValuePair[]{new NameValuePair("url", fullUrl)});
    httpclient.executeMethod(method);
    InputStreamReader isr = new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8");
    StringWriter sw = new StringWriter();
    int c;
    while ((c = isr.read()) != -1)
        sw.write(c);
    isr.close();
    method.releaseConnection();

    return sw.toString();
}
项目:ucsd-spark-plugin    文件:SparkApi.java   
/**
 * Requests a specific team member from the Spark servers and returns it as
 * a Java Object. If the team member does not exist (or cannot be found) it
 * returns null
 *
 * @param account
 *            Account to request from
 * @param teamId
 *            Team ID to check
 * @param personEmail
 *            User's email to check
 * @return Membership ID as a String
 * @throws SparkReportException
 *             if the report fails
 * @throws HttpException
 *             if there's a problem accessing the report
 * @throws IOException
 *             if there's a problem accessing the report
 * @see SparkRooms
 */
public static String getSparkTeamMemberships(SparkAccount account, String teamId, String personEmail)
        throws SparkReportException, HttpException, IOException {
    // Set up a request to the spark server
    SparkHttpConnection req = new SparkHttpConnection(account,
            SparkConstants.SPARK_TEAMS_MEMBERSHIP_URI + "?teamId=" + teamId + "&personEmail=" + personEmail,
            httpMethod.GET);
    req.execute();
    String json = req.getResponse();
    Gson gson = new Gson();
    SparkTeamMemberships members = gson.fromJson(json, SparkTeamMemberships.class);
    if (members.getItems().size() > 0) {
        // There is a bug (2016-07-15) which means searching via email
        // doesn't work - find it ourselves
        for (SparkTeamMembership member : members.getItems()) {
            if (personEmail.toLowerCase().equals(member.getPersonEmail().toLowerCase())) {
                return member.getId();
            }
        }
    }
    return null;
}
项目:weixinmp4j    文件:IPAddressService.java   
/**
 * 
 */
public IP onSuccess() throws HttpException, IOException {
    //数据demo if(window.AA) {AA({"ip":"115.199.97.37","pro":"浙江省","city":"杭州市","region":"","addr":"浙江省杭州市","regionNames":""});} 
    String content=method.getResponseBodyAsString();
    String jsonData=content.substring(content.indexOf("{", content.indexOf("{")+1)/*左起第二个话括弧*/, content.indexOf("}")+1/*第一个反括号结束*/);
    JSONObject jsonObject=new JSONObject(jsonData);

    IP ip=new IP();
    ip.setIp(jsonObject.getString("ip"));
    ip.setAddr(jsonObject.getString("addr"));
    ip.setCity(jsonObject.getString("city"));
    ip.setPro(jsonObject.getString("pro"));
    ip.setRegion(jsonObject.getString("region"));
    ip.setRegionNames(jsonObject.getString("regionNames"));
    return ip;

    //反射效率太低
    //return (IP)JSONObject.toBean(jsonObject, IP.class);
}
项目:motu    文件:HttpClientCAS.java   
public int executeMethod(HostConfiguration hostconfig, HttpMethod method, HttpState state, boolean addCasTicket)
        throws IOException, HttpException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("executeMethod(HostConfiguration, HttpMethod, HttpState) - entering");
    }

    try {
        if (this.isAddCasTicketParams()) {
            HttpClientCAS.addCASTicket(method);
        }
    } catch (MotuCasException e) {
        throw new HttpException(e.notifyException(), e);
    }

    int returnint = super.executeMethod(hostconfig, method, state);
    if (LOG.isDebugEnabled()) {
        LOG.debug("executeMethod(HostConfiguration, HttpMethod, HttpState) - exiting");
    }
    return returnint;
}
项目:motu    文件:HttpClientCAS.java   
@Override
public int executeMethod(HttpMethod method) throws IOException, HttpException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("executeMethod(HttpMethod) - entering");
    }
    try {
        if (this.isAddCasTicketParams()) {
            HttpClientCAS.addCASTicket(method);
        }
    } catch (MotuCasException e) {
        throw new HttpException(e.notifyException(), e);
    }

    // int returnint = super.executeMethod(method);
    int returnint = super.executeMethod(null, method, null);
    if (LOG.isDebugEnabled()) {
        LOG.debug("executeMethod(HttpMethod) - exiting");
    }
    return returnint;
}
项目:development    文件:RequestHandlerBase.java   
/**
 * Will write all request headers stored in the request to the method that
 * are not in the set of banned headers.
 * The Accept-Endocing header is also changed to allow compressed content
 * connection to the server even if the end client doesn't support that. 
 * A Via headers is created as well in compliance with the RFC.
 * 
 * @param method The HttpMethod used for this connection
 * @param request The incoming request
 * @throws HttpException 
 */
protected void setHeaders(HttpMethod method, HttpServletRequest request) throws HttpException {
    Enumeration headers = request.getHeaderNames();
    String connectionToken = request.getHeader("connection");

    while (headers.hasMoreElements()) {
        String name = (String) headers.nextElement();
        boolean isToken = (connectionToken != null && name.equalsIgnoreCase(connectionToken));

        if (!isToken && !bannedHeaders.contains(name.toLowerCase())) {
            Enumeration value = request.getHeaders(name);
            while (value.hasMoreElements()) {
                method.addRequestHeader(name, (String) value.nextElement());
            } 
        } 
    } 

    setProxySpecificHeaders(method, request);
}
项目:osa    文件:IngestAction.java   
@HandlesEvent("getOnkiHttp")
public Resolution getOnkiHttp() throws HttpException, IOException {
    String json = "";
    String language = getUserLocale().toLanguageTag().split("-")[0];
    HttpClient httpClient = new HttpClient();
    httpClient.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    httpClient.getParams().setParameter("http.protocol.content-charset", "UTF-8");

    GetMethod get = new GetMethod("http://onki.fi/key-"+this.getOnkiAccessKey()+"/api/v2/http/onto/" + ontologyId + "/search?q=" + term + "&l=" + language);
    httpClient.executeMethod(get);
    if (get.getStatusCode() == 200) {
        json = get.getResponseBodyAsString();
    }
    //logger.info("getOnkiHttp(): "+json);
    return new StreamingResolution(MIME_JS, json);
}
项目:ffma    文件:PronomSparqlClient.java   
/**
     * @param query
     */
    public PronomSparqlClient(String query) {
        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().
        setConnectionTimeout(10000);
        String url = query;
        try {
            HttpMethod method = new GetMethod(url);
            method.setFollowRedirects(false);
//      try {
            client.executeMethod(method);
            responseBody = method.getResponseBodyAsString();
            log.info("Response body: " + responseBody);
            method.releaseConnection();
        } catch (HttpException he) {
            log.fine("Http error connecting to �" + query + "�");
        } catch (IOException ioe) {
            log.fine("Unable to connect to �" + query + "�");
        } catch (Exception e) {
            log.fine("SPARQL client exception. Unable to parse response from �" + query + "� (Exception: " + e.getLocalizedMessage() + ")");
        }
//      method.releaseConnection();
    }
项目:ffma    文件:SPARQLClient.java   
/**
     * @param endpointURL
     * @param sparql
     */
    public SPARQLClient(String endpointURL, String sparql) {
        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().
        setConnectionTimeout(10000);
        String url = endpointURL + sparql;
        HttpMethod method = new GetMethod(url);
        method.setFollowRedirects(false);
        try {
            client.executeMethod(method);
//          log.info("Response body: " + method.getResponseBodyAsString());
            InputStream ins = new ByteArrayInputStream(method.getResponseBodyAsString().getBytes("UTF-8"));
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser sax = factory.newSAXParser();
            sax.parse(ins, this);
        } catch (HttpException he) {
            log.fine("Http error connecting to �" + endpointURL + "�");
        } catch (IOException ioe) {
            log.fine("Unable to connect to �" + endpointURL + "�");
        } catch (SAXException se) {
            log.fine("Unable to parse response from �" + endpointURL + "� (Exception: " + se.getLocalizedMessage() + ")");
        } catch (ParserConfigurationException pce) {
            log.fine("Unable to parse response from �" + endpointURL + "� (Exception: " + pce.getLocalizedMessage() + ")");
        }
        method.releaseConnection();
    }
项目:power-java    文件:DBpediaLookupClient.java   
public DBpediaLookupClient(String query) throws Exception {
  this.query = query;
  HttpClient client = new HttpClient();

  String query2 = query.replaceAll(" ", "+");
  HttpMethod method =
      new GetMethod("http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" +
          query2);
  try {
    client.executeMethod(method);
    InputStream ins = method.getResponseBodyAsStream();
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser sax = factory.newSAXParser();
    sax.parse(ins, this);
  } catch (HttpException he) {
    System.err.println("Http error connecting to lookup.dbpedia.org");
  } catch (IOException ioe) {
    System.err.println("Unable to connect to lookup.dbpedia.org");
  }
  method.releaseConnection();
}