0
votes

I am using JMeter to run some web service tests and here is my problem:

  1. Here is my test structure:
> Threadgroup
>         -User Defined Variables
>         -SOAP/XML-RPC Request1
>            ->Xpath Extractor
>            ->Beanshell PostProcessor
>         -SOAP/XML-RPC Request2
>             ->HTTP Authorization manager
>             ->Beanshell PreProcessor
>         -Debug Sampler
>       View Results Tree
  1. The Xpath Extractor processes Request1 results to extract a password and the Beanshell PostProcessor stores it in a User Defined Variable "Authorization".

  2. The Beanshell PreProcessor extracts the password from the variable, sets it with a user in the authorization manager.

AuthManager authmanager = sampler.getAuthManager();
Authorization authorization = new Authorization();
authorization.setURL("http://localhost:1130");
authorization.setUser("user"); 
authorization.setPass(vars.get("Authorization"));
authorization.setRealm("gSOAP Web Service");
authmanager.addAuth(authorization);

Everything works perfectly until I need to loop the group thread. The first loop works fine but the rest of the execution fails. It seems as if on the second round the Authorization Manager is not updated with new credentials which causes the following requests to fail.

I tried clearing the Authorization manager before creating the new authorization but it's not working.

Help!!

1

1 Answers

1
votes

addAuth method (as can be seeing in code) will only add an Authorization object if it doesn't yet exist. So before adding the object for the second time you have to remove it, something like this:

AuthManager authmanager = sampler.getAuthManager();
// ... (same as before)
authorization.setRealm("gSOAP Web Service");
for (int i = 0; i < authmanager.getAuthCount(); i++) {
        Authorization oldAuthorization = authmanager.get(i);
        if (oldAuthorization == null) {
            continue;
        }
        if (oldAuthorization.getURL().equals(authorization.getURL())) { 
            authmanager.remove(i);
        }
}
authmanager.addAuth(authorization);