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
ConstructorDescriptionCreates 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 TypeMethodDescriptionvoid
onAccepted
(Accepted event, IOSubchannel encryptedChannel) Creates a new downstream connection asLinkedIOSubchannel
of the network connection together with anSSLEngine
.void
Forwards a close event upstream.void
onClosed
(Closed<Void> event, IOSubchannel encryptedChannel) Handles a close event from the encrypted channel (client).void
onConnected
(ClientConnected event, IOSubchannel encryptedChannel) Creates a new downstream connection asLinkedIOSubchannel
of the network connection together with anSSLEngine
.void
onHalfClosed
(HalfClosed event, IOSubchannel encryptedChannel) Handles a half close event from the encrypted channel (client).void
onInput
(Input<ByteBuffer> event, IOSubchannel encryptedChannel) Handles encrypted data from upstream (the network).void
Handles anIOError
event from the encrypted channel (client) by sending it downstream.void
Forward the connection request to the encrypted network.void
onOutput
(Output<ByteBuffer> event, org.jgrapes.net.SslCodec.PlainChannel plainChannel) Sends plain data through the engine and then upstream.void
onPurge
(Purge event, IOSubchannel encryptedChannel) Forwards aPurge
event downstream.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods 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, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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
- iftrue
accept 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 asLinkedIOSubchannel
of 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 asLinkedIOSubchannel
of 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
SSLEngine
and 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:
InterruptedException
SSLException
ExecutionException
-
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:
InterruptedException
SSLException
-
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:
InterruptedException
SSLException
-
onPurge
@Handler(channels=org.jgrapes.net.SslCodec.EncryptedChannel.class, excludeSelf=true) public void onPurge(Purge event, IOSubchannel encryptedChannel) Forwards aPurge
event 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 anIOError
event 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
-