Commit 7f0c0cff authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

enhance proxy resource

parent bd7b5a7e
...@@ -8,6 +8,7 @@ import org.apache.http.impl.client.HttpClients; ...@@ -8,6 +8,7 @@ import org.apache.http.impl.client.HttpClients;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.io.IOException; import java.io.IOException;
...@@ -16,15 +17,17 @@ import java.io.InputStream; ...@@ -16,15 +17,17 @@ import java.io.InputStream;
/** /**
* Created by gpietrus on 16.02.16. * Created by gpietrus on 16.02.16.
*/ */
@Path(value = "/proxy") @Path(value = "/proxy/task")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class ProxyResource public class ProxyResource
{ {
@GET @GET
@Path("{task_id}/{path: .*}")
@Produces("text/html; charset=UTF-8") @Produces("text/html; charset=UTF-8")
public InputStream foo() throws IOException { public InputStream foo(final @PathParam("task_id") String taskId,
final @PathParam("path") String path) throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://onet.pl"); HttpGet httpget = new HttpGet("https://pl.wikipedia.org/" + taskId + "/" + path);
CloseableHttpResponse execute = httpClient.execute(httpget); CloseableHttpResponse execute = httpClient.execute(httpget);
HttpEntity entity = execute.getEntity(); HttpEntity entity = execute.getEntity();
return entity.getContent(); return entity.getContent();
......
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