@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(1, false, serializer); } catch (IOException e) { throw new TransportException(e); } }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(1, false, serializer); } catch (IOException e) { throw new TransportException(e); } }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(1, false, serializer); } catch (IOException e) { throw new TransportException(e); } }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(1, false, serializer); } catch (IOException e) { throw new TransportException(e); } }
/** * Processes the response sent back by HTTP server. Override this method to implement custom * response processing logic. Note connection is already released when this method is called. * * @param resp Response object from server. * @param responseString Response string message from server. * @throws TransportException when HTTP call was unsuccessful. */ public void checkResponse(HttpResponse resp, String responseString) throws TransportException { /* * Check responses status code of the overall bulk call. */ if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return; } throw new TransportException( "http transport call failed because \"" + resp.getStatusLine().getReasonPhrase() + "\" payload response \"" + responseString + "\""); } }
/** * Processes the response sent back by HTTP server. Override this method to implement custom * response processing logic. Note connection is already released when this method is called. * * @param resp Response object from server. * @param responseString Response string message from server. * @throws TransportException when HTTP call was unsuccessful. */ public void checkResponse(HttpResponse resp, String responseString) throws TransportException { /* * Check responses status code of the overall bulk call. */ if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return; } throw new TransportException( "http transport call failed because \"" + resp.getStatusLine().getReasonPhrase() + "\" payload response \"" + responseString + "\""); } }
protected HttpResponse sendBatchUncompressed(HttpPost httpPost, byte[] raw) throws TransportException { HttpEntity entity = new ByteArrayEntity(raw, getUncompressedContentType()); httpPost.setEntity(entity); /* * Make call */ HttpResponse resp = null; try { resp = this.client.execute(httpPost); } catch (IOException e) { throw new TransportException("failed to make call", e); } return resp; }
protected HttpResponse sendBatchUncompressed(HttpPost httpPost, byte[] raw) throws TransportException { HttpEntity entity = new ByteArrayEntity(raw, getUncompressedContentType()); httpPost.setEntity(entity); /* * Make call */ HttpResponse resp = null; try { resp = this.client.execute(httpPost); } catch (IOException e) { throw new TransportException("failed to make call", e); } return resp; }
@Override public void sendBatch(TransportBuffer buffer) throws TransportException { FileTransportBuffer buf = (FileTransportBuffer) buffer; FileOutputStream out = null; try { out = new FileOutputStream(new File(this.filename)); out.write(buf.getInternalBuffer().toByteArray()); } catch (IOException e) { throw new TransportException("unable to write to file", e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } } }
@Override public void sendBatch(TransportBuffer buffer) throws TransportException { FileTransportBuffer buf = (FileTransportBuffer) buffer; FileOutputStream out = null; try { out = new FileOutputStream(new File(this.filename)); out.write(buf.getInternalBuffer().toByteArray()); } catch (IOException e) { throw new TransportException("unable to write to file", e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } } }
protected HttpResponse sendBatchCompressed(HttpPost httpPost, byte[] raw) throws TransportException { /* * Write gzip data to Entity and set content encoding to gzip */ ByteArrayEntity entity = new ByteArrayEntity(raw, ContentType.DEFAULT_BINARY); entity.setContentEncoding("gzip"); httpPost.addHeader(new BasicHeader("Accept-Encoding", "gzip")); httpPost.setEntity(entity); /* * Make call */ HttpResponse resp = null; try { resp = this.client.execute(httpPost); } catch (IOException e) { throw new TransportException("failed to make call", e); } return resp; }
public S3TransportBuffer(long maxBytes, boolean useCompression, S3TransportSerializer serializer) throws TransportException { this.maxBytes = maxBytes; this.serializer = serializer; baos = new ByteArrayOutputStream(); cos = new CountingOutputStream(baos); if (useCompression) { this.isCompressed = true; try { os = new BZip2CompressorOutputStream(cos); } catch (IOException e) { throw new TransportException("unable to create BZip2CompressorOutputStream", e); } } else { this.isCompressed = false; os = cos; } }
public S3TransportBuffer(long maxBytes, boolean useCompression, S3TransportSerializer serializer) throws TransportException { this.maxBytes = maxBytes; this.serializer = serializer; baos = new ByteArrayOutputStream(); cos = new CountingOutputStream(baos); if (useCompression) { this.isCompressed = true; try { os = new BZip2CompressorOutputStream(cos); } catch (IOException e) { throw new TransportException("unable to create BZip2CompressorOutputStream", e); } } else { this.isCompressed = false; os = cos; } }
protected ByteArrayOutputStream compress(ByteArrayOutputStream raw) throws TransportException { ByteArrayOutputStream compressed = new ByteArrayOutputStream(); BZip2CompressorOutputStream bcos = null; try { bcos = new BZip2CompressorOutputStream(compressed); } catch (IOException e) { throw new TransportException("unable to open compressed stream", e); } try { raw.writeTo(bcos); bcos.flush(); } catch (IOException e) { throw new TransportException("unable to compress data", e); } finally { try { bcos.close(); } catch (IOException e) { } } return compressed; }
@Override public void sendBatch(TransportBuffer buffer) throws TransportException { Buffer internalBuffer = ((TcpTransportBuffer) buffer).getInternalBuffer(); Callable<Boolean> write = () -> { try { sink.write(internalBuffer, internalBuffer.size()); return true; } catch (IOException ex) { throw new TransportException("Error while sending in tcp transport", ex); } }; try { new CallExecutor(retryConfig).execute(write); } catch (RetriesExhaustedException | UnexpectedException ue) { throw new TransportException(ue); } }
@Override public void sendBatch(TransportBuffer buffer) throws TransportException { Buffer internalBuffer = ((TcpTransportBuffer) buffer).getInternalBuffer(); Callable<Boolean> write = () -> { try { sink.write(internalBuffer, internalBuffer.size()); return true; } catch (IOException ex) { throw new TransportException("Error while sending in tcp transport", ex); } }; try { new CallExecutor(retryConfig).execute(write); } catch (RetriesExhaustedException | UnexpectedException ue) { throw new TransportException(ue); } }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(this.config.getBatchSize(), this.config.isUseGzip(), this.serializer); } catch (IOException e) { throw new TransportException("error creating GenericTransportBuffer", e); } } }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(this.config.getBatchSize(), this.config.isUseGzip(), this.serializer); } catch (IOException e) { throw new TransportException("error creating GenericTransportBuffer", e); } } }
@Test(expected = TransportException.class) public void testExceptionEscalation() throws TransportException, InterruptedException { DummyTransporter mockDummyTransporter = mock(DummyTransporter.class); DummyTransporterFactory tfactory = new DummyTransporterFactory(); tfactory.transporter = mockDummyTransporter; doThrow(new TransportException("expected exception in test")).when(mockDummyTransporter) .sendBatch(any(DummyTransportBuffer.class)); IpcSenderService ipc = new IpcSenderService(tfactory); ipc.add(mock(InternalEvent.class)); /* * Expect shutdown to throw a TransportException when a child thread also throws as * TransportException */ ipc.flush(); }
@Test(expected = TransportException.class) public void testGeneralTransportExceptionOnShutdown() throws Throwable { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; List<DummyEvent> events = new ArrayList<DummyEvent>(1); events.add(new DummyEvent("foo", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); IpcSenderService spy = spy(handler.getIpcService()); handler.setIpcService(spy); doThrow(new TransportException("expected")).when(spy).flush(); try { handler.handler(events, context); } catch (Exception e) { throw e.getCause().getCause(); } }