Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Custom status code is not showing and always shows 200 OK.

Hi,

i have a scenario where i need to validate account ID and display error message as "Invalid account ID" if account ID is invalid. I am able to validate and display message but i am not able to display my custom status code as 400. It always shows 200 OK. Can you help me on what changes i need to make this work? Thank You and looking for solution.

  1. Data without dates is working.
  2. Data with date is working but not showing custom status code as 400. Always shows default as 200 OK.
Tagged:

Comments

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    The status code is controller by the option in "Return Status" in the "Options" tab. You should have a responder for each status code and correlation condition combination.

  • Thank You. I have custom values as 400 - Bad Request under "Return Status" in the "Options" tab but it is not showing that. It always shows 200 with OK only.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    Double check your correlations and make sure that the expected responder is matching. Also check the order of your responders as we saw in the other case you had that the first one to match will reply.

  • Thank You. I have checked them and i don't see any differences in the responders except parameters.

  • I have the logic in the assets where we are validating account ID. I have created responder but my logic is in the assets are always executing so i am not seeing status code changing. Do we have any other way we can handle this through responder? I cannot move the logic from assets so looking for alternate.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    I am not sure why the logic could not be moved from, I am guessing you mean the "Response" tab, into a correlation. The custom correlation should have access to all the same data as is in the "Response" tab. The other way to do it would be to chain an extension tool to the responder and data bank the status code. The return status could then be set to "parameterized" to used the data banked status code.

  • Thank You for response. I am not sure how i can do the "chain an extension tool to the responder and data bank the status code". Do you mean to copy the logic into responder or is there a way to attach them together?

  • Thank You. I am new to the Parasoft and trying to understand the functionality. Thank you for helping me.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Glad to help!

  • I have a responder for invalid accountID but my responder never executes as we have groovy code in the asset that is throwing same error message based on the condition. Can we also include handling status messages and code in groovy and any example will help please?

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    Do you mean the http return status code and status message? I don't know of a why to set those using scripting.

  • Thank You. Yes. looking to see if i can do that through groovy? Currently we have a code that validates accountID and throws error message as "invalid Account". My responder also have same message with bad request and 400 but this is never executes because other script is executing all the time. I Tried with different options but other script executes and shows 200 OK only.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    The best course is to setup correlations that match each case that have the response status code and status message preconfigured. When you say other script executes and returns 200 OK does that mean you need to reorder your responders?

    For example would having your responder that is the error case first work?

  • Thank You. I tried with reordering my responder but i always see the message from other script with 200 OK. I tried below reordering but nothing works.

    Responder01 with validating account ID and throws error message "invalid Account".
    Responder02 do not have logic for validating accountID but have setup with 4 parameters and custom message/code.

    We don't want to remove logic from Responder01 because it is having other rules in it. I only need to change the status code and status based on the error message. I am confused how to handle this kind of scenario.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    The way to handle it is with separate message responders. It sounds like in your case the error responders correlation is not matching when it should. The fact that if it is the first responder but the second responder is being picked means matching failed. One way to get more information about why a responder didn't match is to disable all other responders in the asset. Then send your message, it should response with some details about what correlations did and did not match.

  • Thank You. I disabled other responders and tried to run again. i can only see the responder which have logic is running all the time. i compared both the responders and i did not see any difference except login in the first responder.

  • When i look at the log it always, it always shows first responder.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    If there is only one responder and it's correlation does not match you should see a message returned in the response that indicates why it did not match.

  • I don't see any message saying why it did not match. I am also not seeing my responder in event log. it is only showing responder that has a code for error.

    responder1 with code for error message.

    responder2 without code with custom status code and status message.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    Make sure all other responders are disabled. The message will be in the response payload it may not be in the event details because nothing matched. This sounds like a problem with your specific correlation condition not matching when sending the error case. You will have to debug your correlation condition to figure out why it's not matching. The message in the response when there is only a single responder and no responders match will give some more clues.

  • My responder and other responder both are identical except logic code.

    1. Responder0 - have 4 parameters and logic code.
      2.Responder1 - have 4 parameters and without logic code.

    Default responder always executes because it satisfies with invalid account ID. It is not even coming to Responder1. Can i do this using groovy code?

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    The way that a matching responder is found is by going through them in order from 1 to N, e.g 1, 2, 3, 4, etc. The first responder with a correlation that matches will be used to send the response.

    It sounds like in your case the correlation you have setup on the first responder is not matching. What makes an account ID invalid? What correlations have you tried setting up for an invalid account ID? You may need to use a custom correlation (groovy script) for an invalid account ID if it is something not covered by built in functionality.

  • Thank You.

    Responder0 - have 4 parameters and logic code. [here i am having groovy script that validates accountID and throws error message as "invalid ID".

    2.Responder1 - have 4 parameters and without logic code. [here i don't have any code to validate so it always satisfy the first responder0.

    Note: I have created Responder1 and Responder0 is already there so with logic in it.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    When you say that the first responder has a groovy script that valises and throws an error message, do you mean the script throws an exception? If that is that case that is possibly the cause of the issue. Custom correlation scripts are expected to return either true if the match of false if they do not. Throwing an exception will most likely cause the responder to be skipped.

  • Thank You. No. It is not throwing any exceptions. It is doing what it is intended for throwing error if invalid id is passed.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    From everything you have shared the issue sounds like the custom correlation script is not matching in a case you expect it to match. You need to debug the script. Two ways of getting information about what is happening is using event monitoring and there other I described is disabling all other responders so that a correlation failure detail message will be return in the response to the client.

    Without being able to see how the asset is configured and having an example request which is invalid I can't do much more.

  • Thank You. I will try again and see if i can be successful. Not sure why i am not able to make it work, Every thing looks ok from both responders.

  • Thank You again for helping. I want to throw status codes through Groovy script? How can we achieve that?

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    I am attaching an example that sets a status code for the error case when date is missing and a different status code for when the date is not in a valid range. I did this by setting a context value during correlation and then in another extension tool I get those values and create xml so that I can put them into an XML Data Bank. Then in the return status I can parameterize the response code and message.