本文整理汇总了Java中org.apache.tomcat.util.buf.MessageBytes.toBytes方法的典型用法代码示例。如果您正苦于以下问题:Java MessageBytes.toBytes方法的具体用法?Java MessageBytes.toBytes怎么用?Java MessageBytes.toBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.buf.MessageBytes
的用法示例。
在下文中一共展示了MessageBytes.toBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processParameters
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
public void processParameters( MessageBytes data, String encoding ) {
if( data==null || data.isNull() || data.getLength() <= 0 ) {
return;
}
if( data.getType() != MessageBytes.T_BYTES ) {
data.toBytes();
}
ByteChunk bc=data.getByteChunk();
processParameters( bc.getBytes(), bc.getOffset(),
bc.getLength(), getCharset(encoding));
}
示例2: processParameters
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
public void processParameters(MessageBytes data, String encoding) {
if (data == null || data.isNull() || data.getLength() <= 0)
return;
if (data.getType() != MessageBytes.T_BYTES) {
data.toBytes();
}
ByteChunk bc = data.getByteChunk();
processParameters(bc.getBytes(), bc.getOffset(), bc.getLength(),
encoding);
}
示例3: processParameters
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
public void processParameters(MessageBytes data, String encoding) {
if (data == null || data.isNull() || data.getLength() <= 0) {
return;
}
if (data.getType() != MessageBytes.T_BYTES) {
data.toBytes();
}
ByteChunk bc = data.getByteChunk();
processParameters(bc.getBytes(), bc.getOffset(), bc.getLength(), getCharset(encoding));
}
示例4: processCookies
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
/** Add all Cookie found in the headers of a request.
*/
public void processCookies( MimeHeaders headers ) {
if( headers==null ) {
return;// nothing to process
}
// process each "cookie" header
int pos=0;
while( pos>=0 ) {
// Cookie2: version ? not needed
pos=headers.findHeader( "Cookie", pos );
// no more cookie headers headers
if( pos<0 ) {
break;
}
MessageBytes cookieValue=headers.getValue( pos );
if( cookieValue==null || cookieValue.isNull() ) {
pos++;
continue;
}
if( cookieValue.getType() != MessageBytes.T_BYTES ) {
Exception e = new Exception();
log.warn("Cookies: Parsing cookie as String. Expected bytes.",
e);
cookieValue.toBytes();
}
if(log.isDebugEnabled()) {
log.debug("Cookies: Parsing b[]: " + cookieValue.toString());
}
ByteChunk bc=cookieValue.getByteChunk();
if (CookieSupport.PRESERVE_COOKIE_HEADER) {
int len = bc.getLength();
if (len > 0) {
byte[] buf = new byte[len];
System.arraycopy(bc.getBytes(), bc.getOffset(), buf, 0, len);
processCookieHeader(buf, 0, len);
}
} else {
processCookieHeader( bc.getBytes(),
bc.getOffset(),
bc.getLength());
}
pos++;// search from the next position
}
}
示例5: authenticate
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
/**
* Authenticate the user making this request, based on the specified login
* configuration. Return <code>true</code> if any specified constraint has
* been satisfied, or <code>false</code> if we have created a response
* challenge already.
*
* @param request
* Request we are processing
* @param response
* Response we are creating
* @param config
* Login configuration describing how authentication should be
* performed
*
* @exception IOException
* if an input/output error occurs
*/
@Override
public boolean authenticate(Request request, HttpServletResponse response, LoginConfig config) throws IOException {
if (checkForCachedAuthentication(request, response, true)) {
return true;
}
// Validate any credentials already included with this request
String username = null;
String password = null;
MessageBytes authorization = request.getCoyoteRequest().getMimeHeaders().getValue("authorization");
if (authorization != null) {
authorization.toBytes();
ByteChunk authorizationBC = authorization.getByteChunk();
if (authorizationBC.startsWithIgnoreCase("basic ", 0)) {
authorizationBC.setOffset(authorizationBC.getOffset() + 6);
byte[] decoded = Base64.decodeBase64(authorizationBC.getBuffer(), authorizationBC.getOffset(),
authorizationBC.getLength());
// Get username and password
int colon = -1;
for (int i = 0; i < decoded.length; i++) {
if (decoded[i] == ':') {
colon = i;
break;
}
}
if (colon < 0) {
username = new String(decoded, B2CConverter.ISO_8859_1);
} else {
username = new String(decoded, 0, colon, B2CConverter.ISO_8859_1);
password = new String(decoded, colon + 1, decoded.length - colon - 1, B2CConverter.ISO_8859_1);
}
authorizationBC.setOffset(authorizationBC.getOffset() - 6);
}
Principal principal = context.getRealm().authenticate(username, password);
if (principal != null) {
register(request, response, principal, HttpServletRequest.BASIC_AUTH, username, password);
return (true);
}
}
StringBuilder value = new StringBuilder(16);
value.append("Basic realm=\"");
if (config.getRealmName() == null) {
value.append(REALM_NAME);
} else {
value.append(config.getRealmName());
}
value.append('\"');
response.setHeader(AUTH_HEADER_NAME, value.toString());
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return (false);
}
示例6: processCookies
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
/**
* Add all Cookie found in the headers of a request.
*/
public void processCookies(MimeHeaders headers) {
if (headers == null) {
return;// nothing to process
}
// process each "cookie" header
int pos = 0;
while (pos >= 0) {
// Cookie2: version ? not needed
pos = headers.findHeader("Cookie", pos);
// no more cookie headers headers
if (pos < 0) {
break;
}
MessageBytes cookieValue = headers.getValue(pos);
if (cookieValue == null || cookieValue.isNull()) {
pos++;
continue;
}
if (cookieValue.getType() != MessageBytes.T_BYTES) {
Exception e = new Exception();
log.warn("Cookies: Parsing cookie as String. Expected bytes.", e);
cookieValue.toBytes();
}
if (log.isDebugEnabled()) {
log.debug("Cookies: Parsing b[]: " + cookieValue.toString());
}
ByteChunk bc = cookieValue.getByteChunk();
if (CookieSupport.PRESERVE_COOKIE_HEADER) {
int len = bc.getLength();
if (len > 0) {
byte[] buf = new byte[len];
System.arraycopy(bc.getBytes(), bc.getOffset(), buf, 0, len);
processCookieHeader(buf, 0, len);
}
} else {
processCookieHeader(bc.getBytes(), bc.getOffset(), bc.getLength());
}
pos++;// search from the next position
}
}