public class JsonHttpCommandCodec extends java.lang.Object implements CommandCodec<HttpRequest>
Modifier and Type | Class and Description |
---|---|
private static class |
JsonHttpCommandCodec.CommandSpec |
Modifier and Type | Field and Description |
---|---|
private BeanToJsonConverter |
beanToJsonConverter |
private JsonToBeanConverter |
jsonToBeanConverter |
private com.google.common.collect.BiMap<java.lang.String,JsonHttpCommandCodec.CommandSpec> |
nameToSpec |
private static com.google.common.base.Splitter |
PATH_SPLITTER |
private static java.lang.String |
SESSION_ID_PARAM |
Constructor and Description |
---|
JsonHttpCommandCodec() |
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
buildUri(Command command,
JsonHttpCommandCodec.CommandSpec spec) |
Command |
decode(HttpRequest encodedCommand)
Decodes a command.
|
void |
defineCommand(java.lang.String name,
HttpMethod method,
java.lang.String pathPattern)
Defines a new command mapping.
|
private void |
defineCommand(java.lang.String name,
JsonHttpCommandCodec.CommandSpec spec) |
private static JsonHttpCommandCodec.CommandSpec |
delete(java.lang.String path) |
HttpRequest |
encode(Command command)
Encodes a command.
|
private static JsonHttpCommandCodec.CommandSpec |
get(java.lang.String path) |
private java.lang.String |
getParameter(java.lang.String parameterName,
Command command) |
private static JsonHttpCommandCodec.CommandSpec |
post(java.lang.String path) |
private static final com.google.common.base.Splitter PATH_SPLITTER
private static final java.lang.String SESSION_ID_PARAM
private final com.google.common.collect.BiMap<java.lang.String,JsonHttpCommandCodec.CommandSpec> nameToSpec
private final BeanToJsonConverter beanToJsonConverter
private final JsonToBeanConverter jsonToBeanConverter
public HttpRequest encode(Command command)
CommandCodec
encode
in interface CommandCodec<HttpRequest>
command
- the command to encode.public Command decode(HttpRequest encodedCommand)
CommandCodec
decode
in interface CommandCodec<HttpRequest>
encodedCommand
- the command to decode.public void defineCommand(java.lang.String name, HttpMethod method, java.lang.String pathPattern)
name
- The command name.method
- The HTTP method to use for the command.pathPattern
- The URI path pattern for the command. When encoding a command, each
path segment prefixed with a ":" will be replaced with the corresponding parameter
from the encoded command.private void defineCommand(java.lang.String name, JsonHttpCommandCodec.CommandSpec spec)
private static JsonHttpCommandCodec.CommandSpec delete(java.lang.String path)
private static JsonHttpCommandCodec.CommandSpec get(java.lang.String path)
private static JsonHttpCommandCodec.CommandSpec post(java.lang.String path)
private java.lang.String buildUri(Command command, JsonHttpCommandCodec.CommandSpec spec)
private java.lang.String getParameter(java.lang.String parameterName, Command command)