Java Reference
In-Depth Information
}
The first invocation succeeds, but the second fails because we are allowed to invoke this
method only once per day.
Build and Run the Example Program
Perform the following steps:
1. Open a command prompt or shell terminal and change to the
ex15_1
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 install
.
Example ex15_1: JSON Web Encryption
In
Chapter 15
,
you learned a little bit about JSON Web Encryption (JWE) and how it can be
used to encrypt HTTP message body or header values. This example augments the customer
chat client implemented in
Chapter 27
. Chat clients will use a shared secret to encrypt and
decrypt the messages they send to and receive from the chat server. Chat clients that know
the shared secret see the decrypted message, while clients that don't know it see only the
JWE encoding. Let's take a look at the code:
src/main/java/ChatClient.java
public
public class
class
ChatClient
ChatClient
{
public
public static
static
void
void
main
(
String
[]
args
)
throws
throws
Exception
{
String name
=
args
[
0
];
final
final
String secret
=
args
[
1
];
The
ChatClient
first starts out by storing the name and secret password that the client will
use. It obtains these values from the command line.
final
final
Client client
=
new
new
ResteasyClientBuilder
()
.
connectionPoolSize
(
3
)
.
build
();
WebTarget target
=
client
.
target
(
"http://localhost:8080/services/chat"
);
target
.
request
().
async
().
get
(
new
new
InvocationCallback
<
Response
>()
{
@Override