當前位置: 首頁>>代碼示例>>Java>>正文


Java ParseException類代碼示例

本文整理匯總了Java中org.apache.http.ParseException的典型用法代碼示例。如果您正苦於以下問題:Java ParseException類的具體用法?Java ParseException怎麽用?Java ParseException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ParseException類屬於org.apache.http包,在下文中一共展示了ParseException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseHeader

import org.apache.http.ParseException; //導入依賴的package包/類
public HeaderElement parseHeader(
        final CharArrayBuffer buffer,
        final ParserCursor cursor) throws ParseException {
    if (buffer == null) {
        throw new IllegalArgumentException("Char array buffer may not be null");
    }
    if (cursor == null) {
        throw new IllegalArgumentException("Parser cursor may not be null");
    }
    NameValuePair nvp = parseNameValuePair(buffer, cursor);
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair param = parseNameValuePair(buffer, cursor);
        params.add(param);
    }
    return new BasicHeaderElement(
            nvp.getName(),
            nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:NetscapeDraftHeaderParser.java

示例2: getContentCharSet

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * Obtains character set of the entity, if known.
 *
 * @param entity must not be null
 * @return the character set, or null if not found
 * @throws ParseException if header elements cannot be parsed
 * @throws IllegalArgumentException if entity is null
 *
 * @deprecated (4.1.3) use {@link ContentType#getOrDefault(HttpEntity)}
 */
@Deprecated
public static String getContentCharSet(final HttpEntity entity) throws ParseException {
    if (entity == null) {
        throw new IllegalArgumentException("HTTP entity may not be null");
    }
    String charset = null;
    if (entity.getContentType() != null) {
        HeaderElement values[] = entity.getContentType().getElements();
        if (values.length > 0) {
            NameValuePair param = values[0].getParameterByName("charset");
            if (param != null) {
                charset = param.getValue();
            }
        }
    }
    return charset;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:EntityUtils.java

示例3: main

import org.apache.http.ParseException; //導入依賴的package包/類
public static void main(String[] args) throws ParseException, IOException {
	HttpRequestUtil util = new HttpRequestUtil();
	CloseableHttpClient client = util.setDoubleInit();
	
	Map<String,String> map = new HashMap<>();
	CloseableHttpResponse httpPost = util.httpPost(client, "https://127.0.0.1:8443/pwp-web/login.do", map);
	
	HttpEntity entity = httpPost.getEntity();
	String string = EntityUtils.toString(entity, Charset.defaultCharset());
	
	System.out.println(string);
}
 
開發者ID:strictnerd,項目名稱:LearningSummary,代碼行數:13,代碼來源:HttpRequestUtil.java

示例4: getByteArray

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * 獲取響應內容為字節數組
 * 
 * 
 * @date 2015年7月17日
 * @return
 */
public byte[] getByteArray() {
	try {
		return EntityUtils.toByteArray(entity);
	} catch (ParseException | IOException e) {
		logger.error(e.getMessage(), e);
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:16,代碼來源:ResponseWrap.java

示例5: apiDataCubeGetInterfaceSummaryHour

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * 獲取接口分析小時數據。
 * 
 * @param date
 * @return
 * @throws AccessTokenFailException
 * @throws ParseException
 * @throws IOException
 * @throws URISyntaxException
 */
public DataCubeGetInterfaceSummaryHourResp apiDataCubeGetInterfaceSummaryHour(java.sql.Date date)
		throws AccessTokenFailException, ParseException, IOException, URISyntaxException {
	MpAccessToken token = mpApi.apiToken();
	String path = String.format("/datacube/getinterfacesummaryhour?access_token=%s", token.getAccessToken());
	TreeMap<String, Object> reqMap = new TreeMap<String, Object>();
	reqMap.put("begin_date", date);
	reqMap.put("end_date", date);
	String respText = HttpUtil.post(mpApi.config.getApiHttps(), path, reqMap);
	DataCubeGetInterfaceSummaryHourResp resp = new Gson().fromJson(respText,
			DataCubeGetInterfaceSummaryHourResp.class);
	if (mpApi.log.isInfoEnabled()) {
		mpApi.log.info(String.format("apiDataCubeGetInterfaceSummaryHour %s", resp));
	}
	return resp;
}
 
開發者ID:AlexLee-CN,項目名稱:weixin_api,代碼行數:26,代碼來源:MpDataCubeApi.java

示例6: apiSnsOAuth2RefreshToken

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * 刷新微信用戶網頁授權AccessToken。如果是開放平台模式則此方法內部會調用OpenApi中獲取。
 * 由於此api使用頻次比較低,因此未進行緩存,要求業務係統保存OAuthAccessToken,特別是其中的refresh_token。
 * 
 * @param refreshToken
 * @return
 * @throws AccessTokenFailException
 * @throws URISyntaxException
 * @throws IOException
 * @throws ParseException
 */
public OAuthAccessToken apiSnsOAuth2RefreshToken(String refreshToken)
		throws AccessTokenFailException, ParseException, IOException, URISyntaxException {
	if (mpApi.config.isOpenMode()) {// 公眾平台模式
		return OpenApi.getInstance().apiSnsOAuth2ComponentRefreshToken(mpApi.appid, refreshToken);
	}
	String path = String.format("/oauth2/refresh_token?mpApi.appid=%s&grant_type=refresh_token&refresh_token=%s",
			mpApi.config.getAppId(), refreshToken);
	String respText = HttpUtil.get(mpApi.config.getApiOAuth(), path);
	OAuthAccessToken resp = new Gson().fromJson(respText, OAuthAccessToken.class);
	if (mpApi.log.isInfoEnabled()) {
		mpApi.log.info(String.format("apiSnsOAuth2RefreshToken %s", resp));
	}
	return resp;

}
 
開發者ID:AlexLee-CN,項目名稱:weixin_api,代碼行數:27,代碼來源:MpWebApi.java

示例7: apiSnsOAuth2ComponentAccessToken

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * 獲取微信用戶網頁授權AccessToken。
 * 由於此api使用頻次比較低,因此要求業務係統保存OAuthAccessToken,特別是其中的refresh_token。
 * 如果網頁授權的作用域為snsapi_base,則本步驟中獲取到網頁授權access_token的同時,也獲取到了openid,snsapi_base式的網頁授權流程即到此為止。
 * 
 * @param mpAppid
 * @param code
 * 
 * @return
 * @throws AccessTokenFailException
 * @throws URISyntaxException
 * @throws IOException
 * @throws ParseException
 */
public OAuthAccessToken apiSnsOAuth2ComponentAccessToken(String mpAppid, String code)
		throws AccessTokenFailException, ParseException, IOException, URISyntaxException {
	ComponentAccessToken caToken = apiComponentToken();
	String path = String.format(
			"/oauth2/component/access_token?appid=%s&code=%s&grant_type=authorization_code&component_appid=%s&component_access_token=%s",
			mpAppid, code, config.getComponentAppid(), caToken.getComponentAccessToken());

	String respText = HttpUtil.get(config.getApiOAuth(), path);
	OAuthAccessToken resp = new Gson().fromJson(respText, OAuthAccessToken.class);
	if (log.isInfoEnabled()) {
		log.info(String.format("apiOAuth2ComponentAccessToken %s", resp));
	}
	return resp;

}
 
開發者ID:AlexLee-CN,項目名稱:weixin_api,代碼行數:30,代碼來源:OpenApi.java

示例8: waitForContent

import org.apache.http.ParseException; //導入依賴的package包/類
protected Optional<String> waitForContent(String url) {
    return Stream.generate(() -> {
                try {
                    Thread.sleep(1000);
                    System.out.println(url);
                    return getUrlContentPage(url);
                } catch (ParseException | IOException | InterruptedException e) {
                    return null;
                } finally {
                    
                }
            })
        .limit(TestUtils.NB_ITERATION_MAX)
        .filter(content -> content != null && !content.contains("404"))
        .findFirst();
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:17,代碼來源:AbstractDeploymentControllerIT.java

示例9: deserialize

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * Deserializes an HTTP response entity to a given class.
 * 
 * @param entity
 *            the HTTP response entity to be deserialized.
 * @param cls
 *            the target class.
 * @return the response deserialized to the target class.
 * @throws HttpResponseException
 *             when the response cannot be deserialized to the given entity
 *             class.
 */
static <T> T deserialize(HttpEntity entity, Class<T> cls) throws HttpResponseException {
	if (entity == null) {
		logger.error(ERROR_ENTITY_CANNOT_BE_NULL);

		throw new IllegalArgumentException(ERROR_ENTITY_CANNOT_BE_NULL);
	}

	T result = null;
	try {
		logger.debug(DEBUG_CONVERTING_HTTP_ENTITY);
		result = GsonProvider.getInstance().fromJson(EntityUtils.toString(entity, StandardCharsets.UTF_8), cls);
	} catch (ParseException | IOException e) {
		String errorMessage = MessageFormat
				.format(ERROR_PROBLEM_OCCURED_WHILE_CONVERTING_RESPONSE_ENTITY_TO_CLASS_MESSAGE, cls.getName());
		logger.error(errorMessage);
		throw new HttpResponseException(errorMessage, e);
	}

	logger.debug(DEBUG_CONVERTED_HTTP_ENTITY);
	return result;
}
 
開發者ID:SAP,項目名稱:cloud-ariba-partner-flow-extension-ext,代碼行數:34,代碼來源:HttpResponseUtils.java

示例10: parseElements

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * Parses elements with the given parser.
 *
 * @param value     the header value to parse
 * @param parser    the parser to use, or <code>null</code> for default
 *
 * @return  array holding the header elements, never <code>null</code>
 */
public final static
    HeaderElement[] parseElements(final String value,
                                  HeaderValueParser parser)
    throws ParseException {

    if (value == null) {
        throw new IllegalArgumentException
            ("Value to parse may not be null");
    }

    if (parser == null)
        parser = BasicHeaderValueParser.DEFAULT;

    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseElements(buffer, cursor);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:BasicHeaderValueParser.java

示例11: parseHeaderElement

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * Parses an element with the given parser.
 *
 * @param value     the header element to parse
 * @param parser    the parser to use, or <code>null</code> for default
 *
 * @return  the parsed header element
 */
public final static
    HeaderElement parseHeaderElement(final String value,
                                     HeaderValueParser parser)
    throws ParseException {

    if (value == null) {
        throw new IllegalArgumentException
            ("Value to parse may not be null");
    }

    if (parser == null)
        parser = BasicHeaderValueParser.DEFAULT;

    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseHeaderElement(buffer, cursor);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:BasicHeaderValueParser.java

示例12: parseParameters

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * Parses parameters with the given parser.
 *
 * @param value     the parameter list to parse
 * @param parser    the parser to use, or <code>null</code> for default
 *
 * @return  array holding the parameters, never <code>null</code>
 */
public final static
    NameValuePair[] parseParameters(final String value,
                                    HeaderValueParser parser)
    throws ParseException {

    if (value == null) {
        throw new IllegalArgumentException
            ("Value to parse may not be null");
    }

    if (parser == null)
        parser = BasicHeaderValueParser.DEFAULT;

    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseParameters(buffer, cursor);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:BasicHeaderValueParser.java

示例13: parseNameValuePair

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * Parses a name-value-pair with the given parser.
 *
 * @param value     the NVP to parse
 * @param parser    the parser to use, or <code>null</code> for default
 *
 * @return  the parsed name-value pair
 */
public final static
   NameValuePair parseNameValuePair(final String value,
                                    HeaderValueParser parser)
    throws ParseException {

    if (value == null) {
        throw new IllegalArgumentException
            ("Value to parse may not be null");
    }

    if (parser == null)
        parser = BasicHeaderValueParser.DEFAULT;

    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseNameValuePair(buffer, cursor);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:BasicHeaderValueParser.java

示例14: findNext

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * Determines the next token.
 * If found, the token is stored in {@link #currentToken}.
 * The return value indicates the position after the token
 * in {@link #currentHeader}. If necessary, the next header
 * will be obtained from {@link #headerIt}.
 * If not found, {@link #currentToken} is set to <code>null</code>.
 *
 * @param from      the position in the current header at which to
 *                  start the search, -1 to search in the first header
 *
 * @return  the position after the found token in the current header, or
 *          negative if there was no next token
 *
 * @throws ParseException   if an invalid header value is encountered
 */
protected int findNext(int from)
    throws ParseException {

    if (from < 0) {
        // called from the constructor, initialize the first header
        if (!this.headerIt.hasNext()) {
            return -1;
        }
        this.currentHeader = this.headerIt.nextHeader().getValue();
        from = 0;
    } else {
        // called after a token, make sure there is a separator
        from = findTokenSeparator(from);
    }

    int start = findTokenStart(from);
    if (start < 0) {
        this.currentToken = null;
        return -1; // nothing found
    }

    int end = findTokenEnd(start);
    this.currentToken = createToken(this.currentHeader, start, end);
    return end;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:42,代碼來源:BasicTokenIterator.java

示例15: BufferedHeader

import org.apache.http.ParseException; //導入依賴的package包/類
/**
 * Creates a new header from a buffer.
 * The name of the header will be parsed immediately,
 * the value only if it is accessed.
 *
 * @param buffer    the buffer containing the header to represent
 *
 * @throws ParseException   in case of a parse error
 */
public BufferedHeader(final CharArrayBuffer buffer)
    throws ParseException {

    super();
    if (buffer == null) {
        throw new IllegalArgumentException
            ("Char array buffer may not be null");
    }
    int colon = buffer.indexOf(':');
    if (colon == -1) {
        throw new ParseException
            ("Invalid header: " + buffer.toString());
    }
    String s = buffer.substringTrimmed(0, colon);
    if (s.length() == 0) {
        throw new ParseException
            ("Invalid header: " + buffer.toString());
    }
    this.buffer = buffer;
    this.name = s;
    this.valuePos = colon + 1;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:BufferedHeader.java


注:本文中的org.apache.http.ParseException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。