Package org.jgrapes.net
Class SslCodec
java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jgrapes.net.SslCodec
- All Implemented Interfaces:
Iterable<ComponentType>,Channel,ComponentType,Eligible,Manager
A component that receives and sends byte buffers on an
encrypted channel and sends and receives the corresponding
decrypted data on a plain channel.
The encrypted channel is assumed to be the network side
(“upstream”) and therefore Input events represent
encrypted data and are decoded to Output events on
the plain channel (“downstream”) and vice versa.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new codec to be used as client.SslCodec(Channel plainChannel, Channel encryptedChannel, SSLContext sslContext) Creates a new codec that uses the givenSSLContext. -
Method Summary
Modifier and TypeMethodDescriptionvoidonAccepted(Accepted event, IOSubchannel encryptedChannel) Creates a new downstream connection asLinkedIOSubchannelof the network connection together with anSSLEngine.voidForwards a close event upstream.voidonClosed(Closed<Void> event, IOSubchannel encryptedChannel) Handles a close event from the encrypted channel (client).voidonConnected(ClientConnected event, IOSubchannel encryptedChannel) Creates a new downstream connection asLinkedIOSubchannelof the network connection together with anSSLEngine.voidonHalfClosed(HalfClosed event, IOSubchannel encryptedChannel) Handles a half close event from the encrypted channel (client).voidonInput(Input<ByteBuffer> event, IOSubchannel encryptedChannel) Handles encrypted data from upstream (the network).voidHandles anIOErrorevent from the encrypted channel (client) by sending it downstream.voidForward the connection request to the encrypted network.voidonOutput(Output<ByteBuffer> event, org.jgrapes.net.SslCodec.PlainChannel plainChannel) Sends plain data through the engine and then upstream.voidonPurge(Purge event, IOSubchannel encryptedChannel) Forwards aPurgeevent downstream.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setNameMethods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGeneratorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SslCodec
Creates a new codec that uses the givenSSLContext.- Parameters:
plainChannel- the component’s channelencryptedChannel- the channel with the encrypted datasslContext- the SSL context to use
-
SslCodec
Creates a new codec to be used as client.- Parameters:
plainChannel- the component’s channelencryptedChannel- the channel with the encrypted datadontValidate- iftrueaccept all kinds of certificates
-
-
Method Details
-
onAccepted
@Handler(channels=org.jgrapes.net.SslCodec.EncryptedChannel.class, excludeSelf=true) public void onAccepted(Accepted event, IOSubchannel encryptedChannel) Creates a new downstream connection asLinkedIOSubchannelof the network connection together with anSSLEngine.- Parameters:
event- the accepted event
-
onOpenConnection
Forward the connection request to the encrypted network.- Parameters:
event- the event
-
onConnected
@Handler(channels=org.jgrapes.net.SslCodec.EncryptedChannel.class, excludeSelf=true) public void onConnected(ClientConnected event, IOSubchannel encryptedChannel) Creates a new downstream connection asLinkedIOSubchannelof the network connection together with anSSLEngine.- Parameters:
event- the accepted event
-
onInput
@Handler(channels=org.jgrapes.net.SslCodec.EncryptedChannel.class, excludeSelf=true) public void onInput(Input<ByteBuffer> event, IOSubchannel encryptedChannel) throws InterruptedException, SSLException, ExecutionException Handles encrypted data from upstream (the network).The data is send through the
SSLEngineand events are sent downstream (and in the initial phases upstream) according to the conversion results.- Parameters:
event- the eventencryptedChannel- the channel for exchanging the encrypted data- Throws:
InterruptedExceptionSSLExceptionExecutionException
-
onHalfClosed
@Handler(channels=org.jgrapes.net.SslCodec.EncryptedChannel.class, excludeSelf=true) public void onHalfClosed(HalfClosed event, IOSubchannel encryptedChannel) throws SSLException, InterruptedException Handles a half close event from the encrypted channel (client).- Parameters:
event- the eventencryptedChannel- the channel for exchanging the encrypted data- Throws:
InterruptedExceptionSSLException
-
onClosed
@Handler(channels=org.jgrapes.net.SslCodec.EncryptedChannel.class, excludeSelf=true) public void onClosed(Closed<Void> event, IOSubchannel encryptedChannel) throws SSLException, InterruptedException Handles a close event from the encrypted channel (client).- Parameters:
event- the eventencryptedChannel- the channel for exchanging the encrypted data- Throws:
InterruptedExceptionSSLException
-
onPurge
@Handler(channels=org.jgrapes.net.SslCodec.EncryptedChannel.class, excludeSelf=true) public void onPurge(Purge event, IOSubchannel encryptedChannel) Forwards aPurgeevent downstream.- Parameters:
event- the eventencryptedChannel- the encrypted channel
-
onIOError
@Handler(channels=org.jgrapes.net.SslCodec.EncryptedChannel.class, excludeSelf=true) public void onIOError(IOError event) throws SSLException, InterruptedException Handles anIOErrorevent from the encrypted channel (client) by sending it downstream.- Parameters:
event- the event- Throws:
SSLException- the SSL exceptionInterruptedException- the interrupted exception
-
onOutput
@Handler public void onOutput(Output<ByteBuffer> event, org.jgrapes.net.SslCodec.PlainChannel plainChannel) throws InterruptedException, SSLException, ExecutionException Sends plain data through the engine and then upstream.- Parameters:
event- the event with the data- Throws:
InterruptedException- if the execution was interruptedSSLException- if some SSL related problem occursExecutionException
-
onClose
@Handler public void onClose(Close event, org.jgrapes.net.SslCodec.PlainChannel plainChannel) throws InterruptedException, SSLException Forwards a close event upstream.- Parameters:
event- the close event- Throws:
SSLException- if an SSL related problem occursInterruptedException- if the execution was interrupted
-