New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
local ip address configurable #1291
Comments
Sebb (migrated from Bugzilla): |
Heinrich Soebke (migrated from Bugzilla): |
Heinrich Soebke (migrated from Bugzilla): |
Eric Bloch (migrated from Bugzilla): -Eric |
Sebb (migrated from Bugzilla): Also, note that proxies will present the same IP address to the server even It is wrong to assuming that an IP address is unique to a host - let alone a |
Heinrich Soebke (migrated from Bugzilla): HttpRequest.javaimport java.io.*;
import java.util.*;
import java.net.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class HttpRequest
extends TestProcedure {
public TpHttpRequest()
throws Exception {
}
public TpHttpRequest( String system )
throws Exception {
super( system );
}
// description for testsuite (short)
public String _shortDescription = "TpHttpRequest makes a http request " +
"";
// description for testsuite (long)
public String _detailedDescription = "The class TpHttpRequest makes a " +
"http request and checks the return code.";
public ParamStr _targetIpAddress = new ParamStr("destination ip address", "139.21.93.123");
public ParamStr _targetProtocol = new ParamStr("protocol which is used to connect to the target",
new String[] { "http", "https" });
public ParamStr _targetPort = new ParamStr( " portnumber of target ", "80");
public ParamStr _targetPath = new ParamStr( " url path of target (without leading slash)", "index.html");
public ParamStr _sourceIpAddress = new ParamStr("list of local ip addresses, separated by semicolon or comma", "10.0.0.2,10.0.0.3,10.0.0.4,10.0.0.5,10.0.0.6,10.0.0.7");
InetAddress _sourceIpAddressResolved = null;
private static String className = TpHttpRequest.class.getName();
private Vector _validIpAddresses = null;
/**
* composes the url from the given parameters of the procedure.
* @return complete url
*/
private String getURL() throws Exception {
String result = this._targetProtocol.getSubstitutedStrValue() +
"://" +
this._targetIpAddress.getSubstitutedStrValue() +
":" +
this._targetPort.getSubstitutedStrValue() +
"/" +
this._targetPath.getSubstitutedStrValue();
return result;
}
private int getTargetPort() throws Exception {
String sPort = _targetPort.getSubstitutedStrValue();
int port = Integer.parseInt(sPort);
return port;
}
private HostConfiguration getHostConfiguration(InetAddress pAddress) throws Exception {
HostConfiguration hc = new HostConfiguration();
hc.setHost(this._targetIpAddress.getSubstitutedStrValue(),
getTargetPort(),
this._targetProtocol.getSubstitutedStrValue());
hc.setLocalAddress(pAddress);
return hc;
}
private List getSourceAddresses() throws Exception {
if (_validIpAddresses == null) {
String addresses = _sourceIpAddress.getSubstitutedStrValue();
Vector result = new Vector();
StringTokenizer tokenizer = new StringTokenizer(addresses, ";, ");
while (tokenizer.hasMoreElements()) {
String address = tokenizer.nextToken();
InetAddress ia = null;
try {
ia = InetAddress.getByName(address);
} catch (UnknownHostException e) {
System.out.println( className + ".getSourceAddresses: address not valid: <" + address + ">");
}
if (ia != null) {
result.add(ia);
}
}
_validIpAddresses = result;
}
return _validIpAddresses;
}
public void runTp() throws Exception{
HttpMethod hMethod = new GetMethod();
HttpClient hClient = new HttpClient();
List sourceAddress = getSourceAddresses();
if (sourceAddress.size() == 0) {
_testProcedureResult.failed( "no source addresses available" );
}
Iterator ads = sourceAddress.iterator();
while (ads.hasNext()) {
InetAddress ia = (InetAddress) ads.next();
HostConfiguration hc = getHostConfiguration(ia);
int statusCode = -1;
try {
// We will retry up to 3 times.
for (int attempt = 0; statusCode == -1 && attempt < 3; attempt++) {
try {
hMethod.recycle();
hMethod.setPath(this._targetPath.getValue());
// execute the method.
statusCode = hClient.executeMethod(hc, hMethod);
_testProcedureResult.passed( "TpHttp passed" );
} catch (HttpRecoverableException e) {
System.out.println( className + ".runTp: A recoverable exception occurred, retrying. " + e.getMessage());
}
}
} catch (BindException e) {
_testProcedureResult.failed( "TpHttp: Address not valid " + ia.toString());
} catch (IOException e) {
_testProcedureResult.failed( "TpHttp failed" );
}
}
}
}
|
Heinrich Soebke (migrated from Bugzilla):
|
Sebb (migrated from Bugzilla): It will be in the next release, and in the the nightly from 2-1.20060414 Sorry it has taken so long. Note that it will only work with the Apache HttpClient sampler. |
Heinrich Soebke (Bug 26136):
Sometimes it would be useful, if the ip address of a http request is
configurable (out of set of ip-addresses which are known for this pc).
I didn't find a possibility to do this in JMeter so far.
Votes in Bugzilla: 1
OS: other
The text was updated successfully, but these errors were encountered: