Commit 1667b9c3 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

header passing stub

parent e78511c8
......@@ -37,7 +37,7 @@ public abstract class Task
{
}
public abstract String getTextForUser(User user, String path) throws IOException;
public abstract String getTextForUser(User user, String path, String kynHeaderValue) throws IOException;
public String getName()
{
......
......@@ -23,7 +23,7 @@ public class TextTask extends Task
{
}
public String getTextForUser(User user, String path)
public String getTextForUser(User user, String path, String kynHeaderValue)
{
return text;
}
......
......@@ -33,11 +33,11 @@ public class WebTask extends Task
{
}
public String getTextForUser(User user, String path) throws IOException
public String getTextForUser(User user, String path, String kynHeaderValue) throws IOException
{
// String url = URL_JOINER.join(getUrl(), path); //todo: rethink
String url = getUrl() + path;
return StreamUtils.readStream(proxyRequest(url, user));
return StreamUtils.readStream(proxyRequest(url, user, kynHeaderValue));
}
public String getUrl()
......@@ -50,13 +50,15 @@ public class WebTask extends Task
this.url = url;
}
private InputStream proxyRequest(String url, User user) throws IOException
private InputStream proxyRequest(String url, User user, String kynHeaderValue) throws IOException
{
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpget = new HttpGet(url);
httpget.setHeader("CTF-User", user.getName());
httpget.setHeader("CTF-User", user.getName()); //todo: is it necessary?
httpget.setHeader("KYN_2016", kynHeaderValue); //todo: move to configuration
CloseableHttpResponse execute = httpClient.execute(httpget);
HttpEntity entity = execute.getEntity();
return entity.getContent();
//todo: back to user
}
}
......@@ -20,6 +20,8 @@ import java.io.IOException;
@Path(value = "/task")
public class TaskResource
{
private static final String KYN_HEADER_NAME = "KYN_2016"; //todo
private final TasksRepository tasksRepository;
@Inject
......@@ -39,10 +41,11 @@ public class TaskResource
//todo: refactor, path not necessary in textTasks
ContainerRequest context = (ContainerRequest) containerRequestContext;
String query = context.getRequestUri().getQuery();
String kynHeaderValue = context.getHeaderString(KYN_HEADER_NAME);
String fullPath = path;
if(query != null) { //todo: refactor
fullPath = fullPath + "?" + query;
}
return Response.ok().entity(task.getTextForUser(user, fullPath)).build();
return Response.ok().entity(task.getTextForUser(user, fullPath, kynHeaderValue)).build();
}
}
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