use of org.apache.jmeter.protocol.http.control.HeaderManager in project jmeter by apache.
the class ProxyControl method createAuthorization.
/**
* Detect Header manager in subConfigs,
* Find(if any) Authorization header
* Construct Authentication object
* Removes Authorization if present
*
* @param subConfigs {@link TestElement}[]
* @param sampler {@link HTTPSamplerBase}
* @return {@link Authorization}
*/
private Authorization createAuthorization(final TestElement[] testElements, HTTPSamplerBase sampler) {
Header authHeader;
Authorization authorization = null;
// Iterate over subconfig elements searching for HeaderManager
for (TestElement te : testElements) {
if (te instanceof HeaderManager) {
// headers should only contain the correct classes
@SuppressWarnings("unchecked") List<TestElementProperty> headers = (ArrayList<TestElementProperty>) ((HeaderManager) te).getHeaders().getObjectValue();
for (Iterator<?> iterator = headers.iterator(); iterator.hasNext(); ) {
TestElementProperty tep = (TestElementProperty) iterator.next();
if (tep.getName().equals(HTTPConstants.HEADER_AUTHORIZATION)) {
//Construct Authorization object from HEADER_AUTHORIZATION
authHeader = (Header) tep.getObjectValue();
//$NON-NLS-1$
String[] authHeaderContent = authHeader.getValue().split(" ");
String authType;
String authCredentialsBase64;
if (authHeaderContent.length >= 2) {
authType = authHeaderContent[0];
authCredentialsBase64 = authHeaderContent[1];
authorization = new Authorization();
try {
authorization.setURL(sampler.getUrl().toExternalForm());
} catch (MalformedURLException e) {
log.error("Error filling url on authorization, message:" + e.getMessage(), e);
//$NON-NLS-1$
authorization.setURL("${AUTH_BASE_URL}");
}
// if HEADER_AUTHORIZATION contains "Basic"
// then set Mechanism.BASIC_DIGEST, otherwise Mechanism.KERBEROS
authorization.setMechanism(authType.equals(BASIC_AUTH) || authType.equals(DIGEST_AUTH) ? AuthManager.Mechanism.BASIC_DIGEST : AuthManager.Mechanism.KERBEROS);
if (BASIC_AUTH.equals(authType)) {
String authCred = new String(Base64.decodeBase64(authCredentialsBase64));
//$NON-NLS-1$
String[] loginPassword = authCred.split(":");
authorization.setUser(loginPassword[0]);
authorization.setPass(loginPassword[1]);
} else {
// Digest or Kerberos
//$NON-NLS-1$
authorization.setUser("${AUTH_LOGIN}");
//$NON-NLS-1$
authorization.setPass("${AUTH_PASSWORD}");
}
}
// remove HEADER_AUTHORIZATION from HeaderManager
// because it's useless after creating Authorization object
iterator.remove();
}
}
}
}
return authorization;
}
use of org.apache.jmeter.protocol.http.control.HeaderManager in project jmeter by apache.
the class HttpRequestHdr method createHeaderManager.
private HeaderManager createHeaderManager() {
HeaderManager manager = new HeaderManager();
for (Map.Entry<String, Header> entry : headers.entrySet()) {
final String key = entry.getKey();
if (!key.equals(PROXY_CONNECTION) && !key.equals(CONTENT_LENGTH) && !key.equalsIgnoreCase(HTTPConstants.HEADER_CONNECTION)) {
manager.add(entry.getValue());
}
}
// $NON-NLS-1$
manager.setName(JMeterUtils.getResString("header_manager_title"));
manager.setProperty(TestElement.TEST_CLASS, HeaderManager.class.getName());
manager.setProperty(TestElement.GUI_CLASS, HeaderPanel.class.getName());
return manager;
}
use of org.apache.jmeter.protocol.http.control.HeaderManager in project jmeter by apache.
the class HTTPSamplerBase method setHeaderManager.
public void setHeaderManager(final HeaderManager value) {
HeaderManager mgr = getHeaderManager();
HeaderManager lValue = value;
if (mgr != null) {
lValue = mgr.merge(value);
if (log.isDebugEnabled()) {
log.debug("Existing HeaderManager '" + mgr.getName() + "' merged with '" + lValue.getName() + "'");
for (int i = 0; i < lValue.getHeaders().size(); i++) {
log.debug(" " + lValue.getHeader(i).getName() + "=" + lValue.getHeader(i).getValue());
}
}
}
setProperty(new TestElementProperty(HEADER_MANAGER, lValue));
}
use of org.apache.jmeter.protocol.http.control.HeaderManager in project jmeter by apache.
the class TestHttpRequestHdr method testParse1.
@Test
public void testParse1() throws Exception {
// no space after :
HttpRequestHdr req = new HttpRequestHdr();
ByteArrayInputStream bis = null;
bis = new ByteArrayInputStream("GET xxx HTTP/1.0\r\nname:value \r\n".getBytes("ISO-8859-1"));
req.parse(bis);
bis.close();
HeaderManager mgr = req.getHeaderManager();
Header header;
mgr.getHeaders();
header = mgr.getHeader(0);
assertEquals("name", header.getName());
assertEquals("value", header.getValue());
}
use of org.apache.jmeter.protocol.http.control.HeaderManager in project jmeter by apache.
the class TestHttpRequestHdr method testParse2.
@Test
public void testParse2() throws Exception {
// spaces after :
HttpRequestHdr req = new HttpRequestHdr();
ByteArrayInputStream bis = null;
bis = new ByteArrayInputStream("GET xxx HTTP/1.0\r\nname: value \r\n".getBytes("ISO-8859-1"));
req.parse(bis);
bis.close();
HeaderManager mgr = req.getHeaderManager();
Header header;
mgr.getHeaders();
header = mgr.getHeader(0);
assertEquals("name", header.getName());
assertEquals("value", header.getValue());
}
Aggregations