本文整理汇总了Java中org.apache.tomcat.util.http.MimeHeaders类的典型用法代码示例。如果您正苦于以下问题:Java MimeHeaders类的具体用法?Java MimeHeaders怎么用?Java MimeHeaders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MimeHeaders类属于org.apache.tomcat.util.http包,在下文中一共展示了MimeHeaders类的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: testCanHandleWithFalseConditions
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
@Test(description = "This test case tests the canHandle method of the BSTAuthenticator under faulty conditions")
public void testCanHandleWithFalseConditions() throws IllegalAccessException {
Request request = new Request();
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
request.setCoyoteRequest(coyoteRequest);
Assert.assertFalse(bstAuthenticator.canHandle(request),
"BST Authenticator can handle a request without content type");
MimeHeaders mimeHeaders = new MimeHeaders();
MessageBytes bytes = mimeHeaders.addValue("content-type");
bytes.setString("test");
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
Assert.assertFalse(bstAuthenticator.canHandle(request),
"BST Authenticator can handle a request with content type test");
}
示例3: createSoapRequest
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
/**
* To create a soap request by reading the request from given file.
*
* @param fileName Name of the file that has the soap request content.
* @return Request created with soap content.
* @throws IllegalAccessException Illegal Access Exception.
* @throws IOException IO Exception.
*/
private Request createSoapRequest(String fileName) throws IllegalAccessException, IOException {
Request request = new Request();
ClassLoader classLoader = getClass().getClassLoader();
URL resourceUrl = classLoader
.getResource("requests" + File.separator + "BST" + File.separator + fileName);
String bstRequestContent = null;
if (resourceUrl != null) {
File bst = new File(resourceUrl.getFile());
bstRequestContent = FileUtils.readFileToString(bst);
}
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
MimeHeaders mimeHeaders = new MimeHeaders();
MessageBytes bytes = mimeHeaders.addValue("content-type");
bytes.setString("application/xml");
bytes = mimeHeaders.addValue("custom");
bytes.setString(bstRequestContent);
headersField.set(coyoteRequest, mimeHeaders);
TestInputBuffer inputBuffer = new TestInputBuffer();
coyoteRequest.setInputBuffer(inputBuffer);
Context context = new StandardContext();
request.setContext(context);
request.setCoyoteRequest(coyoteRequest);
return request;
}
示例4: createJWTRequest
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
/**
* To create a JWT request with the given jwt header.
* @param jwtToken JWT token to be added to the header
* @param requestUri Request URI to be added to the request.
*/
private Request createJWTRequest(String jwtToken, String requestUri)
throws IllegalAccessException, NoSuchFieldException {
Request request = new Request();
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
MimeHeaders mimeHeaders = new MimeHeaders();
MessageBytes bytes = mimeHeaders.addValue(JWT_HEADER);
bytes.setString(jwtToken);
headersField.set(coyoteRequest, mimeHeaders);
Field uriMB = org.apache.coyote.Request.class.getDeclaredField("uriMB");
uriMB.setAccessible(true);
bytes = MessageBytes.newInstance();
bytes.setString(requestUri);
uriMB.set(coyoteRequest, bytes);
request.setCoyoteRequest(coyoteRequest);
return request;
}
示例5: testCanHandleWithoutRequireParameters
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
@Test(description = "This method tests the behaviour of canHandle method when different wrong values given for a "
+ "request")
public void testCanHandleWithoutRequireParameters()
throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException,
InvocationTargetException, InstantiationException {
request = new Request();
context = new StandardContext();
request.setContext(context);
Assert.assertFalse(basicAuthAuthenticator.canHandle(request),
"Without proper headers and parameters, the request can be handled by BasicAuthAuthenticator.");
context.addParameter("basicAuth", "true");
request.setContext(context);
Assert.assertFalse(basicAuthAuthenticator.canHandle(request),
"Without proper Authentication headers request can be handled by BasicAuthAuthenticator.");
coyoteRequest = new org.apache.coyote.Request();
mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("test");
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
Assert.assertFalse(basicAuthAuthenticator.canHandle(request),
"With a different authorization header Basic Authenticator can handle the request");
}
示例6: testAuthenticateWithValidCredentials
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
@Test(description = "This method tests the behaviour of the authenticate method in BasicAuthenticator with valid "
+ "credentials", dependsOnMethods = "testCanHandleWithRequireParameters")
public void testAuthenticateWithValidCredentials() throws EncoderException, IllegalAccessException {
String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":" + ADMIN_USER).getBytes()));
request = new Request();
context = new StandardContext();
context.addParameter("basicAuth", "true");
request.setContext(context);
mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString(BASIC_HEADER + encodedString);
coyoteRequest = new org.apache.coyote.Request();
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
AuthenticationInfo authenticationInfo = basicAuthAuthenticator.authenticate(request, null);
Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.CONTINUE,
"For a valid user authentication failed.");
Assert.assertEquals(authenticationInfo.getUsername(), ADMIN_USER,
"Authenticated username for from BasicAuthenticator is not matching with the original user.");
Assert.assertEquals(authenticationInfo.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
"Authenticated user's tenant domain from BasicAuthenticator is not matching with the "
+ "original user's tenant domain");
Assert.assertEquals(authenticationInfo.getTenantId(), MultitenantConstants.SUPER_TENANT_ID,
"Authenticated user's tenant ID from BasicAuthenticator is not matching with the "
+ "original user's tenant ID");
}
示例7: createRequest
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
/**
* To create a request with the given authorization header
*
* @param authorizationHeader Authorization header
* @return the relevant request.
* @throws IllegalAccessException Illegal Access Exception.
* @throws NoSuchFieldException No Such Field Exception.
*/
private Request createRequest(String authorizationHeader) throws IllegalAccessException, NoSuchFieldException {
Request request = new TestRequest("", "");
Context context = new StandardContext();
context.addParameter("basicAuth", "true");
context.addParameter("managed-api-enabled", "true");
context.setPath("carbon1");
context.addParameter("doAuthentication", String.valueOf(true));
request.setContext(context);
MimeHeaders mimeHeaders = new MimeHeaders();
MessageBytes bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString(authorizationHeader);
Field headersField = org.apache.coyote.Request.class.getDeclaredField("headers");
headersField.setAccessible(true);
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
return request;
}
示例8: convertHeaders
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
private static void convertHeaders(HttpHeaders headers, MimeHeaders cHeaders) {
if (headers.isEmpty()) {
return;
}
for (Entry<AsciiString, String> e : headers) {
final AsciiString k = e.getKey();
final String v = e.getValue();
if (k.isEmpty() || k.byteAt(0) == ':') {
continue;
}
final MessageBytes cValue = cHeaders.addValue(k.array(), k.arrayOffset(), k.length());
final byte[] valueBytes = v.getBytes(StandardCharsets.US_ASCII);
cValue.setBytes(valueBytes, 0, valueBytes.length);
}
}
示例9: 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;
}
示例10: 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());
}
}
示例11: modifyHandshake
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
HttpServletRequest _request = (HttpServletRequest) GenericReflection.NoThrow.getValue(_HandshakeRequest, request);
Request _requestFaced = (Request) GenericReflection.NoThrow.getValue(Core.requestField, _request);
MimeHeaders mime = new MimeHeaders();
Enumeration<String> enuns = _requestFaced.getHeaderNames();
while(enuns.hasMoreElements()){
String param = (String) enuns.nextElement();
mime.addValue(param).setString(_requestFaced.getHeader(param));
}
Map<String, Object> properties = config.getUserProperties();
properties.put("httpRequest", _request);
properties.put("httpResponse", _request.getAttribute("httpResponse"));
properties.put("httpSession", _request.getSession());
properties.put("context", _requestFaced.getContext());
properties.put("headers", mime);
properties.put("remoteHost", _request.getRemoteHost());
properties.put("localPort", _request.getLocalPort());
properties.put("remoteAddr", _request.getRemoteAddr());
}
示例12: 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;
}
示例13: 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());
}
}
示例14: isConnectionClose
import org.apache.tomcat.util.http.MimeHeaders; //导入依赖的package包/类
private boolean isConnectionClose(MimeHeaders headers) {
MessageBytes connection = headers.getValue(Constants.CONNECTION);
if (connection == null) {
return false;
}
return connection.equals(Constants.CLOSE);
}
示例15: 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;
}