Skip to content
Browse files

Added in the ability to set proxy headers inside the definition of en…

…dpoints.
  • Loading branch information...
1 parent 3c58653 commit 33157f2a9d02e68dd45c834455236e6a016d731e @ieb ieb committed
View
4 ...nel/bundles/proxy/src/main/java/org/sakaiproject/kernel/api/proxy/ProxyClientService.java
@@ -51,6 +51,10 @@
*/
public static final String SAKAI_PROXY_REQUEST_TEMPLATE = "sakai:proxy-request-template";
+ /**
+ * A multi value property containing a list of headers to add to the request.
+ */
+ public static final String SAKAI_PROXY_HEADER = "sakai:proxy-header";
/**
* Executes a HTTP call using a path in the JCR to point to a template and a map of
View
10 ...nel/bundles/proxy/src/main/java/org/sakaiproject/kernel/proxy/ProxyClientServiceImpl.java
@@ -46,6 +46,7 @@
import org.sakaiproject.kernel.proxy.velocity.JcrResourceLoader;
import org.sakaiproject.kernel.proxy.velocity.VelocityLogger;
import org.sakaiproject.kernel.util.JcrUtils;
+import org.sakaiproject.kernel.util.StringUtils;
import java.io.InputStream;
import java.io.Reader;
@@ -55,6 +56,7 @@
import java.util.Map.Entry;
import javax.jcr.Node;
+import javax.jcr.Value;
/**
*
@@ -63,6 +65,7 @@
@Component(immediate = true)
public class ProxyClientServiceImpl implements ProxyClientService, ProxyNodeSource {
+
/**
*
*/
@@ -246,6 +249,13 @@ public ProxyResponse executeCall(Node node, Map<String, String> headers,
for (Entry<String, String> header : headers.entrySet()) {
method.addRequestHeader(header.getKey(), header.getValue());
}
+
+ Value[] additionalHeaders = JcrUtils.getValues(node, SAKAI_PROXY_HEADER);
+ for ( Value v : additionalHeaders ) {
+ String header = v.getString();
+ String[] keyVal = StringUtils.split(header, ':', 2);
+ method.addRequestHeader(keyVal[0].trim(), keyVal[1].trim());
+ }
if (method instanceof EntityEnclosingMethod) {
String contentType = requestContentType;
View
9 ...bundles/proxy/src/test/java/org/sakaiproject/kernel/proxy/ProxyClientServiceImplTest.java
@@ -186,6 +186,8 @@ public void testInvokeServiceNodeEndPoint() throws ProxyClientException,
true).atLeastOnce();
expect(node.getProperty(ProxyClientService.SAKAI_PROXY_REQUEST_TEMPLATE)).andReturn(
templateProperty).atLeastOnce();
+ expect(node.hasProperty(ProxyClientService.SAKAI_PROXY_HEADER)).andReturn(
+ false).atLeastOnce();
expect(templateProperty.getValue()).andReturn(value);
expect(templateProperty.getDefinition()).andReturn(propertyDefinition);
@@ -246,6 +248,9 @@ public void testInvokeServiceNodeEndPointPut() throws ProxyClientException,
expect(value.getString()).andReturn(dummyServer.getUrl());
+ expect(node.hasProperty(ProxyClientService.SAKAI_PROXY_HEADER)).andReturn(
+ false).atLeastOnce();
+
expect(node.hasProperty(ProxyClientService.SAKAI_REQUEST_PROXY_METHOD)).andReturn(
true);
@@ -320,7 +325,9 @@ private void testRequest(String type, String expectedMethod, String body)
expect(node.getProperty(ProxyClientService.SAKAI_REQUEST_PROXY_ENDPOINT)).andReturn(
endpointProperty);
-
+ expect(node.hasProperty(ProxyClientService.SAKAI_PROXY_HEADER)).andReturn(
+ false).atLeastOnce();
+
expect(endpointProperty.getDefinition()).andReturn(propertyDefinition);
expect(propertyDefinition.isMultiple()).andReturn(false).atLeastOnce();
expect(endpointProperty.getValue()).andReturn(value);

0 comments on commit 33157f2

Please sign in to comment.
Something went wrong with that request. Please try again.