Java Reference
In-Depth Information
.
content
(
message
)
.
dir
(
secret
);
target
.
request
().
post
(
Entity
.
text
(
encrypted
));
}
the RESTEasy
org.jboss.resteasy.jose.jwe.JWEBuilder
class to encrypt the text mes-
sage we want to post to the server. The
JWEBuilder.contentType()
method sets the
cty
header of the JWE. The
content()
method sets the entity we want to encrypt. The
dir()
method first takes the entity and marshals it using a
MessageBodyReader
picked from the
content type and the entity's class. The
dir()
method then generates the JWE based on this
marshalled content and shared secret algorithm. Once we have our JWE-encoded string, we
then post it to the chat server.
One thing to notice is that we have not changed the server at all. The server is a dumb inter-
mediary that just forwards messages from one client to others. It doesn't care about what is
being sent across the wire.
Build and Run the Example Program
You'll need multiple console windows to run this example. In the first console window, per-
form the following steps:
1. Change to the
ex15_2
directory of the workbook example code.
2. Make sure your PATH is set up to include both the JDK and Maven, as described in
3. Perform the build and run the example by typing
maven jetty:run
.
This will start the JAX-RS services for the example.
Open another console window and do the following.
1. Change to the
ex15_2
directory of the workbook example code.
2. Run the chat client by typing
maven exec:java -Dexec.mainClass=ChatClient -
Dexec.args="
your-name your-secret
"
.
Replace
your-name
with your first name and
your-secret
with your shared password.
Repeat this process in yet another console window to run a second chat client. You may also
want to start different chat clients that use different passwords to see what happens.