use of javax.websocket.DecodeException in project tomcat by apache.
the class PojoMessageHandlerWholeBinary method decode.
@Override
protected Object decode(ByteBuffer message) throws DecodeException {
for (Decoder decoder : decoders) {
if (decoder instanceof Binary) {
if (((Binary<?>) decoder).willDecode(message)) {
return ((Binary<?>) decoder).decode(message);
}
} else {
byte[] array = new byte[message.limit() - message.position()];
message.get(array);
ByteArrayInputStream bais = new ByteArrayInputStream(array);
try {
return ((BinaryStream<?>) decoder).decode(bais);
} catch (IOException ioe) {
throw new DecodeException(message, sm.getString("pojoMessageHandlerWhole.decodeIoFail"), ioe);
}
}
}
return null;
}
use of javax.websocket.DecodeException in project jetty.project by eclipse.
the class BinaryWholeMessage method messageComplete.
@SuppressWarnings("unchecked")
@Override
public void messageComplete() {
super.finished = true;
byte[] data = out.toByteArray();
DecoderFactory.Wrapper decoder = msgWrapper.getDecoder();
Decoder.Binary<Object> binaryDecoder = (Binary<Object>) decoder.getDecoder();
try {
Object obj = binaryDecoder.decode(BufferUtil.toBuffer(data));
wholeHandler.onMessage(obj);
} catch (DecodeException e) {
throw new WebSocketException("Unable to decode binary data", e);
}
}
use of javax.websocket.DecodeException in project jetty.project by eclipse.
the class BadDualDecoder method decode.
@Override
public Fruit decode(String s) throws DecodeException {
Pattern pat = Pattern.compile("([^|]*)|([^|]*)");
Matcher mat = pat.matcher(s);
if (!mat.find()) {
throw new DecodeException(s, "Unable to find Fruit reference encoded in text message");
}
Fruit fruit = new Fruit();
fruit.name = mat.group(1);
fruit.color = mat.group(2);
return fruit;
}
use of javax.websocket.DecodeException in project jetty.project by eclipse.
the class JsrCallable method init.
public void init(JsrSession session) {
// Default for the session.
// Session is an optional parameter (always)
idxSession = findIndexForRole(Param.Role.SESSION);
if (idxSession >= 0) {
args[idxSession] = session;
}
// Optional EndpointConfig
idxConfig = findIndexForRole(Param.Role.ENDPOINT_CONFIG);
if (idxConfig >= 0) {
args[idxConfig] = session.getEndpointConfig();
}
// Default for the path parameters
// PathParam's are optional parameters (always)
Map<String, String> pathParams = session.getPathParameters();
if ((pathParams != null) && (pathParams.size() > 0)) {
for (Param param : params) {
if (param.role == Role.PATH_PARAM) {
int idx = param.index;
String rawvalue = pathParams.get(param.getPathParamName());
Decoder decoder = session.getDecoderFactory().getDecoderFor(param.type);
if (decoder instanceof Decoder.Text<?>) {
Decoder.Text<?> textDecoder = (Decoder.Text<?>) decoder;
try {
args[idx] = textDecoder.decode(rawvalue);
} catch (DecodeException e) {
session.notifyError(e);
}
} else {
throw new InvalidWebSocketException("PathParam decoders must use Decoder.Text");
}
}
}
}
}
use of javax.websocket.DecodeException in project jetty.project by eclipse.
the class TextWholeMessage method messageComplete.
@SuppressWarnings("unchecked")
@Override
public void messageComplete() {
finished = true;
DecoderFactory.Wrapper decoder = msgWrapper.getDecoder();
Decoder.Text<Object> textDecoder = (Decoder.Text<Object>) decoder.getDecoder();
try {
Object obj = textDecoder.decode(utf.toString());
wholeHandler.onMessage(obj);
} catch (DecodeException e) {
throw new WebSocketException("Unable to decode text data", e);
}
}
Aggregations