本文整理汇总了Java中org.apache.tomcat.util.http.MimeHeaders.size方法的典型用法代码示例。如果您正苦于以下问题:Java MimeHeaders.size方法的具体用法?Java MimeHeaders.size怎么用?Java MimeHeaders.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.http.MimeHeaders
的用法示例。
在下文中一共展示了MimeHeaders.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSessionCookieInternal
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* Special method for adding a session cookie as we should be overriding any
* previous
*
* @param cookie
*/
public void addSessionCookieInternal(final Cookie cookie) {
if (isCommitted()) {
return;
}
String name = cookie.getName();
final String headername = "Set-Cookie";
final String startsWith = name + "=";
final StringBuffer sb = generateCookieString(cookie);
boolean set = false;
MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
int n = headers.size();
for (int i = 0; i < n; i++) {
if (headers.getName(i).toString().equals(headername)) {
if (headers.getValue(i).toString().startsWith(startsWith)) {
headers.getValue(i).setString(sb.toString());
set = true;
}
}
}
if (!set) {
addHeader(headername, sb.toString());
}
}
示例2: getHeaderNames
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
@Override
public Collection<String> getHeaderNames() {
MimeHeaders headers = coyoteResponse.getMimeHeaders();
int n = headers.size();
List<String> result = new ArrayList<String>(n);
for (int i = 0; i < n; i++) {
result.add(headers.getName(i).toString());
}
return result;
}
示例3: addSessionCookieInternal
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* Special method for adding a session cookie as we should be overriding
* any previous
* @param cookie
*/
public void addSessionCookieInternal(final Cookie cookie) {
if (isCommitted())
return;
String name = cookie.getName();
final String headername = "Set-Cookie";
final String startsWith = name + "=";
final StringBuffer sb = generateCookieString(cookie);
boolean set = false;
MimeHeaders headers = coyoteResponse.getMimeHeaders();
int n = headers.size();
for (int i = 0; i < n; i++) {
if (headers.getName(i).toString().equals(headername)) {
if (headers.getValue(i).toString().startsWith(startsWith)) {
headers.getValue(i).setString(sb.toString());
set = true;
}
}
}
if (!set) {
addHeader(headername, sb.toString());
}
}
示例4: getHeaderNames
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
@Override
public Collection<String> getHeaderNames() {
MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
int n = headers.size();
List<String> result = new ArrayList<String>(n);
for (int i = 0; i < n; i++) {
result.add(headers.getName(i).toString());
}
return result;
}
示例5: addSessionCookieInternal
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* Special method for adding a session cookie as we should be overriding
* any previous
* @param cookie
*/
public void addSessionCookieInternal(final Cookie cookie) {
if (isCommitted()) {
return;
}
String name = cookie.getName();
final String headername = "Set-Cookie";
final String startsWith = name + "=";
final StringBuffer sb = generateCookieString(cookie);
boolean set = false;
MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
int n = headers.size();
for (int i = 0; i < n; i++) {
if (headers.getName(i).toString().equals(headername)) {
if (headers.getValue(i).toString().startsWith(startsWith)) {
headers.getValue(i).setString(sb.toString());
set = true;
}
}
}
if (!set) {
addHeader(headername, sb.toString());
}
}
示例6: getHeaderNames
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* Return an array of all the header names set for this response, or
* a zero-length array if no headers have been set.
*/
public String[] getHeaderNames() {
MimeHeaders headers = coyoteResponse.getMimeHeaders();
int n = headers.size();
String[] result = new String[n];
for (int i = 0; i < n; i++) {
result[i] = headers.getName(i).toString();
}
return result;
}
示例7: getHeaderNames
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
@Override
public Collection<String> getHeaderNames() {
MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
int n = headers.size();
List<String> result = new ArrayList<String>(n);
for (int i = 0; i < n; i++) {
result.add(headers.getName(i).toString());
}
return result;
}
示例8: convertResponse
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
private static HttpHeaders convertResponse(Response coyoteRes) {
final HttpHeaders headers = HttpHeaders.of(HttpStatus.valueOf(coyoteRes.getStatus()));
final String contentType = coyoteRes.getContentType();
if (contentType != null && !contentType.isEmpty()) {
headers.set(HttpHeaderNames.CONTENT_TYPE, contentType);
}
final long contentLength = coyoteRes.getBytesWritten(true); // 'true' will trigger flush.
final String method = coyoteRes.getRequest().method().toString();
if (!"HEAD".equals(method)) {
headers.setLong(HttpHeaderNames.CONTENT_LENGTH, contentLength);
}
final MimeHeaders cHeaders = coyoteRes.getMimeHeaders();
final int numHeaders = cHeaders.size();
for (int i = 0; i < numHeaders; i++) {
final AsciiString name = toHeaderName(cHeaders.getName(i));
if (name == null) {
continue;
}
final String value = toHeaderValue(cHeaders.getValue(i));
if (value == null) {
continue;
}
headers.add(name.toLowerCase(), value);
}
return headers;
}
示例9: addSessionCookieInternal
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* Special method for adding a session cookie as we should be overriding
* any previous
* @param cookie
*/
public void addSessionCookieInternal(final Cookie cookie) {
if (isCommitted()) {
return;
}
String name = cookie.getName();
final String headername = "Set-Cookie";
final String startsWith = name + "=";
final StringBuffer sb = generateCookieString(cookie);
boolean set = false;
MimeHeaders headers = coyoteResponse.getMimeHeaders();
int n = headers.size();
for (int i = 0; i < n; i++) {
if (headers.getName(i).toString().equals(headername)) {
if (headers.getValue(i).toString().startsWith(startsWith)) {
headers.getValue(i).setString(sb.toString());
set = true;
}
}
}
if (!set) {
addHeader(headername, sb.toString());
}
}
示例10: getHeaderNames
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* Return an Iterable of all the header names set for this response.
*/
@Override
public Collection<String> getHeaderNames() {
MimeHeaders headers = coyoteResponse.getMimeHeaders();
int n = headers.size();
List<String> result = new ArrayList<String>(n);
for (int i = 0; i < n; i++) {
result.add(headers.getName(i).toString());
}
return result;
}
示例11: prepareResponse
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* When committing the response, we have to validate the set of headers, as
* well as setup the response filters.
*/
protected void prepareResponse()
throws IOException {
response.setCommitted(true);
responseHeaderMessage.reset();
responseHeaderMessage.appendByte(Constants.JK_AJP13_SEND_HEADERS);
// HTTP header contents
responseHeaderMessage.appendInt(response.getStatus());
String message = null;
if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER) {
message = response.getMessage();
}
if (message == null){
message = HttpMessages.getMessage(response.getStatus());
} else {
message = message.replace('\n', ' ').replace('\r', ' ');
}
if (message == null) {
// Many httpd 2.x wants a non empty status message
message = Integer.toString(response.getStatus());
}
tmpMB.setString(message);
responseHeaderMessage.appendBytes(tmpMB);
// Special headers
MimeHeaders headers = response.getMimeHeaders();
String contentType = response.getContentType();
if (contentType != null) {
headers.setValue("Content-Type").setString(contentType);
}
String contentLanguage = response.getContentLanguage();
if (contentLanguage != null) {
headers.setValue("Content-Language").setString(contentLanguage);
}
int contentLength = response.getContentLength();
if (contentLength >= 0) {
headers.setValue("Content-Length").setInt(contentLength);
}
// Other headers
int numHeaders = headers.size();
responseHeaderMessage.appendInt(numHeaders);
for (int i = 0; i < numHeaders; i++) {
MessageBytes hN = headers.getName(i);
int hC = Constants.getResponseAjpIndex(hN.toString());
if (hC > 0) {
responseHeaderMessage.appendInt(hC);
}
else {
responseHeaderMessage.appendBytes(hN);
}
MessageBytes hV=headers.getValue(i);
responseHeaderMessage.appendBytes(hV);
}
// Write to buffer
responseHeaderMessage.end();
outputBuffer.put(responseHeaderMessage.getBuffer(), 0, responseHeaderMessage.getLen());
}
示例12: prepareResponse
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* When committing the response, we have to validate the set of headers, as
* well as setup the response filters.
*/
protected void prepareResponse()
throws IOException {
response.setCommitted(true);
responseHeaderMessage.reset();
responseHeaderMessage.appendByte(Constants.JK_AJP13_SEND_HEADERS);
// HTTP header contents
responseHeaderMessage.appendInt(response.getStatus());
String message = null;
if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER) {
message = response.getMessage();
}
if (message == null){
message = HttpMessages.getMessage(response.getStatus());
} else {
message = message.replace('\n', ' ').replace('\r', ' ');
}
if (message == null) {
// Many httpd 2.x wants a non empty status message
message = Integer.toString(response.getStatus());
}
tmpMB.setString(message);
responseHeaderMessage.appendBytes(tmpMB);
// Special headers
MimeHeaders headers = response.getMimeHeaders();
String contentType = response.getContentType();
if (contentType != null) {
headers.setValue("Content-Type").setString(contentType);
}
String contentLanguage = response.getContentLanguage();
if (contentLanguage != null) {
headers.setValue("Content-Language").setString(contentLanguage);
}
int contentLength = response.getContentLength();
if (contentLength >= 0) {
headers.setValue("Content-Length").setInt(contentLength);
}
// Other headers
int numHeaders = headers.size();
responseHeaderMessage.appendInt(numHeaders);
for (int i = 0; i < numHeaders; i++) {
MessageBytes hN = headers.getName(i);
int hC = Constants.getResponseAjpIndex(hN.toString());
if (hC > 0) {
responseHeaderMessage.appendInt(hC);
}
else {
responseHeaderMessage.appendBytes(hN);
}
MessageBytes hV=headers.getValue(i);
responseHeaderMessage.appendBytes(hV);
}
// Write to buffer
responseHeaderMessage.end();
output.write(responseHeaderMessage.getBuffer(), 0, responseHeaderMessage.getLen());
}
示例13: prepareResponse
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* When committing the response, we have to validate the set of headers, as
* well as setup the response filters.
*/
protected void prepareResponse() throws IOException {
response.setCommitted(true);
responseMessage.reset();
responseMessage.appendByte(Constants.JK_AJP13_SEND_HEADERS);
// Responses with certain status codes are not permitted to include a
// response body.
int statusCode = response.getStatus();
if (statusCode < 200 || statusCode == 204 || statusCode == 205 || statusCode == 304) {
// No entity body
swallowResponse = true;
}
// Responses to HEAD requests are not permitted to incude a response
// body.
MessageBytes methodMB = request.method();
if (methodMB.equals("HEAD")) {
// No entity body
swallowResponse = true;
}
// HTTP header contents
responseMessage.appendInt(statusCode);
String message = null;
if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER
&& HttpMessages.isSafeInHttpHeader(response.getMessage())) {
message = response.getMessage();
}
if (message == null) {
message = HttpMessages.getInstance(response.getLocale()).getMessage(response.getStatus());
}
if (message == null) {
// mod_jk + httpd 2.x fails with a null status message - bug 45026
message = Integer.toString(response.getStatus());
}
tmpMB.setString(message);
responseMessage.appendBytes(tmpMB);
// Special headers
MimeHeaders headers = response.getMimeHeaders();
String contentType = response.getContentType();
if (contentType != null) {
headers.setValue("Content-Type").setString(contentType);
}
String contentLanguage = response.getContentLanguage();
if (contentLanguage != null) {
headers.setValue("Content-Language").setString(contentLanguage);
}
long contentLength = response.getContentLengthLong();
if (contentLength >= 0) {
headers.setValue("Content-Length").setLong(contentLength);
}
// Other headers
int numHeaders = headers.size();
responseMessage.appendInt(numHeaders);
for (int i = 0; i < numHeaders; i++) {
MessageBytes hN = headers.getName(i);
int hC = Constants.getResponseAjpIndex(hN.toString());
if (hC > 0) {
responseMessage.appendInt(hC);
} else {
responseMessage.appendBytes(hN);
}
MessageBytes hV = headers.getValue(i);
responseMessage.appendBytes(hV);
}
// Write to buffer
responseMessage.end();
output(responseMessage.getBuffer(), 0, responseMessage.getLen());
}
示例14: replaceCookie
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
protected void replaceCookie(Request request, Response response, Cookie cookie) {
Delegator delegator = (Delegator) request.getAttribute("delegator");
// copy the existing session cookie, but use a different domain (only if domain is valid)
String cookieDomain = null;
cookieDomain = EntityUtilProperties.getPropertyValue("url", "cookie.domain", "", delegator);
if (UtilValidate.isEmpty(cookieDomain)) {
String serverName = request.getServerName();
String[] domainArray = serverName.split("\\.");
// check that the domain isn't an IP address
if (domainArray.length == 4) {
boolean isIpAddress = true;
for (String domainSection : domainArray) {
if (!UtilValidate.isIntegerInRange(domainSection, 0, 255)) {
isIpAddress = false;
break;
}
}
if (isIpAddress) return;
}
if (domainArray.length > 2) {
cookieDomain = "." + domainArray[domainArray.length - 2] + "." + domainArray[domainArray.length - 1];
}
}
if (UtilValidate.isNotEmpty(cookieDomain)) {
Cookie newCookie = new Cookie(cookie.getName(), cookie.getValue());
if (cookie.getPath() != null) {
newCookie.setPath(cookie.getPath());
}
newCookie.setDomain(cookieDomain);
newCookie.setMaxAge(cookie.getMaxAge());
newCookie.setVersion(cookie.getVersion());
if (cookie.getComment() != null) {
newCookie.setComment(cookie.getComment());
}
newCookie.setSecure(cookie.getSecure());
// if the response has already been committed, our replacement strategy will have no effect
if (response.isCommitted()) {
Debug.logError("CrossSubdomainSessionValve: response was already committed!", module);
}
// find the Set-Cookie header for the existing cookie and replace its value with new cookie
MimeHeaders mimeHeaders = request.getCoyoteRequest().getMimeHeaders();
for (int i = 0, size = mimeHeaders.size(); i < size; i++) {
if (mimeHeaders.getName(i).equals("Set-Cookie")) {
MessageBytes value = mimeHeaders.getValue(i);
if (value.indexOf(cookie.getName()) >= 0) {
String newCookieValue = request.getContext().getCookieProcessor().generateHeader(newCookie);
Debug.logVerbose("CrossSubdomainSessionValve: old Set-Cookie value: " + value.toString(), module);
Debug.logVerbose("CrossSubdomainSessionValve: new Set-Cookie value: " + newCookieValue, module);
value.setString(newCookieValue);
}
}
}
}
}
示例15: replaceCookie
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
protected void replaceCookie(Request request, Response response, Cookie cookie) {
// copy the existing session cookie, but use a different domain (only if domain is valid)
String cookieDomain = null;
cookieDomain = UtilProperties.getPropertyValue("url", "cookie.domain", "");
if (UtilValidate.isEmpty(cookieDomain)) {
String serverName = request.getServerName();
String[] domainArray = serverName.split("\\.");
// check that the domain isn't an IP address
if (domainArray.length == 4) {
boolean isIpAddress = true;
for (String domainSection : domainArray) {
if (!UtilValidate.isIntegerInRange(domainSection, 0, 255)) {
isIpAddress = false;
break;
}
}
if (isIpAddress) return;
}
if (domainArray.length > 2) {
cookieDomain = "." + domainArray[domainArray.length - 2] + "." + domainArray[domainArray.length - 1];
}
}
if (UtilValidate.isNotEmpty(cookieDomain)) {
Cookie newCookie = new Cookie(cookie.getName(), cookie.getValue());
if (cookie.getPath() != null) {
newCookie.setPath(cookie.getPath());
}
newCookie.setDomain(cookieDomain);
newCookie.setMaxAge(cookie.getMaxAge());
newCookie.setVersion(cookie.getVersion());
if (cookie.getComment() != null) {
newCookie.setComment(cookie.getComment());
}
newCookie.setSecure(cookie.getSecure());
// if the response has already been committed, our replacement strategy will have no effect
if (response.isCommitted()) {
Debug.logError("CrossSubdomainSessionValve: response was already committed!", module);
}
// find the Set-Cookie header for the existing cookie and replace its value with new cookie
MimeHeaders mimeHeaders = request.getCoyoteRequest().getMimeHeaders();
for (int i = 0, size = mimeHeaders.size(); i < size; i++) {
if (mimeHeaders.getName(i).equals("Set-Cookie")) {
MessageBytes value = mimeHeaders.getValue(i);
if (value.indexOf(cookie.getName()) >= 0) {
StringBuffer buffer = new StringBuffer();
ServerCookie.appendCookieValue(buffer, newCookie.getVersion(), newCookie.getName(), newCookie.getValue(), newCookie.getPath(),
newCookie.getDomain(), newCookie.getComment(), newCookie.getMaxAge(), newCookie.getSecure(), true);
Debug.logVerbose("CrossSubdomainSessionValve: old Set-Cookie value: " + value.toString(), module);
Debug.logVerbose("CrossSubdomainSessionValve: new Set-Cookie value: " + buffer, module);
value.setString(buffer.toString());
}
}
}
}
}