本文整理了Java中org.apache.qpid.proton.engine.Transport
类的一些代码示例,展示了Transport
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transport
类的具体详情如下:
包路径:org.apache.qpid.proton.engine.Transport
类名称:Transport
[英]Operates on the entities in the associated Connectionby accepting and producing binary AMQP output, potentially layered within SASL and/or SSL.
After a connection is bound with #bind(Connection), the methods for accepting and producing output are typically repeatedly called. See the specific methods for details of their legal usage.
Processing the input data received from another AMQP container.
Getting the output data to send to another AMQP container:
The following methods on the byte buffers returned by #getInputBuffer() and #getOutputBuffer()must not be called:
代码示例来源:origin: io.vertx/vertx-proton
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
this.sasl = transport.sasl();
sasl.server();
sasl.allowSkip(false);
sasl.setMechanisms(ProtonSaslAnonymousImpl.MECH_NAME);
succeeded = false;
}
代码示例来源:origin: com.microsoft.azure.iot/proton-j-azure-iot
private void handleOpen(Event event) {
Connection connection = event.getConnection();
if (connection.getRemoteState() != EndpointState.UNINITIALIZED) {
return;
}
Transport transport = Proton.transport();
Sasl sasl = transport.sasl();
sasl.client();
sasl.setMechanisms("ANONYMOUS");
transport.webSocket();
transport.bind(connection);
}
代码示例来源:origin: org.apache.activemq/artemis-proton-plug
@Override
public long tick(boolean firstTick) {
if (!firstTick) {
try {
if (connection.getLocalState() != EndpointState.CLOSED) {
long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
if (transport.isClosed()) {
throw new IllegalStateException("Channel was inactive for to long");
}
return rescheduleAt;
}
}
catch (Exception e) {
transport.close();
connection.setCondition(new ErrorCondition());
}
return 0;
}
return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
}
代码示例来源:origin: Azure/azure-service-bus-java
@Override
public void onConnectionLocalOpen(Event event)
{
Connection connection = event.getConnection();
if (connection.getRemoteState() != EndpointState.UNINITIALIZED)
{
return;
}
Transport transport = Proton.transport();
transport.sasl();
transport.setEmitFlowEventOnSend(false);
transport.bind(connection);
}
代码示例来源:origin: com.ibm.mqlight/mqlight-api
ProtocolTracer protocolTracer = new EngineProtocolTracer(or.clientId);
((TransportImpl) transport).setProtocolTracer(protocolTracer);
transport.setIdleTimeout(or.endpoint.getIdleTimeout());
transport.bind(protonConnection);
Collector collector = Proton.collector();
protonConnection.setContainer(or.clientId);
protonConnection.setHostname(or.endpoint.getHost());
protonConnection.open();
Sasl sasl = transport.sasl();
sasl.client();
if (or.endpoint.getUser() == null) {
sasl.setMechanisms("ANONYMOUS");
} else {
sasl.plain(or.endpoint.getUser(), or.endpoint.getPassword());
int delta = engineConnection.transport.head().remaining();
if (engineConnection.transport.pending() > 0) {
writeToNetwork(engineConnection);
try {
EngineConnection engineConnection = (EngineConnection) dr.channel.getContext();
if (!engineConnection.closed && !engineConnection.transport.isClosed()) {
int bytesAvailable;
while ((bytesAvailable = dr.buffer.readableBytes()) > 0) {
ByteBuffer tail = engineConnection.transport.tail();
if (bytesAvailable > tail.remaining()) {
int max = tail.capacity() - tail.position();
代码示例来源:origin: org.apache.activemq/activemq-osgi
try {
if (response.isException()) {
protonConnection.setProperties(getFailedConnetionProperties());
protonConnection.open();
protonConnection.setCondition(new ErrorCondition(AmqpError.UNAUTHORIZED_ACCESS, exception.getMessage()));
} else if (exception instanceof InvalidClientIDException) {
ErrorCondition condition = new ErrorCondition(AmqpError.INVALID_FIELD, exception.getMessage());
condition.setInfo(infoMap);
protonConnection.setCondition(condition);
if (amqpTransport.isUseInactivityMonitor() && amqpWireFormat.getIdleTimeout() > 0) {
LOG.trace("Connection requesting Idle timeout of: {} mills", amqpWireFormat.getIdleTimeout());
protonTransport.setIdleTimeout(amqpWireFormat.getIdleTimeout());
代码示例来源:origin: org.apache.qpid/qpid-jms-client
this.connectionRequest = connectRequest;
protonTransport.setEmitFlowEventOnSend(false);
protonTransport.setMaxFrameSize(getMaxFrameSize());
protonTransport.setOutboundFrameSizeLimit(getMaxFrameSize());
protonTransport.setChannelMax(getChannelMax());
protonTransport.setIdleTimeout(idleTimeout);
protonTransport.bind(protonConnection);
protonConnection.collect(protonCollector);
Sasl sasl = protonTransport.sasl();
sasl.client();
sasl.setRemoteHostname(hostname);
sasl.setListener(new SaslListener() {
代码示例来源:origin: apache/activemq-artemis
@Override
public void run() {
if (!noContainerID) {
getEndpoint().setContainer(safeGetContainerId());
getEndpoint().setHostname(remoteURI.getHost());
if (!getDesiredCapabilities().isEmpty()) {
getEndpoint().setDesiredCapabilities(getDesiredCapabilities().toArray(new Symbol[0]));
protonTransport.setIdleTimeout(getIdleTimeout());
protonTransport.setMaxFrameSize(getMaxFrameSize());
protonTransport.setChannelMax(getChannelMax());
protonTransport.setEmitFlowEventOnSend(false);
protonTransport.bind(getEndpoint());
Sasl sasl = protonTransport.sasl();
if (sasl != null) {
sasl.client();
代码示例来源:origin: org.apache.qpid/proton-j
private void handleOpen(Reactor reactor, Event event) {
Connection connection = event.getConnection();
if (connection.getRemoteState() != EndpointState.UNINITIALIZED) {
return;
String vhost = connection.getHostname();
if (vhost == null) {
if (conAddr != null) {
Address addr = new Address(conAddr);
connection.setHostname(addr.getHost());
transport.setMaxFrameSize(maxFrameSizeOption);
Sasl sasl = transport.sasl();
sasl.client();
sasl.setMechanisms("ANONYMOUS");
transport.bind(connection);
代码示例来源:origin: EnMasseProject/enmasse
private SaslMechanism chooseSaslMechanismAndSendInit(Connection connection, InputStream in, OutputStream out) throws LoginException, IOException {
Transport transport = connection.getTransport();
Sasl sasl = transport.sasl();
SaslMechanism mechanism = null;
// read from network until we get a sasl-mechanisms
readFromNetwork(connection, in, () -> sasl.getState() == PN_SASL_IDLE && sasl.getRemoteMechanisms().length == 0);
for (SaslMechanismFactory factory : saslFactories) {
if (Arrays.asList(sasl.getRemoteMechanisms()).contains(factory.getName())) {
mechanism = factory.newInstance(callbackHandler, sharedState, options);
if (mechanism != null) {
sasl.setRemoteHostname(saslHostname);
sasl.setMechanisms(factory.getName());
byte[] initialResponse = mechanism.getResponse(null);
if (initialResponse != null && initialResponse.length != 0) {
sasl.send(initialResponse, 0, initialResponse.length);
}
break;
}
}
}
if (mechanism == null) {
throw new LoginException("Unable to authenticate using SASL delegation, no supported mechanisms");
}
writeToNetwork(connection, out);
return mechanism;
}
代码示例来源:origin: com.ibm.mqlight/mqlight-api
logger.entry(this, methodName, event);
if (event.getConnection().getRemoteState() == EndpointState.CLOSED) {
final ErrorCondition remoteCondition = event.getConnection().getRemoteCondition();
final EngineConnection engineConnection = (EngineConnection)event.getConnection().getContext();
if (engineConnection.timerPromise != null) {
TimerPromiseImpl tmp = engineConnection.timerPromise;
final Sasl sasl = engineConnection.transport.sasl();
if (sasl.getOutcome() == Sasl.SaslOutcome.PN_SASL_AUTH) {
clientException = new com.ibm.mqlight.api.SecurityException(
"Failed to authenticate with server - invalid username or password",
|| remoteCondition.getDescription() == null) {
clientException = new NetworkException(
"The server closed the connection without providing any error information.");
EngineConnection engineConnection = (EngineConnection)event.getConnection().getContext();
long now = System.currentTimeMillis();
long timeout = engineConnection.transport.tick(now);
if (timeout > 0) {
engineConnection.timerPromise = new TimerPromiseImpl(this, engineConnection);
代码示例来源:origin: org.apache.qpid/proton-j
Record conn_recs = conn.attachments();
conn_recs.set(CONNECTION_ACCEPTOR_KEY, Acceptor.class, AcceptorImpl.this);
InetSocketAddress peerAddr = (InetSocketAddress)socketChannel.getRemoteAddress();
trans.setMaxFrameSize(maxFrameSizeOption);
Sasl sasl = trans.sasl();
sasl.server();
sasl.setMechanisms("ANONYMOUS");
sasl.done(SaslOutcome.PN_SASL_OK);
trans.bind(conn);
IOHandler.selectableTransport(reactor, socketChannel.socket(), trans);
} catch(IOException ioException) {
代码示例来源:origin: com.microsoft.azure.iot/proton-j-azure-iot
@Override
public void run(Selectable selectable) {
Reactor reactor = selectable.getReactor();
Transport transport = ((SelectableImpl)selectable).getTransport();
int capacity = transport.capacity();
if (capacity > 0) {
SocketChannel socketChannel = (SocketChannel)selectable.getChannel();
try {
int n = socketChannel.read(transport.tail());
if (n == -1) {
transport.close_tail();
} else {
transport.process();
}
} catch (IOException e) {
ErrorCondition condition = new ErrorCondition();
condition.setCondition(Symbol.getSymbol("proton:io"));
condition.setDescription(e.getMessage());
transport.setCondition(condition);
transport.close_tail();
}
}
// (Comment from C code:) occasionally transport events aren't
// generated when expected, so the following hack ensures we
// always update the selector
update(selectable);
reactor.update(selectable);
}
};
代码示例来源:origin: com.microsoft.azure.iot/proton-j-azure-iot
@Override
public void run(Selectable selectable) {
Reactor reactor = selectable.getReactor();
try {
SocketChannel socketChannel = ((ServerSocketChannel)selectable.getChannel()).accept();
if (socketChannel == null) {
throw new ReactorInternalException("Selectable readable, but no socket to accept");
}
Handler handler = BaseHandler.getHandler(AcceptorImpl.this);
if (handler == null) {
handler = reactor.getHandler();
}
Connection conn = reactor.connection(handler);
Transport trans = Proton.transport();
Sasl sasl = trans.sasl();
sasl.server();
sasl.setMechanisms("ANONYMOUS");
sasl.done(SaslOutcome.PN_SASL_OK);
trans.bind(conn);
IOHandler.selectableTransport(reactor, socketChannel.socket(), trans);
} catch(IOException ioException) {
sel.error();
}
}
}
代码示例来源:origin: Azure/azure-iot-sdk-java
/**
* Event handler for the connection bound event
* @param event The proton event object
*/
@Override
public void onConnectionBound(Event event)
{
// Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_010: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_011: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport]
Transport transport = event.getConnection().getTransport();
if (transport != null)
{
if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS)
{
WebSocketImpl webSocket = new WebSocketImpl();
webSocket.configure(this.webSocketHostName, WEBSOCKET_PATH, 0, WEBSOCKET_SUB_PROTOCOL, null, null);
((TransportInternal)transport).addTransportLayer(webSocket);
}
Sasl sasl = transport.sasl();
sasl.plain(this.userName, this.sasToken);
SslDomain domain = makeDomain(SslDomain.Mode.CLIENT);
domain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
Ssl ssl = transport.ssl(domain);
}
}
代码示例来源:origin: org.apache.activemq/artemis-amqp-protocol
public void createServerSASL(String[] mechanisms) {
Sasl sasl = transport.sasl();
sasl.server();
sasl.setMechanisms(mechanisms);
sasl.setListener(this);
}
代码示例来源:origin: EnMasseProject/enmasse
private void performSaslSteps(Connection connection, InputStream in,
OutputStream out,
SaslMechanism mechanism) throws IOException, LoginException {
Transport transport = connection.getTransport();
Sasl sasl = transport.sasl();
do {
readFromNetwork(connection, in, () ->
!(EnumSet.of(PN_SASL_PASS, PN_SASL_FAIL).contains(sasl.getState())
|| (sasl.getState() == PN_SASL_STEP && sasl.pending() > 0)));
if (sasl.pending() > 0) {
byte[] challenge = new byte[sasl.pending()];
byte[] response = mechanism.getResponse(challenge);
if (sasl.getState() == PN_SASL_STEP) {
sasl.send(response, 0, response.length);
writeToNetwork(connection, out);
}
}
} while (sasl.getState() == PN_SASL_STEP);
}
代码示例来源:origin: EnMasseProject/enmasse
transport.bind(connection);
Sasl sasl = transport.sasl();
sasl.client();
OutputStream out = socket.getOutputStream();
transport.open();
connection.close();
transport.close();
socket.close();
代码示例来源:origin: org.apache.activemq/activemq-osgi
public AmqpConnection(AmqpTransport transport, BrokerService brokerService) {
this.amqpTransport = transport;
AmqpInactivityMonitor monitor = transport.getInactivityMonitor();
if (monitor != null) {
monitor.setAmqpTransport(amqpTransport);
}
this.amqpWireFormat = transport.getWireFormat();
this.brokerService = brokerService;
// the configured maxFrameSize on the URI.
int maxFrameSize = amqpWireFormat.getMaxAmqpFrameSize();
if (maxFrameSize > AmqpWireFormat.NO_AMQP_MAX_FRAME_SIZE) {
this.protonTransport.setMaxFrameSize(maxFrameSize);
try {
this.protonTransport.setOutboundFrameSizeLimit(maxFrameSize);
} catch (Throwable e) {
// Ignore if older proton-j was injected.
}
}
this.protonTransport.bind(this.protonConnection);
this.protonTransport.setChannelMax(CHANNEL_MAX);
this.protonTransport.setEmitFlowEventOnSend(false);
this.protonConnection.collect(eventCollector);
updateTracer();
}
代码示例来源:origin: jboss-fuse/fabric8
@Override
public void handle(AmqpEvent event) {
switch( event.type ) {
case HEADER:
AmqpHeader header = (AmqpHeader) event.decodedFrame;
switch (header.getProtocolId()) {
case 0:
// amqpTransport.sendToAmqp(new AmqpHeader());
break; // nothing to do..
case 3:
// Client will be using SASL for auth..
sasl = protonTransport.sasl();
// sasl.setMechanisms(new String[] { "ANONYMOUS", "PLAIN" });
sasl.server();
break;
default:
}
processEvent(event);
// Les send back the AMQP response headers so that the client
// can send us the SASL init or AMQP open frames.
Buffer buffer = toBuffer(protonTransport.getOutputBuffer());
protonTransport.outputConsumed();
socket.write(buffer);
break;
default:
processEvent(event);
}
}
内容来源于网络,如有侵权,请联系作者删除!