• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java B2CConverter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: generateNonce

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
/**
 * Generate a unique token. The token is generated according to the
 * following pattern. NOnceToken = Base64 ( MD5 ( client-IP ":" time-stamp
 * ":" private-key ) ).
 *
 * @param request
 *            HTTP Servlet request
 */
protected String generateNonce(Request request) {

	long currentTime = System.currentTimeMillis();

	synchronized (lastTimestampLock) {
		if (currentTime > lastTimestamp) {
			lastTimestamp = currentTime;
		} else {
			currentTime = ++lastTimestamp;
		}
	}

	String ipTimeKey = request.getRemoteAddr() + ":" + currentTime + ":" + getKey();

	byte[] buffer = ConcurrentMessageDigest.digestMD5(ipTimeKey.getBytes(B2CConverter.ISO_8859_1));
	String nonce = currentTime + ":" + MD5Encoder.encode(buffer);

	NonceInfo info = new NonceInfo(currentTime, getNonceCountWindowSize());
	synchronized (nonces) {
		nonces.put(nonce, info);
	}

	return nonce;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:33,代码来源:DigestAuthenticator.java


示例2: getWebSocketAccept

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
private String getWebSocketAccept(String key) throws ServletException {

        MessageDigest sha1Helper = sha1Helpers.poll();
        if (sha1Helper == null) {
            try {
                sha1Helper = MessageDigest.getInstance("SHA1");
            } catch (NoSuchAlgorithmException e) {
                throw new ServletException(e);
            }
        }

        sha1Helper.reset();
        sha1Helper.update(key.getBytes(B2CConverter.ISO_8859_1));
        String result = Base64.encode(sha1Helper.digest(WS_ACCEPT));

        sha1Helpers.add(sha1Helper);

        return result;
    }
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:20,代码来源:WebSocketServlet.java


示例3: doWriteText

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
private void doWriteText(CharBuffer buffer, boolean finalFragment)
        throws IOException {
    CharsetEncoder encoder = B2CConverter.UTF_8.newEncoder();
    do {
        CoderResult cr = encoder.encode(buffer, bb, true);
        if (cr.isError()) {
            cr.throwException();
        }
        bb.flip();
        if (buffer.hasRemaining()) {
            doWriteBytes(bb, false);
        } else {
            doWriteBytes(bb, finalFragment);
        }
    } while (buffer.hasRemaining());

    // Reset - bb will be cleared in doWriteBytes()
    cb.clear();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:20,代码来源:WsOutbound.java


示例4: parseParameters

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
/**
 * Append request parameters from the specified String to the specified
 * Map.  It is presumed that the specified Map is not accessed from any
 * other thread, so no synchronization is performed.
 * <p>
 * <strong>IMPLEMENTATION NOTE</strong>:  URL decoding is performed
 * individually on the parsed name and value elements, rather than on
 * the entire query string ahead of time, to properly deal with the case
 * where the name or value includes an encoded "=" or "&" character
 * that would otherwise be interpreted as a delimiter.
 *
 * @param map Map that accumulates the resulting parameters
 * @param data Input string containing request parameters
 * @param encoding The encoding to use; encoding must not be null.
 * If an unsupported encoding is specified the parameters will not be
 * parsed and the map will not be modified
 */
public static void parseParameters(Map<String,String[]> map, String data,
        String encoding) {

    if ((data != null) && (data.length() > 0)) {

        // use the specified encoding to extract bytes out of the
        // given string so that the encoding is not lost.
        byte[] bytes = null;
        try {
            bytes = data.getBytes(B2CConverter.getCharset(encoding));
            parseParameters(map, bytes, encoding);
        } catch (UnsupportedEncodingException uee) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("requestUtil.parseParameters.uee",
                        encoding), uee);
            }
        }

    }

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:39,代码来源:RequestUtil.java


示例5: URLDecode

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
/**
 * Decode and return the specified URL-encoded String.
 *
 * @param str The url-encoded string
 * @param enc The encoding to use; if null, the default encoding is used. If
 * an unsupported encoding is specified null will be returned
 * @param isQuery Is this a query string being processed
 * @exception IllegalArgumentException if a '%' character is not followed
 * by a valid 2-digit hexadecimal number
 */
public static String URLDecode(String str, String enc, boolean isQuery) {
    if (str == null)
        return (null);

    // use the specified encoding to extract bytes out of the
    // given string so that the encoding is not lost. If an
    // encoding is not specified, let it use platform default
    byte[] bytes = null;
    try {
        if (enc == null) {
            bytes = str.getBytes(Charset.defaultCharset());
        } else {
            bytes = str.getBytes(B2CConverter.getCharset(enc));
        }
    } catch (UnsupportedEncodingException uee) {
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("requestUtil.urlDecode.uee", enc), uee);
        }
    }

    return URLDecode(bytes, enc, isQuery);

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:34,代码来源:RequestUtil.java


