cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any method to get the HTTP status code programmtically through java?

Highlighted
New Contributor

Is there any method to get the HTTP status code programmtically through java?

Hi All,

 

I have created a recipe in Java to submit a REST request and added assertion to it. I am also getting the response back and assertion status, if it is failed or passed.

 

Is there any way I can get the actual HTTP status code received?

 

Code snippet:

 

TestRecipe recipe = newTestRecipe().addStep(
    getRequest(uri)
    .assertContains(assertValue)
   ).buildTestRecipe();

 

Execution execution = executor.executeRecipe(recipe);
ProjectResultReport projectResultReport= execution.getCurrentReport();
RecipeExecutionResult result = execution.getExecutionResult();
String response = result.getTestStepResult(0).getResponseContent();
result.getTestStepResult(0).getAssertionStatus();

 

 

Thanks,

Anuj

2 REPLIES 2
Highlighted
Super Contributor

Re: Is there any method to get the HTTP status code programmtically through java?

The Ready API REST test step result is an object of class RestRequestStepResult, the following should get what you are after:

 

result.getTestStepResult(0).getResponse().getStatusCode()
Highlighted
Community Hero

Re: Is there any method to get the HTTP status code programmtically through java?

This forum is for ReadyAPI questions. If you are using purely java, then this isn't the right place for this question.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 12
2 nmrao 8
3 HimanshuTayal 3