本文整理汇总了Java中org.apache.tomcat.util.http.MimeHeaders.addValue方法的典型用法代码示例。如果您正苦于以下问题:Java MimeHeaders.addValue方法的具体用法?Java MimeHeaders.addValue怎么用?Java MimeHeaders.addValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.http.MimeHeaders
的用法示例。
在下文中一共展示了MimeHeaders.addValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
示例2: 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;
}
示例3: 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;
}
示例4: 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");
}
示例5: 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");
}
示例6: 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;
}
示例7: 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);
}
}
示例8: testHandle
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
@Test(description = "This method tests the canHandle method under different conditions of request")
public void testHandle() throws IllegalAccessException, NoSuchFieldException {
Request request = new Request();
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
request.setCoyoteRequest(coyoteRequest);
Assert.assertFalse(jwtAuthenticator.canHandle(request));
MimeHeaders mimeHeaders = new MimeHeaders();
MessageBytes bytes = mimeHeaders.addValue(JWT_HEADER);
bytes.setString("test");
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
Assert.assertTrue(jwtAuthenticator.canHandle(request));
}
示例9: createOauthRequest
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* This will create an OAuth request.
*
* @param authorizationHeader Authorization Header
*/
private Request createOauthRequest(String authorizationHeader) throws IllegalAccessException {
Request request = new Request();
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
MimeHeaders mimeHeaders = new MimeHeaders();
MessageBytes bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString(authorizationHeader);
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
return request;
}
示例10: testCanHandleWithRequireParameters
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
@Test(description = "This method tests the canHandle method when all the required parameters are given with the "
+ "request", dependsOnMethods = {"testCanHandleWithoutRequireParameters"})
public void testCanHandleWithRequireParameters() throws IllegalAccessException {
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);
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
Assert.assertTrue(basicAuthAuthenticator.canHandle(request),
"Basic Authenticator cannot handle a request with all the required headers and parameters.");
}
示例11: createRequest
import org.apache.tomcat.util.http.MimeHeaders; //导入方法依赖的package包/类
/**
* To create a request that can be understandable by Certificate Authenticator.
*
* @param headerName Name of the header
* @param value Value for the header
* @return Request that is created.
* @throws IllegalAccessException Illegal Access Exception.
* @throws NoSuchFieldException No Such Field Exception.
*/
private Request createRequest(String headerName, String value) throws IllegalAccessException, NoSuchFieldException {
Request request = new Request();
Context context = new StandardContext();
request.setContext(context);
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
MimeHeaders mimeHeaders = new MimeHeaders();
MessageBytes bytes = mimeHeaders.addValue(headerName);
bytes.setString(value);
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
return request;
}