1
|
1 package de.mpiwg.itgroup.diva.rest;
|
|
2
|
|
3 import java.io.PrintWriter;
|
|
4 import java.util.Map;
|
|
5
|
|
6 import javax.servlet.http.HttpServletRequest;
|
|
7 import javax.servlet.http.HttpServletResponse;
|
|
8 import javax.ws.rs.GET;
|
|
9 import javax.ws.rs.Path;
|
|
10 import javax.ws.rs.PathParam;
|
|
11 import javax.ws.rs.Produces;
|
|
12 import javax.ws.rs.QueryParam;
|
|
13 import javax.ws.rs.core.Context;
|
|
14 import javax.ws.rs.core.MediaType;
|
|
15 import javax.ws.rs.core.Response;
|
|
16
|
|
17 import de.mpiwg.itgroup.diva.utils.JSONParam;
|
|
18 import de.mpiwg.itgroup.ismi.utils.HTTPUtils;
|
|
19 import de.mpiwg.itgroup.ismi.utils.HTTPUtils.HttpResponse;
|
|
20 import de.mpiwg.itgroup.ismi.utils.HTTPUtils.HttpStringResponse;
|
|
21
|
|
22 @Path("/diva/proxy")
|
|
23 public class DivaProxy {
|
|
24
|
|
25 private static String IMG_SERVER = "https://images.rasi.mcgill.ca/fcgi-bin/iipsrv.fcgi?FIF=/data7/srv/images/";
|
|
26
|
|
27 @GET
|
|
28 @Path("/image")
|
|
29 @Produces("image/jpeg")
|
|
30 public Response
|
|
31 image(
|
|
32 @QueryParam("f") String f,
|
|
33 @QueryParam("w") String w) throws Exception{
|
|
34
|
|
35 String dirName = getDirName(f);
|
|
36
|
|
37 String url = IMG_SERVER + dirName + "/" + f + "&WID=" + w + "&CVT=JPG";
|
|
38
|
|
39
|
|
40 HttpResponse resp = HTTPUtils.getHttpSSLResponse(url);
|
|
41
|
|
42 if(resp.code == 200){
|
|
43 return Response.ok(resp.content).build();
|
|
44 }
|
|
45
|
|
46 return Response.status(Response.Status.NOT_FOUND).build();
|
|
47 }
|
|
48
|
|
49
|
|
50 @GET
|
|
51 @Path("/json/{file}")
|
|
52 @Produces(MediaType.APPLICATION_JSON)
|
|
53 public Response
|
|
54 json(
|
|
55 @PathParam("file") String file) throws Exception{
|
|
56
|
|
57 HttpStringResponse resp = HTTPUtils.getHttpSSLStringResponse("https://images.rasi.mcgill.ca/data/" + file + ".json");
|
|
58 if(resp.code == 200){
|
|
59 return Response.ok(resp.content).build();
|
|
60 }
|
|
61
|
|
62 return Response.status(Response.Status.NOT_FOUND).build();
|
|
63
|
|
64 }
|
|
65
|
|
66
|
|
67
|
|
68 private String getDirName(String fileName){
|
|
69 String[] array = fileName.split("_");
|
|
70 return fileName.replace("_" + array[array.length-1], "");
|
|
71 }
|
|
72
|
|
73
|
|
74 }
|