From 755f0e4be3fa559e6f9ae46b1809984ade523089 Mon Sep 17 00:00:00 2001 From: Ziheng Sun Date: Mon, 29 Mar 2021 09:19:08 -0400 Subject: [PATCH 1/2] solve the 415 unsupported media type issue by removing requestentity from the control method input parameters --- .../java/com/gw/GeoweaverApplication.java | 4 +- src/main/java/com/gw/utils/BaseTool.java | 29 ++ .../java/com/gw/web/JupyterController.java | 330 ++++++++++++++++-- 3 files changed, 340 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/gw/GeoweaverApplication.java b/src/main/java/com/gw/GeoweaverApplication.java index 293d05fca..9636fcd4f 100644 --- a/src/main/java/com/gw/GeoweaverApplication.java +++ b/src/main/java/com/gw/GeoweaverApplication.java @@ -18,7 +18,9 @@ public static void main(String[] args) { // BasicConfigurator.configure(); SpringApplication.run(GeoweaverApplication.class, args); - browse("http://localhost:8070/Geoweaver/"); + // browse("http://localhost:8070/Geoweaver/"); + + // openHomePage(); diff --git a/src/main/java/com/gw/utils/BaseTool.java b/src/main/java/com/gw/utils/BaseTool.java index 1ec5a5360..e650f0346 100644 --- a/src/main/java/com/gw/utils/BaseTool.java +++ b/src/main/java/com/gw/utils/BaseTool.java @@ -28,6 +28,8 @@ import java.util.Date; import java.util.List; +import javax.servlet.http.HttpServletRequest; + import org.apache.commons.io.IOUtils; import org.dom4j.Document; import org.dom4j.DocumentHelper; @@ -68,6 +70,33 @@ public BaseTool() { } + + public String getBody(HttpServletRequest req) { + String body = ""; + StringBuilder sb = new StringBuilder(); + BufferedReader bufferedReader = null; + + try { + bufferedReader = req.getReader(); + char[] charBuffer = new char[128]; + int bytesRead; + while ((bytesRead = bufferedReader.read(charBuffer)) != -1) { + sb.append(charBuffer, 0, bytesRead); + } + } catch (IOException ex) { + // swallow silently -- can't get body, won't + } finally { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } catch (IOException ex) { + // swallow silently -- can't get body, won't + } + } + } + body = sb.toString(); + return body; + } /** * Normalize the path diff --git a/src/main/java/com/gw/web/JupyterController.java b/src/main/java/com/gw/web/JupyterController.java index 7f8b5af0d..ec9888299 100644 --- a/src/main/java/com/gw/web/JupyterController.java +++ b/src/main/java/com/gw/web/JupyterController.java @@ -5,6 +5,7 @@ import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.ArrayList; +import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -488,7 +489,7 @@ private HttpHeaders getHeaders(HttpHeaders headers, HttpMethod method, HttpServl * @param hostid * @return */ - private ResponseEntity processPatch(HttpEntity entity, HttpMethod method, HttpServletRequest request, String hostid) { + private ResponseEntity processPatch( HttpMethod method, HttpServletRequest request, String hostid) { // return processUtil(entity, method, request, hostid); @@ -514,9 +515,9 @@ private ResponseEntity processPatch(HttpEntity entity, HttpMethod method, HttpSe // // HttpHeaders newheaders = this.updateHeaderReferer(entity.getHeaders(), h, realurl, request.getQueryString()); - HttpHeaders newheaders = getHeaders(entity.getHeaders(), method, request, hostid); + HttpHeaders newheaders = getHeaders(this.getHeaderByRequest(request), method, request, hostid); - HttpEntity newentity = new HttpEntity(entity.getBody(), newheaders); + HttpEntity newentity = new HttpEntity(bt.getBody(request), newheaders); // logger.debug("URL: " + newheaders.get("referer").get(0)); @@ -555,6 +556,97 @@ private ResponseEntity processPatch(HttpEntity entity, HttpMethod method, HttpSe return resp; } + + /** + * Get headers by request + * @param request + * @return + */ + private HttpHeaders getHeaderByRequest(HttpServletRequest request){ + + HttpHeaders header = new HttpHeaders(); + + Enumeration hearderNames = request.getHeaderNames(); + + while(hearderNames.hasMoreElements()) + { + String headerName = hearderNames.nextElement(); + + header.add(headerName, request.getHeader(headerName)); + + } + + return header; + + } + + /** + * Process PUT request + * @param entity + * @param method + * @param request + * @param hostid + * @return + */ + private ResponseEntity processPut(HttpMethod method, HttpServletRequest request, String hostid) { + + ResponseEntity resp = null; + + try { + + logger.debug("=============="); + + logger.debug("PUT request without httpentity..."); + + logger.debug("Request URI: " + request.getRequestURI()); + +// logger.debug("Query String: " + request.getQueryString()); + +// String body = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8); + + HttpHeaders newheaders = getHeaders(this.getHeaderByRequest(request), method, request, hostid); + + String body = bt.getBody(request); + + HttpEntity newentity = new HttpEntity(body, newheaders); + + ResponseEntity responseEntity = restTemplate.exchange( + getRealTargetURL(newheaders.get("referer").get(0)), + method, newentity, String.class); + + resp = new ResponseEntity( + addURLProxy(responseEntity.getBody(), hostid), + responseEntity.getHeaders(), + responseEntity.getStatusCode()); + + }catch (HttpStatusCodeException ex) { + + // http status code e.g. `404 NOT_FOUND` + logger.error(ex.getStatusCode().toString()); + + // get response body +// System.out.println(ex.getResponseBodyAsString()); + + // get http headers +// HttpHeaders headers = ex.getResponseHeaders(); +// System.out.println(headers.get("Content-Type")); +// System.out.println(headers.get("Server")); + + String newbody = addURLProxy(ex.getResponseBodyAsString(), hostid); + + resp = errorControl(newbody, hostid); + + }catch(Exception e) { + + e.printStackTrace(); + + resp = errorControl(e.getLocalizedMessage(), hostid); + + } + + return resp; + + } /** * Process PUT request @@ -708,6 +800,63 @@ private ResponseEntity processDelete(HttpEntity entity, HttpMethod method, HttpS return resp; } + + /** + * Process POST Request + * @param reqentity + * @param method + * @param request + * @param hostid + * @return + * @throws URISyntaxException + */ + private ResponseEntity processPost_415(HttpMethod method, HttpServletRequest request, String hostid) throws URISyntaxException + { + +// return processUtil(reqentity, method, request, hostid); + + ResponseEntity resp = null; + + try { + + logger.debug("=============="); + + logger.debug("Request URI: " + request.getRequestURI()); + + HttpHeaders newheaders = getHeaders(this.getHeaderByRequest(request), method, request, hostid); + + HttpEntity newentity = new HttpEntity(bt.getBody(request), newheaders); + + String target_url = getRealTargetURL(newheaders.get("target_url").get(0)); + + ResponseEntity responseEntity = restTemplate.exchange(target_url, method, newentity, String.class); + + String newbody = addURLProxy(responseEntity.getBody(), hostid); + + HttpHeaders newrespheaders = updateHeader(responseEntity.getHeaders(), newbody, hostid); + + resp = new ResponseEntity( + newbody, + newrespheaders, + responseEntity.getStatusCode()); + + }catch (HttpStatusCodeException ex) { + + String newbody = addURLProxy(ex.getResponseBodyAsString(), hostid); + + resp = errorControl(newbody, hostid); + + }catch(Exception e) { + + e.printStackTrace(); + + resp = errorControl(e.getLocalizedMessage(), hostid); + + } + + return resp; + + } /** * Process POST Request @@ -796,6 +945,97 @@ private ResponseEntity processPost(RequestEntity reqentity, HttpMethod method, H return resp; } + + private ResponseEntity processGet_415(HttpMethod method, HttpServletRequest request, String hostid) throws URISyntaxException + { + + ResponseEntity resp = null; + + try { + + logger.debug("=============="); + + // logger.debug("This is a GET request..."); + + boolean ishub = false; + + if(request.getRequestURI().contains("user")) ishub = true; + + // if(ishub)logger.info("Old Request HTTP Headers: " + reqentity.getHeaders().toString()); + + HttpHeaders newheaders = getHeaders(this.getHeaderByRequest(request), method, request, hostid); + + HttpEntity newentity = new HttpEntity(bt.getBody(request), newheaders); + + String targeturl = getRealTargetURL(newheaders.get("target_url").get(0)); //using referer as the target url is not right + // String targeturl = getRealTargetURL(reqentity.getUrl().toString()); + + // logger.info("New target url: " + targeturl); + + // if(ishub)logger.info("New Request HTTP Headers: " + newheaders.toString()); + +// String sec_fetch_type = getHeaderProperty(reqentity.getHeaders(), "Sec-Fetch-Dest"); + +// logger.debug(URLDecoder.decode(newheaders.get("referer").get(0),"UTF-8")); + +// ((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(TIMEOUT); + + ResponseEntity responseEntity = restTemplate.exchange(targeturl, method, newentity, byte[].class); + + String contenttype = getHeaderProperty(responseEntity.getHeaders(), "Content-Type"); + + byte[] newbody = null; + + if(!bt.isNull(responseEntity.getBody()) && !targeturl.contains(".png") && !targeturl.contains(".woff") + && !(!bt.isNull(contenttype) && (contenttype.contains("image") || contenttype.contains("font"))) ){ + + newbody = addURLProxy(new String(responseEntity.getBody()), hostid).getBytes(); + + }else{ + + newbody = responseEntity.getBody(); + + } + + // if(ishub) logger.debug("Old Response Header: " + responseEntity.getHeaders().toString()); + + HttpHeaders headers = updateHeader(responseEntity.getHeaders(), newbody, hostid); + + // if(ishub) logger.debug("New Response Header: " + headers.toString()); + + resp = new ResponseEntity( + newbody, + headers, + responseEntity.getStatusCode()); + + }catch (HttpStatusCodeException ex) { + + // http status code e.g. `404 NOT_FOUND` +// logger.error(ex.getStatusCode().toString()); + + // get response body +// System.out.println(ex.getResponseBodyAsString()); + + // get http headers +// HttpHeaders headers = ex.getResponseHeaders(); +// System.out.println(headers.get("Content-Type")); +// System.out.println(headers.get("Server")); + + String newbody = addURLProxy(ex.getResponseBodyAsString(), hostid); + + resp = errorControl(newbody, hostid); + + }catch(Exception e) { + + e.printStackTrace(); + + resp = errorControl(e.getLocalizedMessage(), hostid); + + } + + return resp; + + } /** * Process GET Request @@ -1473,18 +1713,35 @@ public ResponseEntity proxydelete( RequestEntity reqentity, @PathVariable("hosti } - @RequestMapping(value="/jupyter-proxy/{hostid}/**", method = RequestMethod.PATCH, + @RequestMapping(value="/jupyter-proxy/{hostid}/**", + method = RequestMethod.PATCH, + consumes = MediaType.ALL_VALUE, + produces = MediaType.ALL_VALUE) + public ResponseEntity proxypatch( @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException + { + ResponseEntity resp = processPatch(method, request, hostid); + + return resp; + + } + + @RequestMapping(value="/jupyter-proxy/{hostid}/**/lab/api/workspaces/**", + method = RequestMethod.PUT, consumes = MediaType.ALL_VALUE, produces = MediaType.ALL_VALUE) - public ResponseEntity proxypatch( RequestEntity reqentity, @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException + public ResponseEntity proxyput_415( @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException { - ResponseEntity resp = processPatch(reqentity, method, request, hostid); + + logger.info("Proxy Put 415 "); + + ResponseEntity resp = processPut(method, request, hostid); return resp; } - @RequestMapping(value="/jupyter-proxy/{hostid}/**", method = RequestMethod.PUT, + @RequestMapping(value="/jupyter-proxy/{hostid}/**", + method = RequestMethod.PUT, consumes = MediaType.ALL_VALUE, produces = MediaType.ALL_VALUE) public ResponseEntity proxyput( RequestEntity reqentity, @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException @@ -1495,9 +1752,34 @@ public ResponseEntity proxyput( RequestEntity reqentity, @PathVariable("hostid") } - @RequestMapping(value="/jupyter-proxy/{hostid}/**", method = RequestMethod.POST, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) + @RequestMapping(value="/jupyter-proxy/{hostid}/**/api/sessions/**", + method = RequestMethod.GET, + consumes = MediaType.ALL_VALUE, + produces = MediaType.ALL_VALUE) + public ResponseEntity proxyget( @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException + { + ResponseEntity resp = processGet_415(method, request, hostid); + + return resp; + + } + + @RequestMapping(value="/jupyter-proxy/{hostid}/**/api/sessions/**", + method = RequestMethod.POST, + consumes = MediaType.ALL_VALUE, + produces = MediaType.ALL_VALUE) + public ResponseEntity proxypost( @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException + { + ResponseEntity resp = processPost_415(method, request, hostid); + + return resp; + + } + + @RequestMapping(value="/jupyter-proxy/{hostid}/**", + method = RequestMethod.POST, + consumes = MediaType.ALL_VALUE, + produces = MediaType.ALL_VALUE) public ResponseEntity proxypost( RequestEntity reqentity, @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException { ResponseEntity resp = processPost(reqentity, method, request, hostid); @@ -1506,9 +1788,10 @@ public ResponseEntity proxypost( RequestEntity reqentity, @PathVariable("hostid" } - @RequestMapping(value="/jupyter-proxy/{hostid}/**", method = RequestMethod.GET, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) + @RequestMapping(value="/jupyter-proxy/{hostid}/**", + method = RequestMethod.GET, + consumes = MediaType.ALL_VALUE, + produces = MediaType.ALL_VALUE) public ResponseEntity proxyget(RequestEntity reqentity, HttpMethod method, @PathVariable("hostid") String hostid, HttpServletRequest request) throws URISyntaxException { ResponseEntity resp = processGET( reqentity, method, request, hostid); @@ -1517,9 +1800,10 @@ public ResponseEntity proxyget(RequestEntity reqentity, HttpMethod method, @Path } - @RequestMapping(value="/jupyter-proxy/{hostid}", method = RequestMethod.GET, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) + @RequestMapping(value="/jupyter-proxy/{hostid}", + method = RequestMethod.GET, + consumes = MediaType.ALL_VALUE, + produces = MediaType.ALL_VALUE) public ResponseEntity proxyroot_get(HttpMethod method, @PathVariable("hostid") String hostid, RequestEntity reqentity, HttpServletRequest request) throws URISyntaxException { ResponseEntity resp = processGET(reqentity, method, request, hostid); @@ -1544,9 +1828,10 @@ public ResponseEntity proxyroot_get(HttpMethod method, @PathVariable("hostid") S } - @RequestMapping(value = "/jupyter-http", method = RequestMethod.GET, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) + @RequestMapping(value = "/jupyter-http", + method = RequestMethod.GET, + consumes = MediaType.ALL_VALUE, + produces = MediaType.ALL_VALUE) public @ResponseBody String jupyter_http(ModelMap model, WebRequest request){ String resp = null; @@ -1577,9 +1862,10 @@ public ResponseEntity proxyroot_get(HttpMethod method, @PathVariable("hostid") S } - @RequestMapping(value = "/jupyter-https", method = RequestMethod.POST, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) + @RequestMapping(value = "/jupyter-https", + method = RequestMethod.POST, + consumes = MediaType.ALL_VALUE, + produces = MediaType.ALL_VALUE) public @ResponseBody String jupyter_https(ModelMap model, WebRequest request){ String resp = null; From 3b86303c9acb5d4e61853b5dc14da881c05ef55c Mon Sep 17 00:00:00 2001 From: Ziheng Sun Date: Tue, 13 Apr 2021 23:41:57 -0400 Subject: [PATCH 2/2] fix issues with jupyter lab, now websocket, upload, download, rename works with jupyter lab warning: big file downloading and uploading has not been tested yet --- .../gw/server/JupyterLabRedirectServlet.java | 303 ++++++++++++++++++ .../java/com/gw/server/WebSocketConfig.java | 7 + .../java/com/gw/web/JupyterController.java | 71 ++-- 3 files changed, 355 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/gw/server/JupyterLabRedirectServlet.java diff --git a/src/main/java/com/gw/server/JupyterLabRedirectServlet.java b/src/main/java/com/gw/server/JupyterLabRedirectServlet.java new file mode 100644 index 000000000..2e0261753 --- /dev/null +++ b/src/main/java/com/gw/server/JupyterLabRedirectServlet.java @@ -0,0 +1,303 @@ +package com.gw.server; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.websocket.EndpointConfig; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.gw.jpa.Host; +import com.gw.tools.HostTool; +import com.gw.tools.JupyterSessionPairTool; +import com.gw.tools.SessionPair; +import com.gw.utils.BaseTool; +import com.gw.utils.BeanTool; + +/** + * + * This works for redirecting all the jupyter notebook traffic + * + * @author JensenSun + * + */ +//ws://localhost:8080/Geoweaver/jupyter-socket/api/kernels/884447f1-bac6-4913-be86-99da11b2a78a/channels?session_id=42b8261488884e869213604975141d8c + +@ServerEndpoint(value = "/jupyter-proxy/{hostid}/api/kernels/{uuid1}/channels", + configurator = JupyterRedirectServerConfig.class) +public class JupyterLabRedirectServlet { + + Logger logger = LoggerFactory.getLogger(getClass()); + +// Session wsSession; + +// @Autowired +// Java2JupyterClientEndpoint client; + + // public static List pairs = new ArrayList(); + + // @Autowired + HostTool ht; + + // @Autowired + BaseTool bt; + + public JupyterLabRedirectServlet() { + + logger.debug("Initializing Jupyter Lab Websocket Session..."); + + } + + private void init(Session b2gsession) { + + logger.debug("WebSocket ServerEndpoint receives " + b2gsession.getRequestURI().toString()); + + if(ht==null) { + + ht = BeanTool.getBean(HostTool.class); + + } + + if(bt==null) { + + bt = BeanTool.getBean(BaseTool.class); + + } + +// SessionPair pair = findPairBy1stSession(b2gsession); + SessionPair pair = JupyterSessionPairTool.findPairByID(b2gsession.getQueryString()); + + if(bt.isNull(pair)) { + + Java2JupyterClientEndpoint client = BeanTool.getBean(Java2JupyterClientEndpoint.class); + + pair = new SessionPair(); + + pair.setId(b2gsession.getQueryString()); + + pair.setBrowse_geoweaver_session(b2gsession); + + pair.setGeoweaver_jupyter_client(client); + + JupyterSessionPairTool.pairs.add(pair); + + logger.debug("New Pair is created: ID: " + pair.getId()); + + }else { + + logger.debug("A pair is found, no need to create new one: " + pair.getId()); + + } + + + } + +// private HttpSession httpSession; + + @OnOpen + public void open(Session session, @PathParam("hostid") String hostid, @PathParam("uuid1") String uuid1, EndpointConfig config) { + + try { + + init(session); + + logger.debug("websocket channel to host "+ hostid +" openned"); + + Host h = ht.getHostById(hostid); + + String[] hh = bt.parseJupyterURL(h.getUrl()); + + String wsprotocol = "ws"; + + String trueurl = wsprotocol + "://"+hh[1]+":"+hh[2]+"/api/kernels/"+uuid1+"/channels?" + session.getQueryString(); + +// logger.debug("Query String: " + trueurl); + +// this.wsSession = session; + +// this.httpSession = (HttpSession) config.getUserProperties() +// .get(HttpSession.class.getName()); + Map> headers = (Map>)config.getUserProperties().get("RequestHeaders"); + +// client = new Java2JupyterClientEndpoint(new URI(trueurl), session, headers, h); + + SessionPair pair = JupyterSessionPairTool.findPairByID(session.getQueryString()); +// + pair.getGeoweaver_jupyter_client().init(new URI(trueurl), session, headers, h, pair.getId()); + +// client.init(new URI(trueurl), session, headers, h); + +// logger.debug("The connections from javascript end to this servlet, and this servlet to Jupyter server have been created."); + + } catch (URISyntaxException e) { + + e.printStackTrace(); + + } + + } + + @OnError + public void error(final Session session, final Throwable throwable) throws Throwable { + +// removeClosedPair(); + + logger.error("websocket channel error" + throwable.getLocalizedMessage()); + + throw throwable; + + } + + @OnMessage(maxMessageSize = 10000000) + public void echo(String message, @PathParam("uuid1") String uuid1, Session session) { + + try { + +// init(); + +// SessionPair pair = findPairBy1stSession(session); + + SessionPair pair = JupyterSessionPairTool.findPairByID(session.getQueryString()); + + if(bt.isNull(pair)) { + + logger.error("Cann't find the corresponding session pair"); + +// session.close(); + + }else { + +// logger.debug(pair.getId() + " Message from Browser: " + message); +// +// logger.debug("UUID string: " + uuid1 + " - Session ID: " + session.getQueryString()); + +// logger.debug("Transfer message to Jupyter Notebook server.."); + + pair.getGeoweaver_jupyter_client().sendMessage(message); +// client.sendMessage(message); + + } + + }catch(Exception e) { + + e.printStackTrace(); + + } + + } + + @OnClose + public void close(final Session session) { + + try { + +// init(); + + logger.error("Channel closed."); + +// SessionPair pair = findPairBy1stSession(session); + SessionPair pair = JupyterSessionPairTool.findPairByID(session.getQueryString()); + + if(!bt.isNull(pair)) { + + pair.getGeoweaver_jupyter_client().getNew_ws_session_between_geoweaver_and_jupyterserver().close(); //close websocket connection + + JupyterSessionPairTool.pairs.remove(pair); + +// client.getNew_ws_session_between_geoweaver_and_jupyterserver().close(); + + } + +// removeClosedPair(); + + } catch (IOException e) { + + e.printStackTrace(); + + } + + } + + + + +// public class SessionPair{ + +// String id; + +// Session browse_geoweaver_session; + +// Java2JupyterClientEndpoint geoweaver_jupyter_client; + +// public String getId() { +// return id; +// } + +// public void setId(String id) { +// this.id = id; +// } + +// public Session findOpenSession() { + +// Set sessionset = browse_geoweaver_session.getOpenSessions(); + +// Iterator it = sessionset.iterator(); + +// Session session = browse_geoweaver_session; + +// while(it.hasNext()){ +// // System.out.println(it.next()); + +// Session cs = (Session)it.next(); + +// if(id.equals(cs.getQueryString())) { + +// session = cs; + +// break; + +// } + +// } + +// return session; + +// } + +// public Session getBrowse_geoweaver_session() { + +// return findOpenSession(); +// } + +// public void setBrowse_geoweaver_session(Session browse_geoweaver_session) { + +// this.browse_geoweaver_session = browse_geoweaver_session; + +// } + +// public Java2JupyterClientEndpoint getGeoweaver_jupyter_client() { +// return geoweaver_jupyter_client; +// } + +// public void setGeoweaver_jupyter_client(Java2JupyterClientEndpoint geoweaver_jupyter_client) { +// this.geoweaver_jupyter_client = geoweaver_jupyter_client; +// } + +// } + + +} diff --git a/src/main/java/com/gw/server/WebSocketConfig.java b/src/main/java/com/gw/server/WebSocketConfig.java index 53e41b338..36f0e4926 100644 --- a/src/main/java/com/gw/server/WebSocketConfig.java +++ b/src/main/java/com/gw/server/WebSocketConfig.java @@ -51,6 +51,13 @@ public JupyterHubRedirectServlet callJupyterHubWebSocketController() { return new JupyterHubRedirectServlet(); } + + @Bean + public JupyterLabRedirectServlet callJupyterLabWebSocketController() { + + return new JupyterLabRedirectServlet(); + + } } diff --git a/src/main/java/com/gw/web/JupyterController.java b/src/main/java/com/gw/web/JupyterController.java index ec9888299..c24ba7a38 100644 --- a/src/main/java/com/gw/web/JupyterController.java +++ b/src/main/java/com/gw/web/JupyterController.java @@ -607,6 +607,15 @@ private ResponseEntity processPut(HttpMethod method, HttpServletRequest request, HttpHeaders newheaders = getHeaders(this.getHeaderByRequest(request), method, request, hostid); String body = bt.getBody(request); + + //only save the content when the request content is jupyter notebook + logger.debug("PUT request received, body: " + body); + + if(body.contains("\"type\":\"notebook\"")){ + + history_tool.saveJupyterCheckpoints(hostid, body, newheaders); + + } HttpEntity newentity = new HttpEntity(body, newheaders); @@ -961,7 +970,14 @@ private ResponseEntity processGet_415(HttpMethod method, HttpServletReque if(request.getRequestURI().contains("user")) ishub = true; - // if(ishub)logger.info("Old Request HTTP Headers: " + reqentity.getHeaders().toString()); + if(request.getRequestURI().contains("api/kernels")){ + + logger.info("URI: " + request.getRequestURI()); + + logger.info("Old Request HTTP Headers: " + this.getHeaderByRequest(request)); + + } + HttpHeaders newheaders = getHeaders(this.getHeaderByRequest(request), method, request, hostid); @@ -1725,7 +1741,19 @@ public ResponseEntity proxypatch( @PathVariable("hostid") String hostid, HttpMet } - @RequestMapping(value="/jupyter-proxy/{hostid}/**/lab/api/workspaces/**", + + @RequestMapping(value="/jupyter-proxy/{hostid}/**", + // method = RequestMethod.PUT, + // consumes = MediaType.ALL_VALUE, + // produces = MediaType.ALL_VALUE) + // public ResponseEntity proxyput( RequestEntity reqentity, @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException + // { + // ResponseEntity resp = processPut(reqentity, method, request, hostid); + + // return resp; + + // } + // @RequestMapping(value="/jupyter-proxy/{hostid}/**/lab/api/workspaces/**", method = RequestMethod.PUT, consumes = MediaType.ALL_VALUE, produces = MediaType.ALL_VALUE) @@ -1740,29 +1768,8 @@ public ResponseEntity proxyput_415( @PathVariable("hostid") String hostid, HttpM } - @RequestMapping(value="/jupyter-proxy/{hostid}/**", - method = RequestMethod.PUT, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) - public ResponseEntity proxyput( RequestEntity reqentity, @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException - { - ResponseEntity resp = processPut(reqentity, method, request, hostid); - - return resp; - - } - @RequestMapping(value="/jupyter-proxy/{hostid}/**/api/sessions/**", - method = RequestMethod.GET, - consumes = MediaType.ALL_VALUE, - produces = MediaType.ALL_VALUE) - public ResponseEntity proxyget( @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException - { - ResponseEntity resp = processGet_415(method, request, hostid); - - return resp; - - } + @RequestMapping(value="/jupyter-proxy/{hostid}/**/api/sessions/**", method = RequestMethod.POST, @@ -1789,12 +1796,24 @@ public ResponseEntity proxypost( RequestEntity reqentity, @PathVariable("hostid" } @RequestMapping(value="/jupyter-proxy/{hostid}/**", + // method = RequestMethod.GET, + // consumes = MediaType.ALL_VALUE, + // produces = MediaType.ALL_VALUE) + // public ResponseEntity proxyget(RequestEntity reqentity, HttpMethod method, @PathVariable("hostid") String hostid, HttpServletRequest request) throws URISyntaxException + // { + // ResponseEntity resp = processGET( reqentity, method, request, hostid); + + // return resp; + + // } + + // @RequestMapping(value="/jupyter-proxy/{hostid}/**/api/sessions/**", method = RequestMethod.GET, consumes = MediaType.ALL_VALUE, produces = MediaType.ALL_VALUE) - public ResponseEntity proxyget(RequestEntity reqentity, HttpMethod method, @PathVariable("hostid") String hostid, HttpServletRequest request) throws URISyntaxException + public ResponseEntity proxyget( @PathVariable("hostid") String hostid, HttpMethod method, HttpServletRequest request) throws URISyntaxException { - ResponseEntity resp = processGET( reqentity, method, request, hostid); + ResponseEntity resp = processGet_415(method, request, hostid); return resp;