当前位置: 首页>>代码示例>>Java>>正文


Java HttpException类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.HttpException的典型用法代码示例。如果您正苦于以下问题:Java HttpException类的具体用法?Java HttpException怎么用?Java HttpException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpException类属于org.apache.commons.httpclient包,在下文中一共展示了HttpException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addRequestHeaders

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
/**
 * 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");
        }
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:38,代码来源:ExpectContinueMethod.java

示例2: postSolrQuery

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:SolrQueryHTTPClient.java

示例3: setHeaders

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:30,代码来源:RequestHandlerBase.java

示例4: retrieveScopusAuthorID

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
/**
   * 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);
  }
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:27,代码来源:AuthorBuilder.java

示例5: createGeoJsonPoint

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:20,代码来源:Institution.java

示例6: processorsActive

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
@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();
    }

}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:21,代码来源:SlingPostProcessorTest.java

示例7: checkUploadedFileState

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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\""));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:26,代码来源:UploadFileTest.java

示例8: getExternalServiceException

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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);
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:20,代码来源:ExceptionUtils.java

示例9: addContentTypeRequestHeader

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:MultipartPostMethod.java

示例10: addContentLengthRequestHeader

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
/**
 * 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));
        }
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:34,代码来源:EntityEnclosingMethod.java

示例11: createAccount

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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();
    }
  }
 
开发者ID:inbravo,项目名称:scribe,代码行数:19,代码来源:HTTPClient.java

示例12: updateAccount

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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();
  }
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例13: createCustomer

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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();
  }
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例14: updateCustomer

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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();
  }
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例15: createLead

import org.apache.commons.httpclient.HttpException; //导入依赖的package包/类
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();
  }
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java


注:本文中的org.apache.commons.httpclient.HttpException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。