/** * @see io.apiman.gateway.engine.components.IBufferFactoryComponent#createBuffer(byte[]) */ @Override public IApimanBuffer createBuffer(byte[] byteData) { return new ByteBuffer(byteData); }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#append(byte) */ @Override public void append(byte b) { byte [] bytes = new byte[1]; bytes[0] = b; append(bytes); }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#getString(int, int) */ @Override public String getString(int start, int end) { return new String(getBytes(start, end)); }
@Override public void handle(ISignalWriteStream connectorStream) { try { final InputStream is = req.getInputStream(); ByteBuffer buffer = new ByteBuffer(2048); int numBytes = buffer.readFrom(is); while (numBytes != -1) { connectorStream.write(buffer); numBytes = buffer.readFrom(is); } connectorStream.end(); } catch (Throwable e) { connectorStream.abort(e); } } });
@Override public void handle(ISignalWriteStream connectorStream) { try { final InputStream is = req.getInputStream(); ByteBuffer buffer = new ByteBuffer(2048); int numBytes = buffer.readFrom(is); while (numBytes != -1) { connectorStream.write(buffer); numBytes = buffer.readFrom(is); } connectorStream.end(); } catch (Throwable e) { connectorStream.abort(e); } } });
/** * @see io.apiman.gateway.engine.components.IBufferFactoryComponent#createBuffer() */ @Override public IApimanBuffer createBuffer() { return new ByteBuffer(1024); }
/** * @see io.apiman.gateway.engine.io.ISignalReadStream#transmit() */ @Override public void transmit() { try { if (!connected) { throw new IOException("Not connected."); //$NON-NLS-1$ } InputStream is = connection.getInputStream(); ByteBuffer buffer = new ByteBuffer(2048); int numBytes = buffer.readFrom(is); while (numBytes != -1) { bodyHandler.handle(buffer); numBytes = buffer.readFrom(is); } IOUtils.closeQuietly(is); connection.disconnect(); connected = false; endHandler.handle(null); } catch (Throwable e) { // At this point we're sort of screwed, because we've already sent the response to // the originating client - and we're in the process of sending the body data. So // I guess the only thing to do is abort() the connection and cross our fingers. if (connected) { abort(e); } throw new RuntimeException(e); } }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#append(byte) */ @Override public void append(byte b) { byte [] bytes = new byte[1]; bytes[0] = b; append(bytes); }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#getString(int, int) */ @Override public String getString(int start, int end) { return new String(getBytes(start, end)); }
/** * @see io.apiman.gateway.engine.components.IBufferFactoryComponent#createBuffer(java.lang.String, * java.lang.String) */ @Override public IApimanBuffer createBuffer(String stringData, String enc) { return new ByteBuffer(stringData, enc); }
/** * @see io.apiman.gateway.engine.io.ISignalReadStream#transmit() */ @Override public void transmit() { try { if (!connected) { throw new IOException("Not connected."); //$NON-NLS-1$ } InputStream is = connection.getInputStream(); ByteBuffer buffer = new ByteBuffer(2048); int numBytes = buffer.readFrom(is); while (numBytes != -1) { bodyHandler.handle(buffer); numBytes = buffer.readFrom(is); } IOUtils.closeQuietly(is); connection.disconnect(); connected = false; endHandler.handle(null); } catch (Throwable e) { // At this point we're sort of screwed, because we've already sent the response to // the originating client - and we're in the process of sending the body data. So // I guess the only thing to do is abort() the connection and cross our fingers. if (connected) { abort(e); } throw new RuntimeException(e); } }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#append(java.lang.String) */ @Override public void append(String string) { byte[] bytes = string.getBytes(); append(bytes); }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#getString(int, int, java.lang.String) */ @Override public String getString(int start, int end, String encoding) { try { return new String(getBytes(start, end), encoding); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * @see io.apiman.gateway.engine.components.IBufferFactoryComponent#createBuffer() */ @Override public IApimanBuffer createBuffer() { return new ByteBuffer(1024); }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#append(java.lang.String, java.lang.String) */ @Override public void append(String string, String encoding) throws UnsupportedEncodingException { byte [] bytes = string.getBytes(encoding); append(bytes); }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#getString(int, int, java.lang.String) */ @Override public String getString(int start, int end, String encoding) { try { return new String(getBytes(start, end), encoding); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }