org.apache.qpid.proton.engine.Transport Java Examples
The following examples show how to use
org.apache.qpid.proton.engine.Transport.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SaslImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public int pending() { if (isOutputInSaslMode() || _outputBuffer.position() != 0) { fillOutputBuffer(); _head.limit(_outputBuffer.position()); if (_head_closed && _outputBuffer.position() == 0) { return Transport.END_OF_STREAM; } else { return _outputBuffer.position(); } } else { _parent.switchToNextOutput(); return _underlyingOutput.pending(); } }
Example #2
Source File: TransportPumper.java From qpid-proton-j with Apache License 2.0 | 6 votes |
private int pumpOnce(Transport transportFrom, String fromRole, Transport transportTo, String toRole) { int outputLength = transportFrom.pending(); if (outputLength > 0) { ByteBuffer outputBuffer = transportFrom.head(); int remaining = outputBuffer.remaining(); assertTrue("Unexpected remaining in buffer: " + remaining + " vs " + outputLength, remaining >= outputLength); byte[] output = new byte[remaining]; outputBuffer.get(output); transportFrom.pop(remaining); ByteBuffer inputBuffer = transportTo.getInputBuffer(); inputBuffer.put(output, 0, output.length); TransportResult result = transportTo.processInput(); result.checkIsOk(); } return outputLength; }
Example #3
Source File: DeliveryImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
int recv(final byte[] bytes, int offset, int size) { final int consumed; if (_dataBuffer != null && _dataBuffer.hasRemaining()) { consumed = Math.min(size, _dataBuffer.remaining()); _dataBuffer.get(bytes, offset, consumed); _dataBuffer.reclaimRead(); } else { consumed = 0; } return (_complete && consumed == 0) ? Transport.END_OF_STREAM : consumed; //TODO - Implement }
Example #4
Source File: ProtonHandler.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void onSaslMechanisms(Sasl sasl, Transport transport) { dispatchMechanismsOffered(sasl.getRemoteMechanisms()); if (clientSASLMechanism == null) { log.infof("Outbound connection failed - unknown mechanism, offered mechanisms: %s", Arrays.asList(sasl.getRemoteMechanisms())); dispatchAuthFailed(); } else { sasl.setMechanisms(clientSASLMechanism.getName()); byte[] initialResponse = clientSASLMechanism.getInitialResponse(); if (initialResponse != null) { sasl.send(initialResponse, 0, initialResponse.length); } } }
Example #5
Source File: HonoSaslAuthenticator.java From hono with Eclipse Public License 2.0 | 6 votes |
@Override public void init(final NetSocket socket, final ProtonConnection protonConnection, final Transport transport) { LOG.debug("initializing SASL authenticator"); this.protonConnection = protonConnection; this.sasl = transport.sasl(); sasl.server(); sasl.allowSkip(false); sasl.setMechanisms(authenticationService.getSupportedSaslMechanisms()); if (socket.isSsl() && Arrays.asList(authenticationService.getSupportedSaslMechanisms()) .contains(AuthenticationConstants.MECHANISM_EXTERNAL)) { LOG.debug("client connected using TLS, extracting client certificate chain"); try { final Certificate cert = socket.sslSession().getPeerCertificates()[0]; if (cert instanceof X509Certificate) { clientCertificate = (X509Certificate) cert; } } catch (final SSLPeerUnverifiedException e) { LOG.debug("could not extract client certificate chain, maybe client uses other mechanism than SASL EXTERNAL"); } } }
Example #6
Source File: AmqpSaslAuthenticator.java From qpid-jms with Apache License 2.0 | 6 votes |
public void handleSaslMechanisms(Sasl sasl, Transport transport) { try { String[] remoteMechanisms = sasl.getRemoteMechanisms(); if (remoteMechanisms != null && remoteMechanisms.length != 0) { try { mechanism = mechanismFinder.apply(remoteMechanisms); } catch (SaslSecurityRuntimeException ssre){ recordFailure("Could not find a suitable SASL mechanism. " + ssre.getMessage(), ssre); return; } byte[] response = mechanism.getInitialResponse(); if (response != null) { sasl.send(response, 0, response.length); } sasl.setMechanisms(mechanism.getName()); } } catch (Throwable error) { recordFailure("Exception while processing SASL init: " + error.getMessage(), error); } }
Example #7
Source File: SimpleSslTransportWrapper.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public int pending() { try { wrapOutput(); } catch (SSLException e) { _logger.log(Level.WARNING, e.getMessage()); _head_closed = true; } _head.limit(_outputBuffer.position()); if (_head_closed && _outputBuffer.position() == 0) { return Transport.END_OF_STREAM; } return _outputBuffer.position(); }
Example #8
Source File: AmqpSaslAuthenticator.java From qpid-jms with Apache License 2.0 | 6 votes |
public void handleSaslOutcome(Sasl sasl, Transport transport) { try { switch (sasl.getState()) { case PN_SASL_FAIL: handleSaslFail(sasl); break; case PN_SASL_PASS: handleSaslCompletion(sasl); break; default: break; } } catch (Throwable error) { recordFailure(error.getMessage(), error); } }
Example #9
Source File: EventImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Connection getConnection() { if (context instanceof Connection) { return (Connection) context; } else if (context instanceof Transport) { Transport transport = getTransport(); if (transport == null) { return null; } return ((TransportImpl) transport).getConnectionImpl(); } else { Session ssn = getSession(); if (ssn == null) { return null; } return ssn.getConnection(); } }
Example #10
Source File: EventImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Transport getTransport() { if (context instanceof Transport) { return (Transport) context; } else if (context instanceof Connection) { return ((Connection)context).getTransport(); } else { Session session = getSession(); if (session == null) { return null; } Connection connection = session.getConnection(); if (connection == null) { return null; } return connection.getTransport(); } }
Example #11
Source File: EventImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Reactor getReactor() { if (context instanceof Reactor) { return (Reactor) context; } else if (context instanceof Task) { return ((Task)context).getReactor(); } else if (context instanceof Transport) { return ((TransportImpl)context).getReactor(); } else if (context instanceof Delivery) { return ((Delivery)context).getLink().getSession().getConnection().getReactor(); } else if (context instanceof Link) { return ((Link)context).getSession().getConnection().getReactor(); } else if (context instanceof Session) { return ((Session)context).getConnection().getReactor(); } else if (context instanceof Connection) { return ((Connection)context).getReactor(); } else if (context instanceof Selectable) { return ((Selectable)context).getReactor(); } return null; }
Example #12
Source File: SaslTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void onSaslInit(Sasl s, Transport t) { assertArrayEquals("Server should now know the client's chosen mechanism.", new String[]{TESTMECH1}, s.getRemoteMechanisms()); byte[] serverReceivedInitialBytes = new byte[s.pending()]; s.recv(serverReceivedInitialBytes, 0, serverReceivedInitialBytes.length); assertArrayEquals("Server should now know the client's initial response.", INITIAL_RESPONSE_BYTES, serverReceivedInitialBytes); s.send(CHALLENGE_BYTES, 0, CHALLENGE_BYTES.length); assertFalse("Should not have already received init", initReceived.getAndSet(true)); }
Example #13
Source File: SimpleTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void test() { Connection connection1 = Proton.connection(); Connection connection2 = Proton.connection();; Transport transport1 = Proton.transport(); transport1.bind(connection1); Transport transport2 = Proton.transport(); transport2.bind(connection2); assertEquals(EndpointState.UNINITIALIZED, connection1.getLocalState()); assertEquals(EndpointState.UNINITIALIZED, connection1.getRemoteState()); connection1.open(); connection2.open(); }
Example #14
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testGetTransportWithDeliveryContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); Session session = connection.session(); Sender sender = session.sender("mySender"); Delivery delivery = sender.delivery("tag".getBytes()); EventImpl event = createEvent(delivery, Event.Type.DELIVERY); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #15
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testOutputTooBigToBeWrittenInOneGo() { int smallMaxFrameSize = 512; _transport = new TransportImpl(smallMaxFrameSize); Connection conn = new ConnectionImpl(); _transport.bind(conn); // Open frame sized in order to produce a frame that will almost fill output buffer conn.setHostname(stringOfLength("x", 500)); conn.open(); // Close the connection to generate a Close frame which will cause an overflow // internally - we'll get the remaining bytes on the next interaction. conn.close(); ByteBuffer buf = _transport.getOutputBuffer(); assertEquals("Expecting buffer to be full", smallMaxFrameSize, buf.remaining()); buf.position(buf.limit()); _transport.outputConsumed(); buf = _transport.getOutputBuffer(); assertTrue("Expecting second buffer to have bytes", buf.remaining() > 0); assertTrue("Expecting second buffer to not be full", buf.remaining() < Transport.MIN_MAX_FRAME_SIZE); }
Example #16
Source File: SimpleSslTransportWrapperTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testSslUnwrapThrowsException_returnsErrorResultAndRefusesFurtherInput() throws Exception { String unwrapExceptionMessage = "unwrap exception message"; SSLException sslException = new SSLException(unwrapExceptionMessage); _dummySslEngine.rejectNextEncodedPacket(sslException); _sslWrapper.tail().put("<-A->".getBytes(StandardCharsets.UTF_8)); try { _sslWrapper.process(); fail("no exception"); } catch(TransportException e) { assertEquals("javax.net.ssl.SSLException: " + unwrapExceptionMessage, e.getMessage()); } assertEquals(Transport.END_OF_STREAM, _sslWrapper.capacity()); }
Example #17
Source File: SslTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void assertConditions(Transport transport) { ErrorCondition remoteCondition = transport.getRemoteCondition(); if (remoteCondition != null) { assertNull(remoteCondition.getCondition()); } ErrorCondition condition = transport.getCondition(); if (condition != null) { assertNull(condition.getCondition()); } }
Example #18
Source File: ConnectionTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
/** * "Prior to any explicit negotiation, the maximum frame size is 512 (MIN-MAX-FRAME-SIZE) and the maximum channel number is 0" */ @Test public void testReceiptOfOpenBiggerThanDefaultMaximumFrameSize_causesTODO() { _pumper.pumpAll(); _serverTransport.bind(_serverConnection); assertEnpointState(_serverConnection, UNINITIALIZED, UNINITIALIZED); // containerId and extended header sized to give an open frame // 1 byte larger the than 512 bytes permitted before negotiation by the AMQP spec. String containerId = "123456789"; int extendedHeaderSize = 122 * 4; Open bigOpen = new Open(); bigOpen.setContainerId(containerId); byte[] openFrameBuffer = _framer.generateFrame(0, new byte[extendedHeaderSize], bigOpen); assertEquals("Test requires a frame of size MIN_MAX_FRAME_SIZE + 1", Transport.MIN_MAX_FRAME_SIZE + 1, openFrameBuffer.length); int serverConsumed = _serverTransport.input(openFrameBuffer, 0, openFrameBuffer.length); assertEquals(openFrameBuffer.length, serverConsumed); // TODO server should indicate error but currently both implementations currently process // the larger frames. The following assertions should fail but currently pass. assertEnpointState(_serverConnection, UNINITIALIZED, ACTIVE); assertNotNull(_serverConnection.getRemoteContainer()); }
Example #19
Source File: SaslTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onSaslMechanisms(Sasl s, Transport t) { assertArrayEquals("Client should now know the server's mechanisms.", new String[]{TESTMECH1, TESTMECH2}, s.getRemoteMechanisms()); assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, s.getOutcome()); s.setMechanisms(TESTMECH1); s.send(INITIAL_RESPONSE_BYTES, 0, INITIAL_RESPONSE_BYTES.length); assertFalse("Should not have already received mechanisms", mechanismsReceived.getAndSet(true)); }
Example #20
Source File: SaslTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onSaslChallenge(Sasl s, Transport t) { byte[] clientReceivedChallengeBytes = new byte[s.pending()]; s.recv(clientReceivedChallengeBytes, 0, clientReceivedChallengeBytes.length); assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, s.getOutcome()); assertArrayEquals("Client should now know the server's challenge", CHALLENGE_BYTES, clientReceivedChallengeBytes); s.send(RESPONSE_BYTES, 0, RESPONSE_BYTES.length); assertFalse("Should not have already received challenge", challengeReceived.getAndSet(true)); }
Example #21
Source File: FrameParserTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testInputOfInvalidProtocolHeader_causesErrorAndRefusesFurtherInput() { ByteBuffer buffer = _frameParser.tail(); buffer.put("hello".getBytes()); _frameParser.process(); verify(_mockFrameHandler).closed(any(TransportException.class)); assertEquals(_frameParser.capacity(), Transport.END_OF_STREAM); }
Example #22
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetTransportWithLinkContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); Session session = connection.session(); Link link = session.receiver("myReceiver"); EventImpl event = createEvent(link, Event.Type.LINK_INIT); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #23
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetTransportWithSessionContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); Session session = connection.session(); EventImpl event = createEvent(session, Event.Type.SESSION_INIT); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #24
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetTransportWithTransportContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); EventImpl event = createEvent(transport, Event.Type.TRANSPORT); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #25
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetTransportWithConnectionContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); EventImpl event = createEvent(connection, Event.Type.CONNECTION_BOUND); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #26
Source File: AmqpAdapterSaslAuthenticatorFactory.java From hono with Eclipse Public License 2.0 | 5 votes |
@Override public void init(final NetSocket socket, final ProtonConnection protonConnection, final Transport transport) { LOG.trace("initializing SASL authenticator"); this.protonConnection = protonConnection; this.sasl = transport.sasl(); sasl.server(); sasl.allowSkip(false); sasl.setMechanisms(getSupportedMechanisms()); if (socket.isSsl()) { LOG.trace("client connected through a secured port"); sslSession = socket.sslSession(); } }
Example #27
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testChannelMaxDefault() throws Exception { Transport transport = Proton.transport(); assertEquals("Unesxpected value for channel-max", 65535, transport.getChannelMax()); }
Example #28
Source File: ProtonHandler.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void onSaslChallenge(Sasl sasl, Transport transport) { int challengeSize = sasl.pending(); byte[] challenge = new byte[challengeSize]; sasl.recv(challenge, 0, challengeSize); byte[] response = clientSASLMechanism.getResponse(challenge); sasl.send(response, 0, response.length); }
Example #29
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testSetGetChannelMax() throws Exception { Transport transport = Proton.transport(); int channelMax = 456; transport.setChannelMax(channelMax); assertEquals("Unesxpected value for channel-max", channelMax, transport.getChannelMax()); }
Example #30
Source File: ProtonHandler.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void onSaslInit(Sasl sasl, Transport transport) { log.debug("onSaslInit: " + sasl); dispatchRemoteMechanismChosen(sasl.getRemoteMechanisms()[0]); if (chosenMechanism != null) { processPending(sasl); } else { // no auth available, system error saslComplete(sasl, Sasl.SaslOutcome.PN_SASL_SYS); } }