@Test public void streamPathWithRegularChars() throws Exception { context.setDataSource("whatCAN1tellYOU"); Response result = writableResource.stream(mockServletContext, mockHeaders, mockInputStream); assertEquals(Response.Status.OK, Response.Status.fromStatusCode(result.getStatus())); assertEquals("wrote 0 bulks to whatCAN1tellYOU", result.getEntity().toString()); }
@POST @Path("stream") @Consumes(MediaType.APPLICATION_OCTET_STREAM) public Response stream(@Context final ServletContext servletContext, @Context HttpHeaders headers, InputStream inputStream) throws Exception { RequestContext context = parseRequest(headers); Bridge bridge = bridgeFactory.getWriteBridge(context); String path = context.getDataSource(); bridge.beginIteration(); long totalWritten = 0; Exception ex = null; try (DataInputStream dataStream = new DataInputStream(inputStream)) { while (bridge.setNext(dataStream)) { ++totalWritten; } } catch (ClientAbortException cae) { if (LOG.isDebugEnabled()) { LOG.debug("Remote connection closed by GPDB", cae); } else { LOG.error("Remote connection closed by GPDB (Enable debug for stacktrace)"); } } catch (Exception e) { LOG.error("Exception: totalWritten so far " + totalWritten + " to " + path, e); ex = e; throw ex; } finally { try { bridge.endIteration(); } catch (Exception e) { throw (ex == null) ? e : ex; } } String censuredPath = Utilities.maskNonPrintables(path); String returnMsg = "wrote " + totalWritten + " bulks to " + censuredPath; LOG.debug(returnMsg); return Response.ok(returnMsg).build(); }
WritableResource extends BaseResource { @POST @Path("stream") @Consumes(MediaType.APPLICATION_OCTET_STREAM) public Response stream(@Context final ServletContext servletContext, @Context HttpHeaders headers, InputStream inputStream) throws Exception { RequestContext context = parseRequest(headers); Bridge bridge = bridgeFactory.getWriteBridge(context); String path = context.getDataSource(); bridge.beginIteration(); long totalWritten = 0; Exception ex = null; try (DataInputStream dataStream = new DataInputStream(inputStream)) { while (bridge.setNext(dataStream)) { ++totalWritten; } } catch (ClientAbortException cae) { if (LOG.isDebugEnabled()) { LOG.debug("Remote connection closed by GPDB", cae); } else { LOG.error("Remote connection closed by GPDB (Enable debug for stacktrace)"); } } catch (Exception e) { LOG.error("Exception: totalWritten so far " + totalWritten + " to " + path, e); ex = e; throw ex; } finally { try { bridge.endIteration(); } catch (Exception e) { throw (ex == null) ? e : ex; } } String censuredPath = Utilities.maskNonPrintables(path); String returnMsg = "wrote " + totalWritten + " bulks to " + censuredPath; LOG.debug(returnMsg); return Response.ok(returnMsg).build(); } }
WritableResource extends BaseResource { @POST @Path("stream") @Consumes(MediaType.APPLICATION_OCTET_STREAM) public Response stream(@Context final ServletContext servletContext, @Context HttpHeaders headers, InputStream inputStream) throws Exception { RequestContext context = parseRequest(headers); Bridge bridge = bridgeFactory.getWriteBridge(context); String path = context.getDataSource(); bridge.beginIteration(); long totalWritten = 0; Exception ex = null; try (DataInputStream dataStream = new DataInputStream(inputStream)) { while (bridge.setNext(dataStream)) { ++totalWritten; } } catch (ClientAbortException cae) { if (LOG.isDebugEnabled()) { LOG.debug("Remote connection closed by GPDB", cae); } else { LOG.error("Remote connection closed by GPDB (Enable debug for stacktrace)"); } } catch (Exception e) { LOG.error("Exception: totalWritten so far " + totalWritten + " to " + path, e); ex = e; throw ex; } finally { try { bridge.endIteration(); } catch (Exception e) { throw (ex == null) ? e : ex; } } String censuredPath = Utilities.maskNonPrintables(path); String returnMsg = "wrote " + totalWritten + " bulks to " + censuredPath; LOG.debug(returnMsg); return Response.ok(returnMsg).build(); } WritableResource();   WritableResource(RequestParser<HttpHeaders> parser, BridgeFactory bridgeFactory); }
WritableResource extends BaseResource { @POST @Path("stream") @Consumes(MediaType.APPLICATION_OCTET_STREAM) public Response stream(@Context final ServletContext servletContext, @Context HttpHeaders headers, InputStream inputStream) throws Exception { RequestContext context = parseRequest(headers); Bridge bridge = bridgeFactory.getWriteBridge(context); String path = context.getDataSource(); bridge.beginIteration(); long totalWritten = 0; Exception ex = null; try (DataInputStream dataStream = new DataInputStream(inputStream)) { while (bridge.setNext(dataStream)) { ++totalWritten; } } catch (ClientAbortException cae) { if (LOG.isDebugEnabled()) { LOG.debug("Remote connection closed by GPDB", cae); } else { LOG.error("Remote connection closed by GPDB (Enable debug for stacktrace)"); } } catch (Exception e) { LOG.error("Exception: totalWritten so far " + totalWritten + " to " + path, e); ex = e; throw ex; } finally { try { bridge.endIteration(); } catch (Exception e) { throw (ex == null) ? e : ex; } } String censuredPath = Utilities.maskNonPrintables(path); String returnMsg = "wrote " + totalWritten + " bulks to " + censuredPath; LOG.debug(returnMsg); return Response.ok(returnMsg).build(); } WritableResource();   WritableResource(RequestParser<HttpHeaders> parser, BridgeFactory bridgeFactory); @POST @Path("stream") @Consumes(MediaType.APPLICATION_OCTET_STREAM) Response stream(@Context final ServletContext servletContext,
                           @Context HttpHeaders headers,
                           InputStream inputStream); }
WritableResource extends BaseResource { @POST @Path("stream") @Consumes(MediaType.APPLICATION_OCTET_STREAM) public Response stream(@Context final ServletContext servletContext, @Context HttpHeaders headers, InputStream inputStream) throws Exception { RequestContext context = parseRequest(headers); Bridge bridge = bridgeFactory.getWriteBridge(context); String path = context.getDataSource(); bridge.beginIteration(); long totalWritten = 0; Exception ex = null; try (DataInputStream dataStream = new DataInputStream(inputStream)) { while (bridge.setNext(dataStream)) { ++totalWritten; } } catch (ClientAbortException cae) { if (LOG.isDebugEnabled()) { LOG.debug("Remote connection closed by GPDB", cae); } else { LOG.error("Remote connection closed by GPDB (Enable debug for stacktrace)"); } } catch (Exception e) { LOG.error("Exception: totalWritten so far " + totalWritten + " to " + path, e); ex = e; throw ex; } finally { try { bridge.endIteration(); } catch (Exception e) { throw (ex == null) ? e : ex; } } String censuredPath = Utilities.maskNonPrintables(path); String returnMsg = "wrote " + totalWritten + " bulks to " + censuredPath; LOG.debug(returnMsg); return Response.ok(returnMsg).build(); } WritableResource();   WritableResource(RequestParser<HttpHeaders> parser, BridgeFactory bridgeFactory); @POST @Path("stream") @Consumes(MediaType.APPLICATION_OCTET_STREAM) Response stream(@Context final ServletContext servletContext,
                           @Context HttpHeaders headers,
                           InputStream inputStream);  }