getHeaders(Environment env, HttpServletRequest
/**
* Utility method for extracting the Proxy Headers for a request.
- *
+ *
* The configuration option '{key}.proxyHeaders' is used to specify a multi-valued list of HTTP headers to add to the
- * outbound request to '{key}.uri'.
- *
+ * outbound request to '{key}.uri'.
+ *
* Example:
*
someservice.proxyHeaders=On-Behalf-Of: {wiscedupvi},Some-Other-Header: staticvalue
- *
- * Implementers can specify either static values ('Some-Other-Header: staticvalue') or use placeholders to relay
+ *
+ * Implementers can specify either static values ('Some-Other-Header: staticvalue') or use placeholders to relay
* {@link HttpServletRequest#getAttribute(String)} values ('On-Behalf-Of: {wiscedupvi}')
- *
+ *
* @param env
* @param resourceKey
* @param request
diff --git a/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/ProxyRequestContext.groovy b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/ProxyRequestContext.groovy
new file mode 100644
index 0000000..dc13b5e
--- /dev/null
+++ b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/ProxyRequestContext.groovy
@@ -0,0 +1,46 @@
+package edu.wisc.my.restproxy
+
+import groovy.transform.Canonical;
+import groovy.transform.CompileStatic
+import groovy.transform.builder.Builder
+import groovy.transform.builder.SimpleStrategy;
+import org.springframework.http.HttpMethod;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
+/**
+ * Java Bean representing all of the context about a REST Request this library is proxying.
+ *
+ * @author Nicholas Blair
+ */
+@Builder(builderStrategy = SimpleStrategy)
+@Canonical
+@CompileStatic
+public class ProxyRequestContext {
+
+ final String resourceKey;
+ HttpMethod httpMethod = HttpMethod.GET;
+ String uri;
+ String username;
+ String password;
+ Map attributes = new HashMap<>();
+ Multimap headers = ArrayListMultimap.create();
+ RequestBody requestBody;
+
+ /**
+ *
+ * @param resourceKey required
+ */
+ public ProxyRequestContext(String resourceKey) {
+ this.resourceKey = resourceKey;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "ProxyRequestContext [resourceKey=${resourceKey}, httpMethod=${httpMethod}, uri=${uri}, username=${username}, password=${password != null ? '' : 'empty'}, attributes=${attributes}, headers=${headers}]"
+ }
+
+}
diff --git a/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/RequestBody.groovy b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/RequestBody.groovy
new file mode 100644
index 0000000..5b1c09d
--- /dev/null
+++ b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/RequestBody.groovy
@@ -0,0 +1,16 @@
+package edu.wisc.my.restproxy
+
+import groovy.transform.Canonical
+import groovy.transform.CompileStatic
+import groovy.transform.builder.Builder
+import groovy.transform.builder.SimpleStrategy;
+
+@Builder(builderStrategy = SimpleStrategy)
+@Canonical
+@CompileStatic
+public class RequestBody {
+
+ byte[] body;
+ String contentType;
+
+}
diff --git a/src/main/java/edu/wisc/my/restproxy/config/RestProxyConfiguration.java b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/config/RestProxyConfiguration.groovy
similarity index 72%
rename from src/main/java/edu/wisc/my/restproxy/config/RestProxyConfiguration.java
rename to rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/config/RestProxyConfiguration.groovy
index 11b5576..a4fcf7f 100644
--- a/src/main/java/edu/wisc/my/restproxy/config/RestProxyConfiguration.java
+++ b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/config/RestProxyConfiguration.groovy
@@ -1,22 +1,21 @@
-/**
- *
- */
-package edu.wisc.my.restproxy.config;
+package edu.wisc.my.restproxy.config
+import groovy.transform.CompileStatic;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* {@link Configuration} activating necessary REST proxy services.
- *
+ *
* To use this class, simply {@link Import} it with the rest of your configuration.
* It's strongly suggested that your configuration provide a {@link org.springframework.web.client.RestTemplate} bean, but not required.
- *
+ *
* @author Nicholas Blair
*/
+@CompileStatic
+@ComponentScan(value = ["edu.wisc.my.restproxy.dao", "edu.wisc.my.restproxy.service", "edu.wisc.my.restproxy.web"])
@Configuration
-@ComponentScan(value = {"edu.wisc.my.restproxy.dao", "edu.wisc.my.restproxy.service", "edu.wisc.my.restproxy.web" })
public class RestProxyConfiguration {
}
diff --git a/src/main/java/edu/wisc/my/restproxy/dao/RestProxyDao.java b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/dao/RestProxyDao.groovy
similarity index 82%
rename from src/main/java/edu/wisc/my/restproxy/dao/RestProxyDao.java
rename to rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/dao/RestProxyDao.groovy
index 7d56ff2..ead6971 100644
--- a/src/main/java/edu/wisc/my/restproxy/dao/RestProxyDao.java
+++ b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/dao/RestProxyDao.groovy
@@ -1,17 +1,16 @@
-/**
- *
- */
-package edu.wisc.my.restproxy.dao;
+package edu.wisc.my.restproxy.dao
+import groovy.transform.CompileStatic;
import org.springframework.http.ResponseEntity;
import edu.wisc.my.restproxy.ProxyRequestContext;
/**
* Data access interface for talking with a REST API.
- *
+ *
* @author Nicholas Blair
*/
+@CompileStatic
public interface RestProxyDao {
/**
diff --git a/src/main/java/edu/wisc/my/restproxy/dao/RestProxyDaoImpl.java b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/dao/RestProxyDaoImpl.groovy
similarity index 98%
rename from src/main/java/edu/wisc/my/restproxy/dao/RestProxyDaoImpl.java
rename to rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/dao/RestProxyDaoImpl.groovy
index 5c87575..a0d80ee 100644
--- a/src/main/java/edu/wisc/my/restproxy/dao/RestProxyDaoImpl.java
+++ b/rest-proxy-core/src/main/groovy/edu/wisc/my/restproxy/dao/RestProxyDaoImpl.groovy
@@ -1,6 +1,3 @@
-/**
- *
- */
package edu.wisc.my.restproxy.dao;
import java.util.Map.Entry;
@@ -21,20 +18,20 @@
/**
* {@link RestProxyDao} implementation backed by a {@link RestTemplate}.
- *
+ *
* A default {@link RestTemplate} instance is provided, but consumers are strongly recommended to
* configure their own instance and inject. However, this class will always use
* {@link RestProxyResponseErrorHandler} because it's the client's responsiblity to deal with
* errors.
- *
+ *
* @author Nicholas Blair
*/
@Service
public class RestProxyDaoImpl implements RestProxyDao, InitializingBean {
-
+
@Autowired(required=false)
private RestTemplate restTemplate = new RestTemplate();
-
+
/* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@@ -42,7 +39,7 @@ public class RestProxyDaoImpl implements RestProxyDao, InitializingBean {
public void afterPropertiesSet() throws Exception {
this.restTemplate.setErrorHandler(new RestProxyResponseErrorHandler());
};
-
+
private static final Logger logger = LoggerFactory.getLogger(RestProxyDaoImpl.class);
/* (non-Javadoc)
* @see edu.wisc.my.restproxy.dao.RestProxyDao#proxyRequest(edu.wisc.my.restproxy.ProxyRequestContext)
@@ -59,13 +56,13 @@ public ResponseEntity