示例6: doUtf8BodyTest

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
private void doUtf8BodyTest(String description, int[] input,
        String expected) throws Exception {

    byte[] bytes = new byte[input.length];
    for (int i = 0; i < input.length; i++) {
        bytes[i] = (byte) input[i];
    }

    ByteChunk bc = new ByteChunk();
    int rc = postUrl(bytes, "http://localhost:" + getPort() + "/test", bc,
            null);

    if (expected == null) {
        Assert.assertEquals(description, HttpServletResponse.SC_OK, rc);
        Assert.assertEquals(description, "FAILED", bc.toString());
    } else if (expected.length() == 0) {
        Assert.assertNull(description, bc.toString());
    } else {
        bc.setCharset(B2CConverter.UTF_8);
        Assert.assertEquals(description, expected, bc.toString());
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:23,代码来源:TestInputBuffer.java


示例7: testInvalidPostWithRequestParams

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
private void testInvalidPostWithRequestParams() throws Exception {
    String validBody = Constants.CSRF_REST_NONCE_HEADER_NAME + "=" + validNonce;
    String invalidbody1 = Constants.CSRF_REST_NONCE_HEADER_NAME + "=" + INVALID_NONCE_1;
    String invalidbody2 = Constants.CSRF_REST_NONCE_HEADER_NAME + "="
            + Constants.CSRF_REST_NONCE_HEADER_FETCH_VALUE;
    doTest(METHOD_POST, REMOVE_ALL_CUSTOMERS, CREDENTIALS,
            validBody.getBytes(B2CConverter.ISO_8859_1), USE_COOKIES,
            HttpServletResponse.SC_FORBIDDEN, null, null, true,
            Constants.CSRF_REST_NONCE_HEADER_REQUIRED_VALUE);
    doTest(METHOD_POST, REMOVE_CUSTOMER, CREDENTIALS,
            invalidbody1.getBytes(B2CConverter.ISO_8859_1), USE_COOKIES,
            HttpServletResponse.SC_FORBIDDEN, null, null, true,
            Constants.CSRF_REST_NONCE_HEADER_REQUIRED_VALUE);
    doTest(METHOD_POST, REMOVE_CUSTOMER, CREDENTIALS,
            invalidbody2.getBytes(B2CConverter.ISO_8859_1), USE_COOKIES,
            HttpServletResponse.SC_FORBIDDEN, null, null, true,
            Constants.CSRF_REST_NONCE_HEADER_REQUIRED_VALUE);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:TestRestCsrfPreventionFilter2.java


示例8: generateNonce

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
/**
 * Generate a unique token. The token is generated according to the
 * following pattern. NOnceToken = Base64 ( MD5 ( client-IP ":"
 * time-stamp ":" private-key ) ).
 *
 * @param request HTTP Servlet request
 */
protected String generateNonce(Request request) {

    long currentTime = System.currentTimeMillis();

    synchronized (lastTimestampLock) {
        if (currentTime > lastTimestamp) {
            lastTimestamp = currentTime;
        } else {
            currentTime = ++lastTimestamp;
        }
    }

    String ipTimeKey =
        request.getRemoteAddr() + ":" + currentTime + ":" + getKey();

    byte[] buffer = ConcurrentMessageDigest.digestMD5(
            ipTimeKey.getBytes(B2CConverter.ISO_8859_1));
    String nonce = currentTime + ":" + MD5Encoder.encode(buffer);

    NonceInfo info = new NonceInfo(currentTime, getNonceCountWindowSize());
    synchronized (nonces) {
        nonces.put(nonce, info);
    }

    return nonce;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:34,代码来源:DigestAuthenticator.java


示例9: getWebSocketAccept

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
private String getWebSocketAccept(String key) throws ServletException {

		MessageDigest sha1Helper = sha1Helpers.poll();
		if (sha1Helper == null) {
			try {
				sha1Helper = MessageDigest.getInstance("SHA1");
			} catch (NoSuchAlgorithmException e) {
				throw new ServletException(e);
			}
		}

		sha1Helper.reset();
		sha1Helper.update(key.getBytes(B2CConverter.ISO_8859_1));
		String result = Base64.encode(sha1Helper.digest(WS_ACCEPT));

		sha1Helpers.add(sha1Helper);

		return result;
	}
 
开发者ID:how2j,项目名称:lazycat,代码行数:20,代码来源:WebSocketServlet.java


示例10: doWriteText

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
private void doWriteText(CharBuffer buffer, boolean finalFragment) throws IOException {
	CharsetEncoder encoder = B2CConverter.UTF_8.newEncoder();
	do {
		CoderResult cr = encoder.encode(buffer, bb, true);
		if (cr.isError()) {
			cr.throwException();
		}
		bb.flip();
		if (buffer.hasRemaining()) {
			doWriteBytes(bb, false);
		} else {
			doWriteBytes(bb, finalFragment);
		}
	} while (buffer.hasRemaining());

	// Reset - bb will be cleared in doWriteBytes()
	cb.clear();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:19,代码来源:WsOutbound.java


示例11: URLDecode

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
/**
 * Decode and return the specified URL-encoded String.
 *
 * @param str
 *            The url-encoded string
 * @param enc
 *            The encoding to use; if null, the default encoding is used. If
 *            an unsupported encoding is specified null will be returned
 * @param isQuery
 *            Is this a query string being processed
 * @exception IllegalArgumentException
 *                if a '%' character is not followed by a valid 2-digit
 *                hexadecimal number
 */
public static String URLDecode(String str, String enc, boolean isQuery) {
	if (str == null)
		return (null);

	// use the specified encoding to extract bytes out of the
	// given string so that the encoding is not lost. If an
	// encoding is not specified, let it use platform default
	byte[] bytes = null;
	try {
		if (enc == null) {
			bytes = str.getBytes(Charset.defaultCharset());
		} else {
			bytes = str.getBytes(B2CConverter.getCharset(enc));
		}
	} catch (UnsupportedEncodingException uee) {
		if (log.isDebugEnabled()) {
			log.debug(sm.getString("requestUtil.urlDecode.uee", enc), uee);
		}
	}

	return URLDecode(bytes, enc, isQuery);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:38,代码来源:RequestUtil.java


示例12: setCharacterEncoding

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
/**
 * Overrides the name of the character encoding used in the body of
 * this request.  This method must be called prior to reading request
 * parameters or reading input using <code>getReader()</code>.
 *
 * @param enc The character encoding to be used
 *
 * @exception UnsupportedEncodingException if the specified encoding
 *  is not supported
 *
 * @since Servlet 2.3
 */
@Override
public void setCharacterEncoding(String enc)
    throws UnsupportedEncodingException {

    if (usingReader) {
        return;
    }

    // Ensure that the specified encoding is valid
    byte buffer[] = new byte[1];
    buffer[0] = (byte) 'a';

    // Confirm that the encoding name is valid
    B2CConverter.getCharset(enc);

    // Save the validated encoding
    coyoteRequest.setCharacterEncoding(enc);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:31,代码来源:Request.java


示例13: setCharacterEncoding

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
/**
 * Overrides the name of the character encoding used in the body of
 * this request.  This method must be called prior to reading request
 * parameters or reading input using <code>getReader()</code>.
 *
 * @param enc The character encoding to be used
 *
 * @exception UnsupportedEncodingException if the specified encoding
 *  is not supported
 *
 * @since Servlet 2.3
 */
@Override
public void setCharacterEncoding(String enc)
    throws UnsupportedEncodingException {

    if (usingReader)
        return;
    
    // Ensure that the specified encoding is valid
    byte buffer[] = new byte[1];
    buffer[0] = (byte) 'a';

    // Confirm that the encoding name is valid
    B2CConverter.getCharset(enc);
    
    // Save the validated encoding
    coyoteRequest.setCharacterEncoding(enc);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:30,代码来源:Request.java


示例14: setCharacterEncoding

import org.apache.tomcat.util.buf.B2CConverter; //导入依赖的package包/类
/**
 * Overrides the name of the character encoding used in the body of
 * this request.  This method must be called prior to reading request
 * parameters or reading input using <code>getReader()</code>.
 *
 * @param enc The character encoding to be used
 *
 * @exception UnsupportedEncodingException if the specified encoding
 *  is not supported
 *
 * @since Servlet 2.3
 */
@Override
public void setCharacterEncoding(String enc)
    throws UnsupportedEncodingException {

    if (usingReader) {
        return;
    }

    // Confirm that the encoding name is valid
    B2CConverter.getCharset(enc);

    // Save the validated encoding
    coyoteRequest.setCharacterEncoding(enc);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:Request.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CglibProxyFactory类代码示例发布时间:2022-05-23
下一篇:
Java SupportSQLiteStatement类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap