/**
 * 
 */
package edu.wisc.my.restproxy.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import edu.wisc.my.restproxy.service.RestProxyService;

/**
 * {@link RestController} for proxying other REST resources.
 * 
 * @author Nicholas Blair
 */
@Controller
public class ResourceProxyController {

  @Autowired
  private RestProxyService proxyService;
  @Autowired
  private Environment env;

  /**
   * @param env the env to set
   */
  void setEnv(Environment env) {
    this.env = env;
  }
  /**
   * 
   */
  @RequestMapping("/{key}/**")
  public  @ResponseBody Object proxyResource(HttpServletRequest request, 
      HttpServletResponse response,
      @PathVariable String key) {
    ResponseEntity<Object> responseEntity = proxyService.proxyRequest(key, request);   
    if(responseEntity != null) {
      HttpStatus statusCode = responseEntity.getStatusCode();
      response.setStatus(statusCode.value());
      if(responseEntity.hasBody()) {
        return responseEntity.getBody();
      }
    }else {
      response.setStatus(HttpStatus.NOT_FOUND.value());
    }
    return null;    
  }
}

@@ -1040,16 +1040,17 @@
 nv;%0A  %7D%0A
+%0A
   /**%0A  
@@ -1052,16 +1052,344 @@
 **%0A   * 
+Proxies the request and then calls %7B@link HttpServletResponse#setStatus(int)%7D with the%0A   * %7B@link HttpStatus%7D recieved. If the proxy response contains content it's simply returned here%0A   * as an %7B@link Object%7D.%0A   * %0A   * @param request%0A   * @param response%0A   * @param key%0A   * @return the body of the proxy response or null.
 %0A   */%0A 
@@ -1676,48 +1676,18 @@
 ity 
-!
+=
 = null
-) %7B%0A      HttpStatus statusCode =
+ %7C%7C
  res
@@ -1713,17 +1713,27 @@
 usCode()
-;
+ == null) %7B
 %0A      r
@@ -1754,37 +1754,86 @@
 tus(
-statusCode.value());%0A      if
+HttpStatus.NOT_FOUND.value());%0A      return null;%0A    %7D%0A    response.setStatus
 (res
@@ -1848,25 +1848,34 @@
 ity.
-hasBody()) %7B%0A    
+getStatusCode().value());%0A
     
@@ -1900,119 +1900,54 @@
 ity.
-get
+has
 Body()
-;%0A      %7D%0A    %7Delse %7B%0A      response.setStatus(HttpStatus.NOT_FOUND.value());%0A    %7D%0A    return
+ ? responseEntity.getBody() :
  null;  
   %0A 
@@ -1942,17 +1942,15 @@
  null;  
-  
 %0A  %7D%0A%7D%0A

Add some docs + minor refactor