本文整理匯總了Java中javax.websocket.DecodeException類的典型用法代碼示例。如果您正苦於以下問題:Java DecodeException類的具體用法?Java DecodeException怎麽用?Java DecodeException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DecodeException類屬於javax.websocket包,在下文中一共展示了DecodeException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decode
import javax.websocket.DecodeException; //導入依賴的package包/類
@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;
}
示例2: decode
import javax.websocket.DecodeException; //導入依賴的package包/類
@Override
protected Object decode(String message) throws DecodeException {
// Handle primitives
if (primitiveType != null) {
return Util.coerceToType(primitiveType, message);
}
// Handle full decoders
for (Decoder decoder : decoders) {
if (decoder instanceof Text) {
if (((Text<?>) decoder).willDecode(message)) {
return ((Text<?>) decoder).decode(message);
}
} else {
StringReader r = new StringReader(message);
try {
return ((TextStream<?>) decoder).decode(r);
} catch (IOException ioe) {
throw new DecodeException(message, sm.getString(
"pojoMessageHandlerWhole.decodeIoFail"), ioe);
}
}
}
return null;
}
示例3: decode
import javax.websocket.DecodeException; //導入依賴的package包/類
@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;
}
示例4: decode
import javax.websocket.DecodeException; //導入依賴的package包/類
@Override
protected Object decode(String message) throws DecodeException {
// Handle primitives
if (primitiveType != null) {
return Util.coerceToType(primitiveType, message);
}
// Handle full decoders
for (Decoder decoder : decoders) {
if (decoder instanceof Text) {
if (((Text<?>) decoder).willDecode(message)) {
return ((Text<?>) decoder).decode(message);
}
} else {
StringReader r = new StringReader(message);
try {
return ((TextStream<?>) decoder).decode(r);
} catch (IOException ioe) {
throw new DecodeException(message, sm.getString("pojoMessageHandlerWhole.decodeIoFail"), ioe);
}
}
}
return null;
}
示例5: from_byteBuffer
import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void from_byteBuffer() throws IOException, DecodeException {
final String input = "MESSAGE\ndestination:wonderland\nsubscription:a\ncontent-length:4\n\nbody\u0000";
final Frame frame;
try (InputStream is = new ByteArrayInputStream(input.getBytes())) {
frame = Encoding.from(ByteBuffer.wrap(input.getBytes(UTF_8)));
}
assertEquals(Command.MESSAGE, frame.command());
assertEquals(4, frame.headers().size());
// ensure header order is maintained
final Iterator<Entry<Header, List<String>>> itr = frame.headers().entrySet().iterator();
final Entry<Header, List<String>> header2 = itr.next();
assertEquals("destination", header2.getKey().value());
assertEquals(1, header2.getValue().size());
assertEquals("wonderland", header2.getValue().get(0));
final Entry<Header, List<String>> header1 = itr.next();
assertEquals("subscription", header1.getKey().value());
assertEquals(1, header1.getValue().size());
assertEquals("a", header1.getValue().get(0));
assertEquals(ByteBuffer.wrap("body".getBytes(StandardCharsets.UTF_8)), frame.body().get());
}
示例6: decode
import javax.websocket.DecodeException; //導入依賴的package包/類
/**
* @see javax.websocket.Decoder.Text#decode(String)
* @see javax.websocket.Decoder.Binary#decode(ByteBuffer)
*/
@SuppressWarnings("unchecked")
public T decode(M message) throws DecodeException {
try {
return (T) getConversionService().convert(message, getMessageType(), getType());
}
catch (ConversionException ex) {
if (message instanceof String) {
throw new DecodeException((String) message,
"Unable to decode websocket message using ConversionService", ex);
}
if (message instanceof ByteBuffer) {
throw new DecodeException((ByteBuffer) message,
"Unable to decode websocket message using ConversionService", ex);
}
throw ex;
}
}
示例7: decode
import javax.websocket.DecodeException; //導入依賴的package包/類
@Override
public Message decode(String textMessage) throws DecodeException {
Message msg = null;
JsonObject obj = Json.createReader(new StringReader(textMessage)).
readObject();
try {
DecoderHelper helper = new DecoderHelper(obj);
msg = helper.getMessage();
msg.init(obj);
} catch (ApplicationException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
return msg;
}
示例8: decode
import javax.websocket.DecodeException; //導入依賴的package包/類
/**
* Decodes the message
* @param message
* @return
* @throws DecodeException
*/
@Override
public AbstractCommand decode(String message) throws DecodeException {
logger.log(Level.INFO, "Decoding: {0}", message);
JsonObject struct;
try (JsonReader rdr = Json.createReader(new StringReader(message))) {
struct = rdr.readObject();
}
String type = struct.getString("type");
CommandTypes cmdType = CommandTypes.valueOf(type);
try {
AbstractCommand cmd = (AbstractCommand)cmdType.getCommandClass().newInstance();
cmd.decode(struct);
return cmd;
} catch (InstantiationException | IllegalAccessException ex) {
Logger.getLogger(CommandMessageDecoder.class.getName()).log(Level.SEVERE, null, ex);
throw new DecodeException(message,"Could not be decoded - invalid type.");
}
}
示例9: testReadyNoSavedRoom
import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void testReadyNoSavedRoom(@Mocked RoomMediator room) throws DecodeException {
ClientMediator mediator = new ClientMediator(nexus, drain, userId, signedJwt);
String msgTxt = "ready,{}";
RoutedMessage message = new RoutedMessage(msgTxt);
System.out.println(message);
new Expectations() {{
nexus.join(mediator, null, "");
}};
mediator.ready(message);
new Verifications() {{
nexus.join(mediator, null, ""); times = 1;
drain.send((RoutedMessage) any); times = 0;
}};
}
示例10: testReadyUserName
import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void testReadyUserName(@Mocked RoomMediator room) throws DecodeException {
ClientMediator mediator = new ClientMediator(nexus, drain, userId, signedJwt);
String msgTxt = "ready,{\"username\":\"TinyJamFilledMuffin\"}";
RoutedMessage message = new RoutedMessage(msgTxt);
System.out.println(message);
new Expectations() {{
nexus.join(mediator, null, "");
}};
mediator.ready(message);
new Verifications() {{
nexus.join(mediator, null, ""); times = 1;
drain.send((RoutedMessage) any); times = 0;
}};
}
示例11: testReadyZeroBookmark
import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void testReadyZeroBookmark(@Mocked RoomMediator room) throws DecodeException {
ClientMediator mediator = new ClientMediator(nexus, drain, userId, signedJwt);
String msgTxt = "ready,{\"bookmark\":0}";
RoutedMessage message = new RoutedMessage(msgTxt);
System.out.println(message);
new Expectations() {{
nexus.join(mediator, null, "0");
}};
mediator.ready(message);
new Verifications() {{
nexus.join(mediator, null, "0"); times = 1;
drain.send((RoutedMessage) any); times = 0;
}};
}
示例12: testReadySavedRoom
import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void testReadySavedRoom(@Mocked RoomMediator room) throws DecodeException {
ClientMediator mediator = new ClientMediator(nexus, drain, userId, signedJwt);
String msgTxt = "ready,{\"roomId\": \"roomId\",\"bookmark\": \"id\"}";
RoutedMessage message = new RoutedMessage(msgTxt);
System.out.println(message);
new Expectations() {{
nexus.join(mediator, roomId, "id");
}};
mediator.ready(message);
new Verifications() {{
nexus.join(mediator, roomId, "id"); times = 1;
drain.send((RoutedMessage) any); times = 0;
}};
}
示例13: decode
import javax.websocket.DecodeException; //導入依賴的package包/類
@Override
public WebSocketMessage decode(ByteBuffer buffer) throws DecodeException {
try {
MessageProtos.Message decMsg =
MessageProtos.Message.parseFrom(buffer.array());
WebSocketMessage msg = new WebSocketMessage()
.withEvent(decMsg.getEvent())
.withChannel(decMsg.getChannel())
.withFrom(decMsg.getFrom())
.withId(decMsg.getId())
.withPayload(decMsg.getData().toByteArray());
return msg;
}
catch (IOException e) {
throw new DecodeException(buffer, "Error parsing buffer.", e);
}
}
示例14: shouldParseBasicObject
import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void shouldParseBasicObject() throws DecodeException {
// given
String validJson = "{'from' : 'Alice',"//
+ "'to' : 'Bob',"//
+ "'signal' : 'join',"//
+ "'content' : 'something'}";
// when
Message result = decoder.decode(validJson);
// then
assertNotNull(result);
assertThat(result.getFrom(), is("Alice"));
assertThat(result.getTo(), is("Bob"));
assertThat(result.getSignal(), is("join"));
assertThat(result.getContent(), is("something"));
}
示例15: shouldParseAlmostEmptyObject
import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void shouldParseAlmostEmptyObject() throws DecodeException {
// given
String validJson = "{'signal' : 'join',"//
+ "'content' : 'something'}";
// when
Message result = decoder.decode(validJson);
// then
assertNotNull(result);
assertThat(result.getFrom(), is(EMPTY));
assertThat(result.getTo(), is(EMPTY));
assertThat(result.getSignal(), is("join"));
assertThat(result.getContent(), is("something"));
}