22014Dec

Solved : HTTP 302 – ATG Rest MVC Response

ATG REST MVC framework leverages existing Droplets, Form handlers and Components. As REST MVC uses the form handler in web service call, form handler internally redirects to either Success Url or Error Url. So due to this every time we invoke any actor that uses form handler always give HTTP 302 Moved Permanently because internal redirection happens on success and error pages.

Example
  <actor-chain id="login" transaction="TX_SUPPORTS">
    <form id="profileFormHandler-login" name="/atg/userprofiling/ProfileFormHandler"  handle="login" var="profileFormHandler">
      <input name="value.login" value="${param.login}" />
      <input name="value.password" value="${param.password}" />
      <input name="loginErrorURL" value="/rest/model/atg/userprofiling/ProfileActor/login-error"/>
      <input name="loginSuccessURL" value="/rest/model/atg/userprofiling/ProfileActor/login-success"/>
    </form>
  </actor-chain>
  <actor-chain id="login-error" transaction="TX_SUPPORTS">
    <actor id="error" name="/atg/userprofiling/ProfileActor" chain-id="error" return-model-var="model">
      <output id="model" add-map-children="true" value="${model}"/>
    </actor>
  </actor-chain>
  <actor-chain id="login-success" transaction="TX_SUPPORTS">
  </actor-chain>

Like in above login call if login is successful the it is redirecting to /rest/model/atg/userprofiling/ProfileActor/login-success actor chain and if there is an error then it redirects to /rest/model/atg/userprofiling/ProfileActor/login-error actor chain.

So whenerver the redirection occurs in HTTP call we will get HTTP 302 Moved Permanently but as we want to get login exceptions or login success messages we have to follow the redirection.

In my case I am using Apache HTTP Client for calling ATG REST MVC. Apache Http client provides LaxRedirectStrategy that automatically redirects all HEAD, GET and POST requests and relaxes restrictions on automatic redirection of POST methods imposed by the HTTP specification. Use this to create HTTp Client…

CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();

After using this we will always get the response from the actor which is lastly invoked.