List of usage examples for org.apache.http.nio.reactor IOSession getAttribute
Object getAttribute(String name);
From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.MLLPSourceHandler.java
@Override public void disconnected(IOSession session) { MLLPContext mllpContext = (MLLPContext) session.getAttribute(MLLPConstants.MLLP_CONTEXT); shutdownConnection(session, mllpContext, null); }
From source file:org.apache.axis2.transport.nhttp.PlainClientIOEventDispatch.java
public void connected(final IOSession session) { // Decorate I/O session with logging capabilities LoggingNHttpClientConnection conn = new LoggingNHttpClientConnection(new LoggingIOSession(session), new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), this.params); session.setAttribute(NHTTP_CONN, conn); Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY); this.handler.connected(conn, attachment); }
From source file:org.apache.axis2.transport.nhttp.SSLClientIOEventDispatch.java
public void connected(final IOSession session) { SSLIOSession sslSession = new SSLIOSession(session, this.sslcontext, this.sslHandler); LoggingNHttpClientConnection conn = new LoggingNHttpClientConnection(new LoggingIOSession(sslSession), new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), this.params); session.setAttribute(NHTTP_CONN, conn); session.setAttribute(SSL_SESSION, sslSession); Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY); this.handler.connected(conn, attachment); try {/* www . j a va2 s . c o m*/ sslSession.bind(SSLMode.CLIENT, this.params); } catch (SSLException ex) { this.handler.exception(conn, ex); sslSession.shutdown(); } }
From source file:com.ok2c.lightmtp.impl.protocol.AuthCodec.java
@Override public void consumeData(final IOSession iosession, final ClientState state) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(state, "Session state"); SessionInputBuffer buf = this.iobuffers.getInbuf(); int bytesRead = buf.fill(iosession.channel()); SMTPReply reply = this.parser.parse(buf, bytesRead == -1); if (reply != null) { switch (this.codecState) { case AUTH_RESPONSE_READY: AuthMode mode = (AuthMode) iosession.getAttribute(AUTH_TYPE); if (reply.getCode() == SMTPCodes.START_AUTH_INPUT) { if (mode == AuthMode.PLAIN) { this.codecState = CodecState.AUTH_PLAIN_INPUT_READY; } else if (mode == AuthMode.LOGIN) { this.codecState = CodecState.AUTH_LOGIN_USERNAME_INPUT_READY; }//from w ww . ja v a 2 s . c o m state.setReply(reply); iosession.setEvent(SelectionKey.OP_WRITE); } else { // TODO: should we set the failure here ? // At the moment we just process as maybe its possible to send // the mail even without auth this.codecState = CodecState.COMPLETED; state.setReply(reply); } break; case AUTH_PLAIN_INPUT_RESPONSE_EXPECTED: if (reply.getCode() == SMTPCodes.AUTH_OK) { this.codecState = CodecState.COMPLETED; state.setReply(reply); iosession.setEvent(SelectionKey.OP_WRITE); } else { // TODO: should we set the failure here ? // At the moment we just process as maybe its possible to send // the mail even without auth this.codecState = CodecState.COMPLETED; state.setReply(reply); } break; case AUTH_LOGIN_USERNAME_INPUT_RESPONSE_EXPECTED: if (reply.getCode() == SMTPCodes.START_AUTH_INPUT) { this.codecState = CodecState.AUTH_LOGIN_PASSWORD_INPUT_READY; state.setReply(reply); iosession.setEvent(SelectionKey.OP_WRITE); } else { throw new SMTPProtocolException("Unexpected reply:" + reply); } break; case AUTH_LOGIN_PASSWORD_INPUT_RESPONSE_EXPECTED: if (reply.getCode() == SMTPCodes.AUTH_OK) { this.codecState = CodecState.COMPLETED; state.setReply(reply); iosession.setEvent(SelectionKey.OP_WRITE); } else { // TODO: should we set the failure here ? // At the moment we just process as maybe its possible to send // the mail even without auth this.codecState = CodecState.COMPLETED; state.setReply(reply); } break; default: if (reply.getCode() == SMTPCodes.ERR_TRANS_SERVICE_NOT_AVAILABLE) { state.setReply(reply); this.codecState = CodecState.COMPLETED; } else { throw new SMTPProtocolException("Unexpected reply:" + reply); } } } else { if (bytesRead == -1 && !state.isTerminated()) { throw new UnexpectedEndOfStreamException(); } } }
From source file:org.apache.http.impl.nio.conn.HttpPoolEntry.java
public ClientAsyncConnection getOperatedClientConnection() { final IOSession session = getConnection(); return (ClientAsyncConnection) session.getAttribute(IOEventDispatch.CONNECTION_KEY); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.MLLPSourceHandler.java
@Override public void inputReady(IOSession session) { ReadableByteChannel ch = (ReadableByteChannel) session.channel(); MLLPContext mllpContext = (MLLPContext) session.getAttribute(MLLPConstants.MLLP_CONTEXT); inputBuffer.clear();/* ww w. j a va2s. com*/ try { int read; while ((read = ch.read(inputBuffer.getByteBuffer())) > 0) { inputBuffer.flip(); try { mllpContext.getCodec().decode(inputBuffer.getByteBuffer(), mllpContext); } catch (MLLProtocolException e) { handleException(session, mllpContext, e); clearInputBuffers(mllpContext); return; } catch (HL7Exception e) { handleException(session, mllpContext, e); if (mllpContext.isAutoAck()) { mllpContext.setNackMode(true); mllpContext.setHl7Message(HL7MessageUtils.createDefaultNack(e.getMessage())); mllpContext.requestOutput(); } else { hl7Processor.processError(mllpContext, e); } return; } catch (IOException e) { shutdownConnection(session, mllpContext, e); return; } } if (mllpContext.getCodec().isReadComplete()) { if (mllpContext.isAutoAck()) { mllpContext.requestOutput(); bufferFactory.release(inputBuffer); inputBuffer = bufferFactory.getBuffer(); } try { hl7Processor.processRequest(mllpContext); } catch (Exception e) { shutdownConnection(session, mllpContext, e); } } if (read < 0) { clearInputBuffers(mllpContext); session.close(); } } catch (IOException e) { shutdownConnection(session, mllpContext, e); } }