Forschungssoftware will stop it's service on 25.05.2018 due to the new EU regulations. Please make sure you backup your projects!

Commit 82a6cfd7 by Christian Bürckert

make crossorigin possible

parent 757bb63a
......@@ -40,6 +40,7 @@ public abstract class AbstractHandler implements HttpRequestHandler {
*
*/
protected final String target;
private boolean allowCrossOriginHeader = false;
/**
*
......@@ -49,6 +50,11 @@ public abstract class AbstractHandler implements HttpRequestHandler {
this.target = target;
}
public AbstractHandler allowCrossOrigin(boolean allowCrossOriginHeader) {
this.allowCrossOriginHeader = allowCrossOriginHeader;
return this;
}
/**
*
* @return
......@@ -59,6 +65,9 @@ public abstract class AbstractHandler implements HttpRequestHandler {
@Override
public final void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) {
if (allowCrossOriginHeader) {
response.setHeader("Access-Control-Allow-Origin", "*");
}
try {
String requestTarget = URLDecoder.decode(request.getRequestLine().getUri(), "UTF8");
if (!requestTarget.startsWith(target)) {
......
......@@ -53,7 +53,7 @@ public class ThriftServiceHandler<P extends TProcessor> extends AbstractHandler
super(target);
this.processor = processor;
}
/**
*
* @param subtarget
......@@ -65,6 +65,7 @@ public class ThriftServiceHandler<P extends TProcessor> extends AbstractHandler
@Override
public void handle(String subtarget, HttpRequest request, HttpResponse response, HttpContext context) throws Exception {
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
byte[] entityContent = EntityUtils.toByteArray(entity);
final String output = this.thriftRequest(entityContent);
......@@ -78,6 +79,7 @@ public class ThriftServiceHandler<P extends TProcessor> extends AbstractHandler
});
body.setContentType("text/html; charset=UTF-8");
response.setEntity(body);
} else {
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
......
......@@ -48,7 +48,7 @@ public class ThriftWebservice {
private final ArrayList<AbstractHandler> handlers = new ArrayList<AbstractHandler>();
private Thread daemon;
private boolean allowCrossOrigin = false;
/**
*
......@@ -56,6 +56,7 @@ public class ThriftWebservice {
public ThriftWebservice() {
}
/**
*
* @param handler
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment