target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void testToString() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("stringParam", String.class); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, null)).isNull(); assertThat(this.invocableHandlerMethod.convert(param, "str")).isEqualTo("str"); assertThat(this.invocableHandlerMethod.convert(param, (byte) 1)).isEqualTo("1"); assertThat(this.invocableHandlerMethod.convert(param, (short) 2)).isEqualTo("2"); assertThat(this.invocableHandlerMethod.convert(param, 3)).isEqualTo("3"); assertThat(this.invocableHandlerMethod.convert(param, 4L)).isEqualTo("4"); assertThat(this.invocableHandlerMethod.convert(param, 5.5f)).isEqualTo("5.5"); assertThat(this.invocableHandlerMethod.convert(param, 6.6)).isEqualTo("6.6"); assertThat(this.invocableHandlerMethod.convert(param, new BigDecimal("3.141"))) .isEqualTo("3.141"); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void testNewRandomId() { assertThat(IdGenerator.newRandomId(null)).isBetween(IdGenerator.MIN, IdGenerator.MAX); Set<Long> ids = new HashSet<>(); ids.add(1L); assertThat(IdGenerator.newRandomId(ids)).isBetween(IdGenerator.MIN, IdGenerator.MAX); }
public static long newRandomId(@Nullable Set<Long> existingIds) { while (true) { long candidateId = ThreadLocalRandom.current().nextLong(); if (MIN <= candidateId && candidateId <= MAX) { if (existingIds == null) { return candidateId; } if (!existingIds.contains(candidateId)) { return candidateId; } } } }
IdGenerator { public static long newRandomId(@Nullable Set<Long> existingIds) { while (true) { long candidateId = ThreadLocalRandom.current().nextLong(); if (MIN <= candidateId && candidateId <= MAX) { if (existingIds == null) { return candidateId; } if (!existingIds.contains(candidateId)) { return candidateId; } } } } }
IdGenerator { public static long newRandomId(@Nullable Set<Long> existingIds) { while (true) { long candidateId = ThreadLocalRandom.current().nextLong(); if (MIN <= candidateId && candidateId <= MAX) { if (existingIds == null) { return candidateId; } if (!existingIds.contains(candidateId)) { return candidateId; } } } } }
IdGenerator { public static long newRandomId(@Nullable Set<Long> existingIds) { while (true) { long candidateId = ThreadLocalRandom.current().nextLong(); if (MIN <= candidateId && candidateId <= MAX) { if (existingIds == null) { return candidateId; } if (!existingIds.contains(candidateId)) { return candidateId; } } } } static long newRandomId(@Nullable Set<Long> existingIds); static long newLinearId(AtomicLong longValue); }
IdGenerator { public static long newRandomId(@Nullable Set<Long> existingIds) { while (true) { long candidateId = ThreadLocalRandom.current().nextLong(); if (MIN <= candidateId && candidateId <= MAX) { if (existingIds == null) { return candidateId; } if (!existingIds.contains(candidateId)) { return candidateId; } } } } static long newRandomId(@Nullable Set<Long> existingIds); static long newLinearId(AtomicLong longValue); static final long MIN; static final long MAX; }
@Test public void testNewLinearId() { AtomicLong id = new AtomicLong(0); assertThat(IdGenerator.newLinearId(id)).isEqualTo(1); assertThat(IdGenerator.newLinearId(id)).isEqualTo(2); id.set(IdGenerator.MAX - 1L); assertThat(IdGenerator.newLinearId(id)).isEqualTo(IdGenerator.MAX); assertThat(IdGenerator.newLinearId(id)).isEqualTo(1L); }
public static long newLinearId(AtomicLong longValue) { long candiateId = longValue.incrementAndGet(); if (candiateId > IdGenerator.MAX) { longValue.set(1L); candiateId = longValue.longValue(); } return candiateId; }
IdGenerator { public static long newLinearId(AtomicLong longValue) { long candiateId = longValue.incrementAndGet(); if (candiateId > IdGenerator.MAX) { longValue.set(1L); candiateId = longValue.longValue(); } return candiateId; } }
IdGenerator { public static long newLinearId(AtomicLong longValue) { long candiateId = longValue.incrementAndGet(); if (candiateId > IdGenerator.MAX) { longValue.set(1L); candiateId = longValue.longValue(); } return candiateId; } }
IdGenerator { public static long newLinearId(AtomicLong longValue) { long candiateId = longValue.incrementAndGet(); if (candiateId > IdGenerator.MAX) { longValue.set(1L); candiateId = longValue.longValue(); } return candiateId; } static long newRandomId(@Nullable Set<Long> existingIds); static long newLinearId(AtomicLong longValue); }
IdGenerator { public static long newLinearId(AtomicLong longValue) { long candiateId = longValue.incrementAndGet(); if (candiateId > IdGenerator.MAX) { longValue.set(1L); candiateId = longValue.longValue(); } return candiateId; } static long newRandomId(@Nullable Set<Long> existingIds); static long newLinearId(AtomicLong longValue); static final long MIN; static final long MAX; }
@Test public void testToListTArray() { assertThat(CollectionHelper.toList()).isNull(); assertThat(CollectionHelper.toList(1)).isInstanceOf(List.class) .containsExactly(1); assertThat(CollectionHelper.toList(1, 2, 3)).isInstanceOf(List.class) .containsExactly(1, 2, 3); }
@SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; }
CollectionHelper { @SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; } }
CollectionHelper { @SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; } }
CollectionHelper { @SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; } @SafeVarargs @Nullable static List<T> toList(@Nullable T... arguments); @SuppressWarnings("unchecked") @Nullable static List<Object> toList(@Nullable Collection<T> collection); @Nullable static Set<Long> toSet(@Nullable Collection<Long> collection); }
CollectionHelper { @SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; } @SafeVarargs @Nullable static List<T> toList(@Nullable T... arguments); @SuppressWarnings("unchecked") @Nullable static List<Object> toList(@Nullable Collection<T> collection); @Nullable static Set<Long> toSet(@Nullable Collection<Long> collection); }
@Test public void testToListCollectionOfT() { assertThat(CollectionHelper.toList((List<String>) null)).isNull(); assertThat(CollectionHelper.toList(Arrays.asList(1))).isInstanceOf(List.class) .containsExactly(1); assertThat(CollectionHelper.toList(Arrays.asList(1, 2, 3))) .isInstanceOf(List.class).containsExactly(1, 2, 3); Set<Long> set = new HashSet<>(); set.add(11L); set.add(22L); assertThat(CollectionHelper.toList(set)).isInstanceOf(List.class) .containsOnly(11L, 22L); }
@SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; }
CollectionHelper { @SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; } }
CollectionHelper { @SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; } }
CollectionHelper { @SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; } @SafeVarargs @Nullable static List<T> toList(@Nullable T... arguments); @SuppressWarnings("unchecked") @Nullable static List<Object> toList(@Nullable Collection<T> collection); @Nullable static Set<Long> toSet(@Nullable Collection<Long> collection); }
CollectionHelper { @SafeVarargs @Nullable public static <T> List<T> toList(@Nullable T... arguments) { if (arguments != null) { if (arguments.length == 1) { return Collections.singletonList(arguments[0]); } if (arguments.length > 1) { return Arrays.asList(arguments); } } return null; } @SafeVarargs @Nullable static List<T> toList(@Nullable T... arguments); @SuppressWarnings("unchecked") @Nullable static List<Object> toList(@Nullable Collection<T> collection); @Nullable static Set<Long> toSet(@Nullable Collection<Long> collection); }
@Test public void testToSet() { assertThat(CollectionHelper.toSet((Set<Long>) null)).isNull(); Set<Long> set = new HashSet<>(); set.add(33L); set.add(44L); assertThat(CollectionHelper.toSet(set)).isInstanceOf(Set.class).containsOnly(33L, 44L); assertThat(CollectionHelper.toSet(Arrays.asList(1L))).isInstanceOf(Set.class) .containsExactly(1L); assertThat(CollectionHelper.toSet(Arrays.asList(1L, 2L, 3L))) .isInstanceOf(Set.class).containsExactly(1L, 2L, 3L); }
@Nullable public static Set<Long> toSet(@Nullable Collection<Long> collection) { if (collection != null) { if (collection instanceof Set) { return (Set<Long>) collection; } return new HashSet<>(collection); } return null; }
CollectionHelper { @Nullable public static Set<Long> toSet(@Nullable Collection<Long> collection) { if (collection != null) { if (collection instanceof Set) { return (Set<Long>) collection; } return new HashSet<>(collection); } return null; } }
CollectionHelper { @Nullable public static Set<Long> toSet(@Nullable Collection<Long> collection) { if (collection != null) { if (collection instanceof Set) { return (Set<Long>) collection; } return new HashSet<>(collection); } return null; } }
CollectionHelper { @Nullable public static Set<Long> toSet(@Nullable Collection<Long> collection) { if (collection != null) { if (collection instanceof Set) { return (Set<Long>) collection; } return new HashSet<>(collection); } return null; } @SafeVarargs @Nullable static List<T> toList(@Nullable T... arguments); @SuppressWarnings("unchecked") @Nullable static List<Object> toList(@Nullable Collection<T> collection); @Nullable static Set<Long> toSet(@Nullable Collection<Long> collection); }
CollectionHelper { @Nullable public static Set<Long> toSet(@Nullable Collection<Long> collection) { if (collection != null) { if (collection instanceof Set) { return (Set<Long>) collection; } return new HashSet<>(collection); } return null; } @SafeVarargs @Nullable static List<T> toList(@Nullable T... arguments); @SuppressWarnings("unchecked") @Nullable static List<Object> toList(@Nullable Collection<T> collection); @Nullable static Set<Long> toSet(@Nullable Collection<Long> collection); }
@Test public void serializeTest() { InvocationMessage invocationMessage = new InvocationMessage(111, 1, null, null, null); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(111); assertThat(invocationMessage.getRegistrationId()).isEqualTo(1); assertThat(invocationMessage.getCaller()).isNull(); assertThat(invocationMessage.getArguments()).isNull(); assertThat(invocationMessage.getArgumentsKw()).isNull(); String json = serializeToJson(invocationMessage); assertThat(json).isEqualTo("[68,111,1,{}]"); invocationMessage = new InvocationMessage(1, 111, null, Arrays.asList("Hello world"), null); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(1); assertThat(invocationMessage.getRegistrationId()).isEqualTo(111); assertThat(invocationMessage.getCaller()).isNull(); assertThat(invocationMessage.getArguments()).containsExactly("Hello world"); assertThat(invocationMessage.getArgumentsKw()).isNull(); json = serializeToJson(invocationMessage); assertThat(json).isEqualTo("[68,1,111,{},[\"Hello world\"]]"); Map<String, Object> argumentsKw = new HashMap<>(); argumentsKw.put("firstname", "John"); argumentsKw.put("surname", "Doe"); invocationMessage = new InvocationMessage(1, 111, null, Arrays.asList("johnny"), argumentsKw); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(1); assertThat(invocationMessage.getRegistrationId()).isEqualTo(111); assertThat(invocationMessage.getCaller()).isNull(); assertThat(invocationMessage.getArguments()).containsExactly("johnny"); assertThat(invocationMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = serializeToJson(invocationMessage); assertThat(json).isEqualTo( "[68,1,111,{},[\"johnny\"],{\"firstname\":\"John\",\"surname\":\"Doe\"}]"); invocationMessage = new InvocationMessage(1, 111, 17218L, Arrays.asList("Hello world"), null); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(1); assertThat(invocationMessage.getRegistrationId()).isEqualTo(111); assertThat(invocationMessage.getCaller()).isEqualTo(17218L); assertThat(invocationMessage.getArguments()).containsExactly("Hello world"); assertThat(invocationMessage.getArgumentsKw()).isNull(); json = serializeToJson(invocationMessage); assertThat(json).isEqualTo("[68,1,111,{\"caller\":17218},[\"Hello world\"]]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); generator.writeStartObject(); if (this.caller != null) { generator.writeNumberField("caller", this.caller.longValue()); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } }
InvocationMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); generator.writeStartObject(); if (this.caller != null) { generator.writeNumberField("caller", this.caller.longValue()); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } }
InvocationMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); generator.writeStartObject(); if (this.caller != null) { generator.writeNumberField("caller", this.caller.longValue()); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } InvocationMessage(long requestId, long registrationId, @Nullable Number caller, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); InvocationMessage(Procedure procedure, CallMessage callMessage); }
InvocationMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); generator.writeStartObject(); if (this.caller != null) { generator.writeNumberField("caller", this.caller.longValue()); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } InvocationMessage(long requestId, long registrationId, @Nullable Number caller, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); InvocationMessage(Procedure procedure, CallMessage callMessage); static InvocationMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Number getCaller(); @Override String toString(); }
InvocationMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); generator.writeStartObject(); if (this.caller != null) { generator.writeNumberField("caller", this.caller.longValue()); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } InvocationMessage(long requestId, long registrationId, @Nullable Number caller, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); InvocationMessage(Procedure procedure, CallMessage callMessage); static InvocationMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Number getCaller(); @Override String toString(); static final int CODE; }
@Test public void deserializeTest() throws IOException { String json = "[68, 6131533, 9823526, {}]"; InvocationMessage invocationMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(6131533L); assertThat(invocationMessage.getRegistrationId()).isEqualTo(9823526L); assertThat(invocationMessage.getCaller()).isNull(); assertThat(invocationMessage.getArguments()).isNull(); assertThat(invocationMessage.getArgumentsKw()).isNull(); json = "[68, 6131533, 9823527, {}, [\"Hello, world!\"]]"; invocationMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(6131533L); assertThat(invocationMessage.getRegistrationId()).isEqualTo(9823527L); assertThat(invocationMessage.getCaller()).isNull(); assertThat(invocationMessage.getArguments()).containsExactly("Hello, world!"); assertThat(invocationMessage.getArgumentsKw()).isNull(); json = "[68, 6131533, 9823528, {}, [23, 7]]"; invocationMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(6131533L); assertThat(invocationMessage.getRegistrationId()).isEqualTo(9823528L); assertThat(invocationMessage.getCaller()).isNull(); assertThat(invocationMessage.getArguments()).containsExactly(23, 7); assertThat(invocationMessage.getArgumentsKw()).isNull(); json = "[68, 6131533, 9823529, {}, [\"johnny\"], {\"firstname\": \"John\",\"surname\": \"Doe\"}]"; invocationMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(6131533L); assertThat(invocationMessage.getRegistrationId()).isEqualTo(9823529L); assertThat(invocationMessage.getCaller()).isNull(); assertThat(invocationMessage.getArguments()).containsExactly("johnny"); assertThat(invocationMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = "[68, 6131533, 9823528, {\"caller\": 3335656}, [23, 7]]"; invocationMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(invocationMessage.getCode()).isEqualTo(68); assertThat(invocationMessage.getRequestId()).isEqualTo(6131533L); assertThat(invocationMessage.getRegistrationId()).isEqualTo(9823528L); assertThat(invocationMessage.getCaller()).isEqualTo(3335656); assertThat(invocationMessage.getArguments()).containsExactly(23, 7); assertThat(invocationMessage.getArgumentsKw()).isNull(); }
public static InvocationMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); jp.nextToken(); Number caller = null; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { caller = (Number) details.get("caller"); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new InvocationMessage(request, registration, caller, arguments, argumentsKw); }
InvocationMessage extends WampMessage { public static InvocationMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); jp.nextToken(); Number caller = null; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { caller = (Number) details.get("caller"); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new InvocationMessage(request, registration, caller, arguments, argumentsKw); } }
InvocationMessage extends WampMessage { public static InvocationMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); jp.nextToken(); Number caller = null; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { caller = (Number) details.get("caller"); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new InvocationMessage(request, registration, caller, arguments, argumentsKw); } InvocationMessage(long requestId, long registrationId, @Nullable Number caller, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); InvocationMessage(Procedure procedure, CallMessage callMessage); }
InvocationMessage extends WampMessage { public static InvocationMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); jp.nextToken(); Number caller = null; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { caller = (Number) details.get("caller"); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new InvocationMessage(request, registration, caller, arguments, argumentsKw); } InvocationMessage(long requestId, long registrationId, @Nullable Number caller, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); InvocationMessage(Procedure procedure, CallMessage callMessage); static InvocationMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Number getCaller(); @Override String toString(); }
InvocationMessage extends WampMessage { public static InvocationMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); jp.nextToken(); Number caller = null; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { caller = (Number) details.get("caller"); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new InvocationMessage(request, registration, caller, arguments, argumentsKw); } InvocationMessage(long requestId, long registrationId, @Nullable Number caller, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); InvocationMessage(Procedure procedure, CallMessage callMessage); static InvocationMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Number getCaller(); @Override String toString(); static final int CODE; }
@Test public void serializeTest() { CallMessage callMessage = new CallMessage(1, "call"); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(1); assertThat(callMessage.getProcedure()).isEqualTo("call"); assertThat(callMessage.isDiscloseMe()).isFalse(); assertThat(callMessage.getArguments()).isNull(); assertThat(callMessage.getArgumentsKw()).isNull(); String json = serializeToJson(callMessage); assertThat(json).isEqualTo("[48,1,{},\"call\"]"); callMessage = new CallMessage(1, "call", Arrays.asList("Hello world")); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(1); assertThat(callMessage.getProcedure()).isEqualTo("call"); assertThat(callMessage.isDiscloseMe()).isFalse(); assertThat(callMessage.getArguments()).containsExactly("Hello world"); assertThat(callMessage.getArgumentsKw()).isNull(); json = serializeToJson(callMessage); assertThat(json).isEqualTo("[48,1,{},\"call\",[\"Hello world\"]]"); Map<String, Object> argumentsKw = new HashMap<>(); argumentsKw.put("firstname", "John"); argumentsKw.put("surname", "Doe"); callMessage = new CallMessage(1, "call", Arrays.asList("johnny"), argumentsKw, false); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(1); assertThat(callMessage.getProcedure()).isEqualTo("call"); assertThat(callMessage.isDiscloseMe()).isFalse(); assertThat(callMessage.getArguments()).containsExactly("johnny"); assertThat(callMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = serializeToJson(callMessage); assertThat(json).isEqualTo( "[48,1,{},\"call\",[\"johnny\"],{\"firstname\":\"John\",\"surname\":\"Doe\"}]"); callMessage = new CallMessage(1, "call", Arrays.asList("Hello world"), null, true); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(1); assertThat(callMessage.getProcedure()).isEqualTo("call"); assertThat(callMessage.isDiscloseMe()).isTrue(); assertThat(callMessage.getArguments()).containsExactly("Hello world"); assertThat(callMessage.getArgumentsKw()).isNull(); json = serializeToJson(callMessage); assertThat(json) .isEqualTo("[48,1,{\"disclose_me\":true},\"call\",[\"Hello world\"]]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } generator.writeEndObject(); generator.writeString(this.procedure); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } }
CallMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } generator.writeEndObject(); generator.writeString(this.procedure); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } }
CallMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } generator.writeEndObject(); generator.writeString(this.procedure); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } CallMessage(long request, String procedure); CallMessage(long request, String procedure, @Nullable List<Object> arguments); CallMessage(long request, String procedure, @Nullable Map<String, Object> argumentsKw); CallMessage(long requestId, String procedure, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean discloseMe); }
CallMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } generator.writeEndObject(); generator.writeString(this.procedure); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } CallMessage(long request, String procedure); CallMessage(long request, String procedure, @Nullable List<Object> arguments); CallMessage(long request, String procedure, @Nullable Map<String, Object> argumentsKw); CallMessage(long requestId, String procedure, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean discloseMe); static CallMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); String getProcedure(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); boolean isDiscloseMe(); @Override String toString(); }
CallMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } generator.writeEndObject(); generator.writeString(this.procedure); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } CallMessage(long request, String procedure); CallMessage(long request, String procedure, @Nullable List<Object> arguments); CallMessage(long request, String procedure, @Nullable Map<String, Object> argumentsKw); CallMessage(long requestId, String procedure, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean discloseMe); static CallMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); String getProcedure(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); boolean isDiscloseMe(); @Override String toString(); static final int CODE; }
@Test public void deserializeTest() throws IOException { String json = "[48, 7814135, {}, \"com.myapp.ping\"]"; CallMessage callMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(7814135L); assertThat(callMessage.getProcedure()).isEqualTo("com.myapp.ping"); assertThat(callMessage.isDiscloseMe()).isFalse(); assertThat(callMessage.getArguments()).isNull(); assertThat(callMessage.getArgumentsKw()).isNull(); json = " [48, 7814135, {}, \"com.myapp.echo\", [\"Hello, world!\"]]"; callMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(7814135L); assertThat(callMessage.getProcedure()).isEqualTo("com.myapp.echo"); assertThat(callMessage.isDiscloseMe()).isFalse(); assertThat(callMessage.getArguments()).containsExactly("Hello, world!"); assertThat(callMessage.getArgumentsKw()).isNull(); json = "[48, 7814135, {}, \"com.myapp.add2\", [23, 7]]"; callMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(7814135L); assertThat(callMessage.getProcedure()).isEqualTo("com.myapp.add2"); assertThat(callMessage.isDiscloseMe()).isFalse(); assertThat(callMessage.getArguments()).containsExactly(23, 7); assertThat(callMessage.getArgumentsKw()).isNull(); json = "[48, 7814135, {}, \"com.myapp.user.new\", [\"johnny\"],{\"firstname\": \"John\", \"surname\": \"Doe\"}]"; callMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(7814135L); assertThat(callMessage.getProcedure()).isEqualTo("com.myapp.user.new"); assertThat(callMessage.isDiscloseMe()).isFalse(); assertThat(callMessage.getArguments()).containsExactly("johnny"); assertThat(callMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = "[48, 7814135, {\"disclose_me\":true}, \"com.myapp.add2\", [23, 7]]"; callMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(callMessage.getCode()).isEqualTo(48); assertThat(callMessage.getRequestId()).isEqualTo(7814135L); assertThat(callMessage.getProcedure()).isEqualTo("com.myapp.add2"); assertThat(callMessage.isDiscloseMe()).isTrue(); assertThat(callMessage.getArguments()).containsExactly(23, 7); assertThat(callMessage.getArgumentsKw()).isNull(); }
public static CallMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseMe = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseMe = (boolean) options.getOrDefault("disclose_me", false); } jp.nextToken(); String procedure = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new CallMessage(request, procedure, arguments, argumentsKw, discloseMe); }
CallMessage extends WampMessage { public static CallMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseMe = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseMe = (boolean) options.getOrDefault("disclose_me", false); } jp.nextToken(); String procedure = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new CallMessage(request, procedure, arguments, argumentsKw, discloseMe); } }
CallMessage extends WampMessage { public static CallMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseMe = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseMe = (boolean) options.getOrDefault("disclose_me", false); } jp.nextToken(); String procedure = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new CallMessage(request, procedure, arguments, argumentsKw, discloseMe); } CallMessage(long request, String procedure); CallMessage(long request, String procedure, @Nullable List<Object> arguments); CallMessage(long request, String procedure, @Nullable Map<String, Object> argumentsKw); CallMessage(long requestId, String procedure, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean discloseMe); }
CallMessage extends WampMessage { public static CallMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseMe = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseMe = (boolean) options.getOrDefault("disclose_me", false); } jp.nextToken(); String procedure = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new CallMessage(request, procedure, arguments, argumentsKw, discloseMe); } CallMessage(long request, String procedure); CallMessage(long request, String procedure, @Nullable List<Object> arguments); CallMessage(long request, String procedure, @Nullable Map<String, Object> argumentsKw); CallMessage(long requestId, String procedure, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean discloseMe); static CallMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); String getProcedure(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); boolean isDiscloseMe(); @Override String toString(); }
CallMessage extends WampMessage { public static CallMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseMe = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseMe = (boolean) options.getOrDefault("disclose_me", false); } jp.nextToken(); String procedure = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new CallMessage(request, procedure, arguments, argumentsKw, discloseMe); } CallMessage(long request, String procedure); CallMessage(long request, String procedure, @Nullable List<Object> arguments); CallMessage(long request, String procedure, @Nullable Map<String, Object> argumentsKw); CallMessage(long requestId, String procedure, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean discloseMe); static CallMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); String getProcedure(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); boolean isDiscloseMe(); @Override String toString(); static final int CODE; }
@Test public void serializeTest() { PublishMessage publishMessage = PublishMessage.builder(1, "topic").build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(1); assertThat(publishMessage.getTopic()).isEqualTo("topic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).isNull(); assertThat(publishMessage.getArgumentsKw()).isNull(); String json = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,1,{},\"topic\"]"); publishMessage = PublishMessage.builder(1, "topic") .arguments(Arrays.asList("abc", 23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(1); assertThat(publishMessage.getTopic()).isEqualTo("topic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly("abc", 23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,1,{},\"topic\",[\"abc\",23]]"); publishMessage = PublishMessage.builder(1, "topic") .arguments(Collections.singletonMap("colors", "blue")).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(1); assertThat(publishMessage.getTopic()).isEqualTo("topic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).isNull(); assertThat(publishMessage.getArgumentsKw()) .containsExactly(MapEntry.entry("colors", "blue")); json = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,1,{},\"topic\",[],{\"colors\":\"blue\"}]"); publishMessage = PublishMessage.builder(2, "event").discloseMe() .arguments(Arrays.asList(23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isTrue(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,2,{\"disclose_me\":true},\"event\",[23]]"); publishMessage = PublishMessage.builder(2, "event").retain() .arguments(Arrays.asList(23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isTrue(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,2,{\"retain\":true},\"event\",[23]]"); publishMessage = PublishMessage.builder(2, "event").notExcludeMe().acknowledge() .arguments(Arrays.asList(23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isTrue(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isFalse(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = serializeToJson(publishMessage); assertThat(json).isEqualTo( "[16,2,{\"acknowledge\":true,\"exclude_me\":false},\"event\",[23]]"); publishMessage = PublishMessage.builder(2, "event").eligible(toSet(2L, 3L)) .exclude(toSet(7891255L, 1245751L)).arguments(Arrays.asList(23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); assertThat(publishMessage.getEligible()).containsOnly(2L, 3L); assertThat(publishMessage.getExclude()).containsOnly(7891255L, 1245751L); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = serializeToJson(publishMessage); assertThat(json).isEqualTo( "[16,2,{\"exclude\":[1245751,7891255],\"eligible\":[2,3]},\"event\",[23]]"); publishMessage = PublishMessage.builder(2, "event").addEligible(2).addEligible(3) .addExclude(7891255).addExclude(1245751).addArgument(23) .addArgument("color", "green").build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); assertThat(publishMessage.getEligible()).containsOnly(2, 3); assertThat(publishMessage.getExclude()).containsOnly(7891255, 1245751); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()) .containsExactly(MapEntry.entry("color", "green")); json = serializeToJson(publishMessage); assertThat(json).isEqualTo( "[16,2,{\"exclude\":[1245751,7891255],\"eligible\":[2,3]},\"event\",[23],{\"color\":\"green\"}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } }
PublishMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } }
PublishMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } private PublishMessage(long requestId, String topic, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean acknowledge, boolean excludeMe, boolean discloseMe, boolean retain, @Nullable Set<Number> exclude, @Nullable Set<Number> eligible); PublishMessage(Builder builder); }
PublishMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } private PublishMessage(long requestId, String topic, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean acknowledge, boolean excludeMe, boolean discloseMe, boolean retain, @Nullable Set<Number> exclude, @Nullable Set<Number> eligible); PublishMessage(Builder builder); static Builder builder(long requestId, String topic); @SuppressWarnings("unchecked") static PublishMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); boolean isAcknowledge(); boolean isExcludeMe(); boolean isDiscloseMe(); boolean isRetain(); String getTopic(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Set<Number> getExclude(); @Nullable Set<Number> getEligible(); @Override String toString(); }
PublishMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } private PublishMessage(long requestId, String topic, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean acknowledge, boolean excludeMe, boolean discloseMe, boolean retain, @Nullable Set<Number> exclude, @Nullable Set<Number> eligible); PublishMessage(Builder builder); static Builder builder(long requestId, String topic); @SuppressWarnings("unchecked") static PublishMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); boolean isAcknowledge(); boolean isExcludeMe(); boolean isDiscloseMe(); boolean isRetain(); String getTopic(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Set<Number> getExclude(); @Nullable Set<Number> getEligible(); @Override String toString(); static final int CODE; }
@Test public void testToint() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("intParam", Integer.TYPE); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, null)).isNull(); assertThat(this.invocableHandlerMethod.convert(param, (byte) 1)).isEqualTo(1); assertThat(this.invocableHandlerMethod.convert(param, (short) 2)).isEqualTo(2); assertThat(this.invocableHandlerMethod.convert(param, 3)).isEqualTo(3); assertThat(this.invocableHandlerMethod.convert(param, 4L)).isEqualTo(4); assertThat(this.invocableHandlerMethod.convert(param, 5.5f)).isEqualTo(5); assertThat(this.invocableHandlerMethod.convert(param, 6.6)).isEqualTo(6); assertThat(this.invocableHandlerMethod.convert(param, new BigDecimal("3.141"))) .isEqualTo(3); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void deserializeTest() throws IOException { String json = "[16, 239714735, {}, \"com.myapp.mytopic1\"]"; PublishMessage publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(239714735L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic1"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).isNull(); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 239714735, {}, \"com.myapp.mytopic1\", [\"Hello, world!\"]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(239714735L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic1"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly("Hello, world!"); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 239714735, {}, \"com.myapp.mytopic1\", [], {\"color\": \"orange\",\n" + "\"sizes\": [23, 42, 7]}]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(239714735L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic1"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).isEmpty(); assertThat(publishMessage.getArgumentsKw()).containsExactly( MapEntry.entry("color", "orange"), MapEntry.entry("sizes", Arrays.asList(23, 42, 7))); json = "[16, 523412, {\"disclose_me\": true}, \"com.myapp.mytopic\", [23]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(523412L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isTrue(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 523412, {\"retain\": true}, \"com.myapp.mytopic\", [23]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(523412L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isTrue(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 523412, {\"exclude_me\": false,\"acknowledge\":true}, \"com.myapp.mytopic\", [23]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(523412L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isTrue(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isFalse(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 523412, {\"exclude\": [7891255,1245751],\"eligible\": [2,3]}, \"com.myapp.mytopic\", [23]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(523412L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic"); assertThat(publishMessage.getEligible()).containsExactly(2, 3); assertThat(publishMessage.getExclude()).containsOnly(7891255, 1245751); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); }
@SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); }
PublishMessage extends WampMessage { @SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); } }
PublishMessage extends WampMessage { @SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); } private PublishMessage(long requestId, String topic, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean acknowledge, boolean excludeMe, boolean discloseMe, boolean retain, @Nullable Set<Number> exclude, @Nullable Set<Number> eligible); PublishMessage(Builder builder); }
PublishMessage extends WampMessage { @SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); } private PublishMessage(long requestId, String topic, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean acknowledge, boolean excludeMe, boolean discloseMe, boolean retain, @Nullable Set<Number> exclude, @Nullable Set<Number> eligible); PublishMessage(Builder builder); static Builder builder(long requestId, String topic); @SuppressWarnings("unchecked") static PublishMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); boolean isAcknowledge(); boolean isExcludeMe(); boolean isDiscloseMe(); boolean isRetain(); String getTopic(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Set<Number> getExclude(); @Nullable Set<Number> getEligible(); @Override String toString(); }
PublishMessage extends WampMessage { @SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); } private PublishMessage(long requestId, String topic, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw, boolean acknowledge, boolean excludeMe, boolean discloseMe, boolean retain, @Nullable Set<Number> exclude, @Nullable Set<Number> eligible); PublishMessage(Builder builder); static Builder builder(long requestId, String topic); @SuppressWarnings("unchecked") static PublishMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); boolean isAcknowledge(); boolean isExcludeMe(); boolean isDiscloseMe(); boolean isRetain(); String getTopic(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Set<Number> getExclude(); @Nullable Set<Number> getEligible(); @Override String toString(); static final int CODE; }
@Test public void serializeTest() { ErrorMessage errorMessage = new ErrorMessage(64, 25349185L, "wamp.error.procedure_already_exists", null, null); assertThat(errorMessage.getCode()).isEqualTo(8); assertThat(errorMessage.getType()).isEqualTo(64); assertThat(errorMessage.getRequestId()).isEqualTo(25349185L); assertThat(errorMessage.getError()) .isEqualTo("wamp.error.procedure_already_exists"); assertThat(errorMessage.getArguments()).isNull(); assertThat(errorMessage.getArgumentsKw()).isNull(); String json = serializeToJson(errorMessage); assertThat(json) .isEqualTo("[8,64,25349185,{},\"wamp.error.procedure_already_exists\"]"); errorMessage = new ErrorMessage(66, 788923562L, "wamp.error.no_such_registration", Collections.singletonList("No such registration"), null); assertThat(errorMessage.getCode()).isEqualTo(8); assertThat(errorMessage.getType()).isEqualTo(66); assertThat(errorMessage.getRequestId()).isEqualTo(788923562L); assertThat(errorMessage.getError()).isEqualTo("wamp.error.no_such_registration"); assertThat(errorMessage.getArguments()).containsExactly("No such registration"); assertThat(errorMessage.getArgumentsKw()).isNull(); json = serializeToJson(errorMessage); assertThat(json).isEqualTo( "[8,66,788923562,{},\"wamp.error.no_such_registration\",[\"No such registration\"]]"); errorMessage = new ErrorMessage(68, 6131533L, "com.myapp.error.object_write_protected", Collections.singletonList("Object is write protected."), Collections.singletonMap("severity", 3)); assertThat(errorMessage.getCode()).isEqualTo(8); assertThat(errorMessage.getType()).isEqualTo(68); assertThat(errorMessage.getRequestId()).isEqualTo(6131533L); assertThat(errorMessage.getError()) .isEqualTo("com.myapp.error.object_write_protected"); assertThat(errorMessage.getArguments()) .containsExactly("Object is write protected."); assertThat(errorMessage.getArgumentsKw()) .containsExactly(MapEntry.entry("severity", 3)); json = serializeToJson(errorMessage); assertThat(json).isEqualTo( "[8,68,6131533,{},\"com.myapp.error.object_write_protected\",[\"Object is write protected.\"],{\"severity\":3}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.type); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); generator.writeString(this.error); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } }
ErrorMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.type); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); generator.writeString(this.error); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } }
ErrorMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.type); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); generator.writeString(this.error); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } ErrorMessage(int type, long requestId, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(ErrorMessage errorMessage, CallMessage callMessage); ErrorMessage(SubscribeMessage subscribeMessage, WampError error); ErrorMessage(UnsubscribeMessage unsubscribeMessage, WampError error); ErrorMessage(PublishMessage publishMessage, WampError error); ErrorMessage(RegisterMessage registerMessage, WampError error); ErrorMessage(UnregisterMessage unregisterMessage, WampError error); ErrorMessage(CallMessage callMessage, WampError error); ErrorMessage(CallMessage callMessage, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(InvocationMessage invocationMessage, WampError error); }
ErrorMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.type); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); generator.writeString(this.error); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } ErrorMessage(int type, long requestId, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(ErrorMessage errorMessage, CallMessage callMessage); ErrorMessage(SubscribeMessage subscribeMessage, WampError error); ErrorMessage(UnsubscribeMessage unsubscribeMessage, WampError error); ErrorMessage(PublishMessage publishMessage, WampError error); ErrorMessage(RegisterMessage registerMessage, WampError error); ErrorMessage(UnregisterMessage unregisterMessage, WampError error); ErrorMessage(CallMessage callMessage, WampError error); ErrorMessage(CallMessage callMessage, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(InvocationMessage invocationMessage, WampError error); static ErrorMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); int getType(); long getRequestId(); String getError(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
ErrorMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.type); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); generator.writeString(this.error); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } ErrorMessage(int type, long requestId, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(ErrorMessage errorMessage, CallMessage callMessage); ErrorMessage(SubscribeMessage subscribeMessage, WampError error); ErrorMessage(UnsubscribeMessage unsubscribeMessage, WampError error); ErrorMessage(PublishMessage publishMessage, WampError error); ErrorMessage(RegisterMessage registerMessage, WampError error); ErrorMessage(UnregisterMessage unregisterMessage, WampError error); ErrorMessage(CallMessage callMessage, WampError error); ErrorMessage(CallMessage callMessage, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(InvocationMessage invocationMessage, WampError error); static ErrorMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); int getType(); long getRequestId(); String getError(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[8, 64, 25349185, {}, \"wamp.error.procedure_already_exists\"]"; ErrorMessage errorMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(errorMessage.getCode()).isEqualTo(8); assertThat(errorMessage.getType()).isEqualTo(64); assertThat(errorMessage.getRequestId()).isEqualTo(25349185L); assertThat(errorMessage.getError()) .isEqualTo("wamp.error.procedure_already_exists"); assertThat(errorMessage.getArguments()).isNull(); assertThat(errorMessage.getArgumentsKw()).isNull(); json = "[8, 66, 788923562, {}, \"wamp.error.no_such_registration\",[\"No such registration\"]]"; errorMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(errorMessage.getCode()).isEqualTo(8); assertThat(errorMessage.getType()).isEqualTo(66); assertThat(errorMessage.getRequestId()).isEqualTo(788923562L); assertThat(errorMessage.getError()).isEqualTo("wamp.error.no_such_registration"); assertThat(errorMessage.getArguments()).containsExactly("No such registration"); assertThat(errorMessage.getArgumentsKw()).isNull(); json = "[8, 68, 6131533, {}, \"com.myapp.error.object_write_protected\", [\"Object is write protected.\"], {\"severity\": 3}]"; errorMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(errorMessage.getCode()).isEqualTo(8); assertThat(errorMessage.getType()).isEqualTo(68); assertThat(errorMessage.getRequestId()).isEqualTo(6131533L); assertThat(errorMessage.getError()) .isEqualTo("com.myapp.error.object_write_protected"); assertThat(errorMessage.getArguments()) .containsExactly("Object is write protected."); assertThat(errorMessage.getArgumentsKw()) .containsExactly(MapEntry.entry("severity", 3)); }
public static ErrorMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); int type = jp.getIntValue(); jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); jp.nextToken(); String error = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ErrorMessage(type, request, error, arguments, argumentsKw); }
ErrorMessage extends WampMessage { public static ErrorMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); int type = jp.getIntValue(); jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); jp.nextToken(); String error = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ErrorMessage(type, request, error, arguments, argumentsKw); } }
ErrorMessage extends WampMessage { public static ErrorMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); int type = jp.getIntValue(); jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); jp.nextToken(); String error = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ErrorMessage(type, request, error, arguments, argumentsKw); } ErrorMessage(int type, long requestId, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(ErrorMessage errorMessage, CallMessage callMessage); ErrorMessage(SubscribeMessage subscribeMessage, WampError error); ErrorMessage(UnsubscribeMessage unsubscribeMessage, WampError error); ErrorMessage(PublishMessage publishMessage, WampError error); ErrorMessage(RegisterMessage registerMessage, WampError error); ErrorMessage(UnregisterMessage unregisterMessage, WampError error); ErrorMessage(CallMessage callMessage, WampError error); ErrorMessage(CallMessage callMessage, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(InvocationMessage invocationMessage, WampError error); }
ErrorMessage extends WampMessage { public static ErrorMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); int type = jp.getIntValue(); jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); jp.nextToken(); String error = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ErrorMessage(type, request, error, arguments, argumentsKw); } ErrorMessage(int type, long requestId, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(ErrorMessage errorMessage, CallMessage callMessage); ErrorMessage(SubscribeMessage subscribeMessage, WampError error); ErrorMessage(UnsubscribeMessage unsubscribeMessage, WampError error); ErrorMessage(PublishMessage publishMessage, WampError error); ErrorMessage(RegisterMessage registerMessage, WampError error); ErrorMessage(UnregisterMessage unregisterMessage, WampError error); ErrorMessage(CallMessage callMessage, WampError error); ErrorMessage(CallMessage callMessage, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(InvocationMessage invocationMessage, WampError error); static ErrorMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); int getType(); long getRequestId(); String getError(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
ErrorMessage extends WampMessage { public static ErrorMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); int type = jp.getIntValue(); jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); jp.nextToken(); String error = jp.getValueAsString(); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ErrorMessage(type, request, error, arguments, argumentsKw); } ErrorMessage(int type, long requestId, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(ErrorMessage errorMessage, CallMessage callMessage); ErrorMessage(SubscribeMessage subscribeMessage, WampError error); ErrorMessage(UnsubscribeMessage unsubscribeMessage, WampError error); ErrorMessage(PublishMessage publishMessage, WampError error); ErrorMessage(RegisterMessage registerMessage, WampError error); ErrorMessage(UnregisterMessage unregisterMessage, WampError error); ErrorMessage(CallMessage callMessage, WampError error); ErrorMessage(CallMessage callMessage, String error, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ErrorMessage(InvocationMessage invocationMessage, WampError error); static ErrorMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); int getType(); long getRequestId(); String getError(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
@Test public void serializeTest() { RegisteredMessage registeredMessage = new RegisteredMessage(11, 127172L); assertThat(registeredMessage.getCode()).isEqualTo(65); assertThat(registeredMessage.getRequestId()).isEqualTo(11); assertThat(registeredMessage.getRegistrationId()).isEqualTo(127172L); String json = serializeToJson(registeredMessage); assertThat(json).isEqualTo("[65,11,127172]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); }
RegisteredMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); } }
RegisteredMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); } RegisteredMessage(long requestId, long registrationId); RegisteredMessage(RegisterMessage registerMessage, long registrationId); }
RegisteredMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); } RegisteredMessage(long requestId, long registrationId); RegisteredMessage(RegisterMessage registerMessage, long registrationId); static RegisteredMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Override String toString(); }
RegisteredMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); } RegisteredMessage(long requestId, long registrationId); RegisteredMessage(RegisterMessage registerMessage, long registrationId); static RegisteredMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[65, 25349185, 2103333224]"; RegisteredMessage registeredMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(registeredMessage.getCode()).isEqualTo(65); assertThat(registeredMessage.getRequestId()).isEqualTo(25349185L); assertThat(registeredMessage.getRegistrationId()).isEqualTo(2103333224L); }
public static RegisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new RegisteredMessage(request, registration); }
RegisteredMessage extends WampMessage { public static RegisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new RegisteredMessage(request, registration); } }
RegisteredMessage extends WampMessage { public static RegisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new RegisteredMessage(request, registration); } RegisteredMessage(long requestId, long registrationId); RegisteredMessage(RegisterMessage registerMessage, long registrationId); }
RegisteredMessage extends WampMessage { public static RegisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new RegisteredMessage(request, registration); } RegisteredMessage(long requestId, long registrationId); RegisteredMessage(RegisterMessage registerMessage, long registrationId); static RegisteredMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Override String toString(); }
RegisteredMessage extends WampMessage { public static RegisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new RegisteredMessage(request, registration); } RegisteredMessage(long requestId, long registrationId); RegisteredMessage(RegisterMessage registerMessage, long registrationId); static RegisteredMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Override String toString(); }
@Test public void serializeTest() { UnsubscribedMessage unsubscribedMessage = new UnsubscribedMessage(1); assertThat(unsubscribedMessage.getCode()).isEqualTo(35); assertThat(unsubscribedMessage.getRequestId()).isEqualTo(1); assertThat(unsubscribedMessage.getSubscriptionId()).isNull(); assertThat(unsubscribedMessage.getReason()).isNull(); String json = serializeToJson(unsubscribedMessage); assertThat(json).isEqualTo("[35,1]"); unsubscribedMessage = new UnsubscribedMessage(2, 1208L, "removed"); assertThat(unsubscribedMessage.getCode()).isEqualTo(35); assertThat(unsubscribedMessage.getRequestId()).isEqualTo(2); assertThat(unsubscribedMessage.getSubscriptionId()).isEqualTo(1208L); assertThat(unsubscribedMessage.getReason()).isEqualTo("removed"); json = serializeToJson(unsubscribedMessage); assertThat(json) .isEqualTo("[35,2,{\"reason\":\"removed\",\"subscription\":1208}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.subscriptionId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.subscriptionId != null) { generator.writeNumberField("subscription", this.subscriptionId); } generator.writeEndObject(); } }
UnsubscribedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.subscriptionId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.subscriptionId != null) { generator.writeNumberField("subscription", this.subscriptionId); } generator.writeEndObject(); } } }
UnsubscribedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.subscriptionId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.subscriptionId != null) { generator.writeNumberField("subscription", this.subscriptionId); } generator.writeEndObject(); } } UnsubscribedMessage(long requestId); UnsubscribedMessage(long requestId, @Nullable Long subscriptionId, @Nullable String reason); UnsubscribedMessage(UnsubscribeMessage unsubscribeMessage); }
UnsubscribedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.subscriptionId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.subscriptionId != null) { generator.writeNumberField("subscription", this.subscriptionId); } generator.writeEndObject(); } } UnsubscribedMessage(long requestId); UnsubscribedMessage(long requestId, @Nullable Long subscriptionId, @Nullable String reason); UnsubscribedMessage(UnsubscribeMessage unsubscribeMessage); static UnsubscribedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable Long getSubscriptionId(); @Nullable String getReason(); @Override String toString(); }
UnsubscribedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.subscriptionId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.subscriptionId != null) { generator.writeNumberField("subscription", this.subscriptionId); } generator.writeEndObject(); } } UnsubscribedMessage(long requestId); UnsubscribedMessage(long requestId, @Nullable Long subscriptionId, @Nullable String reason); UnsubscribedMessage(UnsubscribeMessage unsubscribeMessage); static UnsubscribedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable Long getSubscriptionId(); @Nullable String getReason(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[35, 85346237]"; UnsubscribedMessage unsubscribedMessage = WampMessage .deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(unsubscribedMessage.getCode()).isEqualTo(35); assertThat(unsubscribedMessage.getRequestId()).isEqualTo(85346237L); assertThat(unsubscribedMessage.getSubscriptionId()).isNull(); assertThat(unsubscribedMessage.getReason()).isNull(); json = "[35, 0, {\"subscription\":1213,\"reason\":\"the reason\"}]"; unsubscribedMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(unsubscribedMessage.getCode()).isEqualTo(35); assertThat(unsubscribedMessage.getRequestId()).isEqualTo(0); assertThat(unsubscribedMessage.getSubscriptionId()).isEqualTo(1213L); assertThat(unsubscribedMessage.getReason()).isEqualTo("the reason"); }
public static UnsubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long subscriptionId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object subscriptionObj = details.get("subscription"); if (subscriptionObj != null) { subscriptionId = ((Number) subscriptionObj).longValue(); } } return new UnsubscribedMessage(request, subscriptionId, reason); }
UnsubscribedMessage extends WampMessage { public static UnsubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long subscriptionId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object subscriptionObj = details.get("subscription"); if (subscriptionObj != null) { subscriptionId = ((Number) subscriptionObj).longValue(); } } return new UnsubscribedMessage(request, subscriptionId, reason); } }
UnsubscribedMessage extends WampMessage { public static UnsubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long subscriptionId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object subscriptionObj = details.get("subscription"); if (subscriptionObj != null) { subscriptionId = ((Number) subscriptionObj).longValue(); } } return new UnsubscribedMessage(request, subscriptionId, reason); } UnsubscribedMessage(long requestId); UnsubscribedMessage(long requestId, @Nullable Long subscriptionId, @Nullable String reason); UnsubscribedMessage(UnsubscribeMessage unsubscribeMessage); }
UnsubscribedMessage extends WampMessage { public static UnsubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long subscriptionId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object subscriptionObj = details.get("subscription"); if (subscriptionObj != null) { subscriptionId = ((Number) subscriptionObj).longValue(); } } return new UnsubscribedMessage(request, subscriptionId, reason); } UnsubscribedMessage(long requestId); UnsubscribedMessage(long requestId, @Nullable Long subscriptionId, @Nullable String reason); UnsubscribedMessage(UnsubscribeMessage unsubscribeMessage); static UnsubscribedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable Long getSubscriptionId(); @Nullable String getReason(); @Override String toString(); }
UnsubscribedMessage extends WampMessage { public static UnsubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long subscriptionId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object subscriptionObj = details.get("subscription"); if (subscriptionObj != null) { subscriptionId = ((Number) subscriptionObj).longValue(); } } return new UnsubscribedMessage(request, subscriptionId, reason); } UnsubscribedMessage(long requestId); UnsubscribedMessage(long requestId, @Nullable Long subscriptionId, @Nullable String reason); UnsubscribedMessage(UnsubscribeMessage unsubscribeMessage); static UnsubscribedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable Long getSubscriptionId(); @Nullable String getReason(); @Override String toString(); }
@Test public void serializeTest() { PublishedMessage publishedMessage = new PublishedMessage(44, 121); assertThat(publishedMessage.getCode()).isEqualTo(17); assertThat(publishedMessage.getRequestId()).isEqualTo(44); assertThat(publishedMessage.getPublicationId()).isEqualTo(121); String json = serializeToJson(publishedMessage); assertThat(json).isEqualTo("[17,44,121]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.publicationId); }
PublishedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.publicationId); } }
PublishedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.publicationId); } PublishedMessage(long requestId, long publicationId); PublishedMessage(PublishMessage publishMessage, long publicationId); }
PublishedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.publicationId); } PublishedMessage(long requestId, long publicationId); PublishedMessage(PublishMessage publishMessage, long publicationId); static PublishedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getPublicationId(); @Override String toString(); }
PublishedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.publicationId); } PublishedMessage(long requestId, long publicationId); PublishedMessage(PublishMessage publishMessage, long publicationId); static PublishedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getPublicationId(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[17, 239714735, 4429313566]"; PublishedMessage publishedMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishedMessage.getCode()).isEqualTo(17); assertThat(publishedMessage.getRequestId()).isEqualTo(239714735L); assertThat(publishedMessage.getPublicationId()).isEqualTo(4429313566L); }
public static PublishedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new PublishedMessage(request, subscription); }
PublishedMessage extends WampMessage { public static PublishedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new PublishedMessage(request, subscription); } }
PublishedMessage extends WampMessage { public static PublishedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new PublishedMessage(request, subscription); } PublishedMessage(long requestId, long publicationId); PublishedMessage(PublishMessage publishMessage, long publicationId); }
PublishedMessage extends WampMessage { public static PublishedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new PublishedMessage(request, subscription); } PublishedMessage(long requestId, long publicationId); PublishedMessage(PublishMessage publishMessage, long publicationId); static PublishedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getPublicationId(); @Override String toString(); }
PublishedMessage extends WampMessage { public static PublishedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new PublishedMessage(request, subscription); } PublishedMessage(long requestId, long publicationId); PublishedMessage(PublishMessage publishMessage, long publicationId); static PublishedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getPublicationId(); @Override String toString(); }
@Test public void serializeTest() { ResultMessage resultMessage = new ResultMessage(111, null, null); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(111); assertThat(resultMessage.getArguments()).isNull(); assertThat(resultMessage.getArgumentsKw()).isNull(); String json = serializeToJson(resultMessage); assertThat(json).isEqualTo("[50,111,{}]"); resultMessage = new ResultMessage(111, Arrays.asList("Hello world"), null); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(111); assertThat(resultMessage.getArguments()).containsExactly("Hello world"); assertThat(resultMessage.getArgumentsKw()).isNull(); json = serializeToJson(resultMessage); assertThat(json).isEqualTo("[50,111,{},[\"Hello world\"]]"); Map<String, Object> argumentsKw = new HashMap<>(); argumentsKw.put("firstname", "John"); argumentsKw.put("surname", "Doe"); resultMessage = new ResultMessage(111, Arrays.asList("johnny"), argumentsKw); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(111); assertThat(resultMessage.getArguments()).containsExactly("johnny"); assertThat(resultMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = serializeToJson(resultMessage); assertThat(json).isEqualTo( "[50,111,{},[\"johnny\"],{\"firstname\":\"John\",\"surname\":\"Doe\"}]"); argumentsKw = new HashMap<>(); argumentsKw.put("firstname", "John"); argumentsKw.put("surname", "Doe"); resultMessage = new ResultMessage(111, null, argumentsKw); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(111); assertThat(resultMessage.getArguments()).isNull(); assertThat(resultMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = serializeToJson(resultMessage); assertThat(json) .isEqualTo("[50,111,{},[],{\"firstname\":\"John\",\"surname\":\"Doe\"}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } }
ResultMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } }
ResultMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } ResultMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(CallMessage callMessage, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(YieldMessage yieldMessage, CallMessage callMessage); }
ResultMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } ResultMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(CallMessage callMessage, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(YieldMessage yieldMessage, CallMessage callMessage); static ResultMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
ResultMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } ResultMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(CallMessage callMessage, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(YieldMessage yieldMessage, CallMessage callMessage); static ResultMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); final long requestId; }
@Test(expected = ConversionFailedException.class) public void testTointException() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("intParam", Integer.TYPE); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, "str")).isEqualTo("str"); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void deserializeTest() throws IOException { String json = "[50, 7814135, {}]"; ResultMessage resultMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(7814135L); assertThat(resultMessage.getArguments()).isNull(); assertThat(resultMessage.getArgumentsKw()).isNull(); json = "[50, 7814135, {}, [\"Hello, world!\"]]"; resultMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(7814135L); assertThat(resultMessage.getArguments()).containsExactly("Hello, world!"); assertThat(resultMessage.getArgumentsKw()).isNull(); json = "[50, 7814135, {}, [30]]"; resultMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(7814135L); assertThat(resultMessage.getArguments()).containsExactly(30); assertThat(resultMessage.getArgumentsKw()).isNull(); json = "[50, 7814135, {}, [], {\"userid\": 123, \"karma\": 10}]"; resultMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(7814135L); assertThat(resultMessage.getArguments()).isEmpty(); assertThat(resultMessage.getArgumentsKw()) .containsOnly(MapEntry.entry("userid", 123), MapEntry.entry("karma", 10)); json = "[50, 7814135, {}, [\"a\",\"b\",\"c\"], {\"userid\": 123, \"karma\": 10}]"; resultMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(resultMessage.getCode()).isEqualTo(50); assertThat(resultMessage.getRequestId()).isEqualTo(7814135L); assertThat(resultMessage.getArguments()).containsExactly("a", "b", "c"); assertThat(resultMessage.getArgumentsKw()) .containsOnly(MapEntry.entry("userid", 123), MapEntry.entry("karma", 10)); }
public static ResultMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ResultMessage(request, arguments, argumentsKw); }
ResultMessage extends WampMessage { public static ResultMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ResultMessage(request, arguments, argumentsKw); } }
ResultMessage extends WampMessage { public static ResultMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ResultMessage(request, arguments, argumentsKw); } ResultMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(CallMessage callMessage, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(YieldMessage yieldMessage, CallMessage callMessage); }
ResultMessage extends WampMessage { public static ResultMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ResultMessage(request, arguments, argumentsKw); } ResultMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(CallMessage callMessage, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(YieldMessage yieldMessage, CallMessage callMessage); static ResultMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
ResultMessage extends WampMessage { public static ResultMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new ResultMessage(request, arguments, argumentsKw); } ResultMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(CallMessage callMessage, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); ResultMessage(YieldMessage yieldMessage, CallMessage callMessage); static ResultMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); final long requestId; }
@Test public void serializeTest() { EventMessage eventMessage = new EventMessage(1, 2, null, null, false, null, null); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(1); assertThat(eventMessage.getPublicationId()).isEqualTo(2); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).isNull(); assertThat(eventMessage.getArgumentsKw()).isNull(); String json = serializeToJson(eventMessage); assertThat(json).isEqualTo("[36,1,2,{}]"); eventMessage = new EventMessage(1, 2, null, null, false, Collections.singletonList("Hello, world!"), null); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(1); assertThat(eventMessage.getPublicationId()).isEqualTo(2); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Hello, world!"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = serializeToJson(eventMessage); assertThat(json).isEqualTo("[36,1,2,{},[\"Hello, world!\"]]"); Map<String, Object> argumentsKw = new HashMap<>(); argumentsKw.put("firstname", "John"); argumentsKw.put("surname", "Doe"); eventMessage = new EventMessage(1, 2, null, null, false, Arrays.asList("johnny"), argumentsKw); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(1); assertThat(eventMessage.getPublicationId()).isEqualTo(2); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("johnny"); assertThat(eventMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = serializeToJson(eventMessage); assertThat(json).isEqualTo( "[36,1,2,{},[\"johnny\"],{\"firstname\":\"John\",\"surname\":\"Doe\"}]"); eventMessage = new EventMessage(1, 2, null, null, false, null, argumentsKw); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(1); assertThat(eventMessage.getPublicationId()).isEqualTo(2); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).isNull(); assertThat(eventMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = serializeToJson(eventMessage); assertThat(json) .isEqualTo("[36,1,2,{},[],{\"firstname\":\"John\",\"surname\":\"Doe\"}]"); eventMessage = new EventMessage(1, 2, "topic", null, false, Collections.singletonList(42), null); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(1); assertThat(eventMessage.getPublicationId()).isEqualTo(2); assertThat(eventMessage.getTopic()).isEqualTo("topic"); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly(42); assertThat(eventMessage.getArgumentsKw()).isNull(); json = serializeToJson(eventMessage); assertThat(json).isEqualTo("[36,1,2,{\"topic\":\"topic\"},[42]]"); eventMessage = new EventMessage(1, 2, "topic", 123, false, Collections.singletonList(42), null); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(1); assertThat(eventMessage.getPublicationId()).isEqualTo(2); assertThat(eventMessage.getTopic()).isEqualTo("topic"); assertThat(eventMessage.getPublisher()).isEqualTo(123); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly(42); assertThat(eventMessage.getArgumentsKw()).isNull(); json = serializeToJson(eventMessage); assertThat(json) .isEqualTo("[36,1,2,{\"topic\":\"topic\",\"publisher\":123},[42]]"); eventMessage = new EventMessage(1, 2, null, null, true, Collections.singletonList(43), null); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(1); assertThat(eventMessage.getPublicationId()).isEqualTo(2); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isTrue(); assertThat(eventMessage.getArguments()).containsExactly(43); assertThat(eventMessage.getArgumentsKw()).isNull(); json = serializeToJson(eventMessage); assertThat(json).isEqualTo("[36,1,2,{\"retained\":true},[43]]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.subscriptionId); generator.writeNumber(this.publicationId); generator.writeStartObject(); if (this.topic != null) { generator.writeStringField("topic", this.topic); } if (this.publisher != null) { generator.writeNumberField("publisher", this.publisher.longValue()); } if (this.retained) { generator.writeBooleanField("retained", this.retained); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } }
EventMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.subscriptionId); generator.writeNumber(this.publicationId); generator.writeStartObject(); if (this.topic != null) { generator.writeStringField("topic", this.topic); } if (this.publisher != null) { generator.writeNumberField("publisher", this.publisher.longValue()); } if (this.retained) { generator.writeBooleanField("retained", this.retained); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } }
EventMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.subscriptionId); generator.writeNumber(this.publicationId); generator.writeStartObject(); if (this.topic != null) { generator.writeStringField("topic", this.topic); } if (this.publisher != null) { generator.writeNumberField("publisher", this.publisher.longValue()); } if (this.retained) { generator.writeBooleanField("retained", this.retained); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } EventMessage(long subscriptionId, long publicationId, @Nullable String topic, @Nullable Number publisher, boolean retained, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); EventMessage(@Nullable String receiverWebSocketSessionId, long subscription, long publication, @Nullable String topic, @Nullable Number publisher, boolean retained, PublishMessage publishMessage); }
EventMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.subscriptionId); generator.writeNumber(this.publicationId); generator.writeStartObject(); if (this.topic != null) { generator.writeStringField("topic", this.topic); } if (this.publisher != null) { generator.writeNumberField("publisher", this.publisher.longValue()); } if (this.retained) { generator.writeBooleanField("retained", this.retained); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } EventMessage(long subscriptionId, long publicationId, @Nullable String topic, @Nullable Number publisher, boolean retained, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); EventMessage(@Nullable String receiverWebSocketSessionId, long subscription, long publication, @Nullable String topic, @Nullable Number publisher, boolean retained, PublishMessage publishMessage); static EventMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSubscriptionId(); long getPublicationId(); @Nullable String getTopic(); @Nullable Number getPublisher(); boolean isRetained(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
EventMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.subscriptionId); generator.writeNumber(this.publicationId); generator.writeStartObject(); if (this.topic != null) { generator.writeStringField("topic", this.topic); } if (this.publisher != null) { generator.writeNumberField("publisher", this.publisher.longValue()); } if (this.retained) { generator.writeBooleanField("retained", this.retained); } generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } EventMessage(long subscriptionId, long publicationId, @Nullable String topic, @Nullable Number publisher, boolean retained, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); EventMessage(@Nullable String receiverWebSocketSessionId, long subscription, long publication, @Nullable String topic, @Nullable Number publisher, boolean retained, PublishMessage publishMessage); static EventMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSubscriptionId(); long getPublicationId(); @Nullable String getTopic(); @Nullable Number getPublisher(); boolean isRetained(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); static final int CODE; }
@Test public void deserializeTest() throws IOException { String json = "[36, 5512315355, 4429313566, {}]"; EventMessage eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).isNull(); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {}, [\"Hello, world!\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Hello, world!"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {}, [], {\"color\": \"orange\",\"sizes\": [23, 42, 7]}]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).isEmpty(); assertThat(eventMessage.getArgumentsKw()).containsExactly( MapEntry.entry("color", "orange"), MapEntry.entry("sizes", Arrays.asList(23, 42, 7))); json = "[36, 5512315355, 4429313566, {}, [\"a\",\"b\"], {\"color\": \"orange\",\"sizes\": [23, 42, 7]}]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("a", "b"); assertThat(eventMessage.getArgumentsKw()).containsExactly( MapEntry.entry("color", "orange"), MapEntry.entry("sizes", Arrays.asList(23, 42, 7))); json = "[36, 5512315355, 4429313566, {\"topic\":\"the_topic\"}, [\"Hello, world!\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isEqualTo("the_topic"); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Hello, world!"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {\"topic\":\"the_topic\", \"publisher\":1234}, [\"Hello, world!\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isEqualTo("the_topic"); assertThat(eventMessage.getPublisher()).isEqualTo(1234); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Hello, world!"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {\"retained\":false}, [\"Not Retained\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Not Retained"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {\"retained\":true}, [\"Retained\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isTrue(); assertThat(eventMessage.getArguments()).containsExactly("Retained"); assertThat(eventMessage.getArgumentsKw()).isNull(); }
public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); }
EventMessage extends WampMessage { public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); } }
EventMessage extends WampMessage { public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); } EventMessage(long subscriptionId, long publicationId, @Nullable String topic, @Nullable Number publisher, boolean retained, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); EventMessage(@Nullable String receiverWebSocketSessionId, long subscription, long publication, @Nullable String topic, @Nullable Number publisher, boolean retained, PublishMessage publishMessage); }
EventMessage extends WampMessage { public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); } EventMessage(long subscriptionId, long publicationId, @Nullable String topic, @Nullable Number publisher, boolean retained, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); EventMessage(@Nullable String receiverWebSocketSessionId, long subscription, long publication, @Nullable String topic, @Nullable Number publisher, boolean retained, PublishMessage publishMessage); static EventMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSubscriptionId(); long getPublicationId(); @Nullable String getTopic(); @Nullable Number getPublisher(); boolean isRetained(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
EventMessage extends WampMessage { public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); } EventMessage(long subscriptionId, long publicationId, @Nullable String topic, @Nullable Number publisher, boolean retained, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); EventMessage(@Nullable String receiverWebSocketSessionId, long subscription, long publication, @Nullable String topic, @Nullable Number publisher, boolean retained, PublishMessage publishMessage); static EventMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSubscriptionId(); long getPublicationId(); @Nullable String getTopic(); @Nullable Number getPublisher(); boolean isRetained(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); static final int CODE; }
@Test public void serializeTest() { RegisterMessage registerMessage = new RegisterMessage(11, "bean.method"); assertThat(registerMessage.getCode()).isEqualTo(64); assertThat(registerMessage.getRequestId()).isEqualTo(11); assertThat(registerMessage.getProcedure()).isEqualTo("bean.method"); assertThat(registerMessage.isDiscloseCaller()).isFalse(); String json = serializeToJson(registerMessage); assertThat(json).isEqualTo("[64,11,{},\"bean.method\"]"); registerMessage = new RegisterMessage(927639114088448L, "com.maypp.add2", true); assertThat(registerMessage.getCode()).isEqualTo(64); assertThat(registerMessage.getRequestId()).isEqualTo(927639114088448L); assertThat(registerMessage.getProcedure()).isEqualTo("com.maypp.add2"); assertThat(registerMessage.isDiscloseCaller()).isTrue(); json = serializeToJson(registerMessage); assertThat(json).isEqualTo( "[64,927639114088448,{\"disclose_caller\":true},\"com.maypp.add2\"]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseCaller) { generator.writeBooleanField("disclose_caller", this.discloseCaller); } generator.writeEndObject(); generator.writeString(this.procedure); }
RegisterMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseCaller) { generator.writeBooleanField("disclose_caller", this.discloseCaller); } generator.writeEndObject(); generator.writeString(this.procedure); } }
RegisterMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseCaller) { generator.writeBooleanField("disclose_caller", this.discloseCaller); } generator.writeEndObject(); generator.writeString(this.procedure); } RegisterMessage(long requestId, String procedure); RegisterMessage(long requestId, String procedure, boolean discloseCaller); }
RegisterMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseCaller) { generator.writeBooleanField("disclose_caller", this.discloseCaller); } generator.writeEndObject(); generator.writeString(this.procedure); } RegisterMessage(long requestId, String procedure); RegisterMessage(long requestId, String procedure, boolean discloseCaller); static RegisterMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); String getProcedure(); boolean isDiscloseCaller(); @Override String toString(); }
RegisterMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.discloseCaller) { generator.writeBooleanField("disclose_caller", this.discloseCaller); } generator.writeEndObject(); generator.writeString(this.procedure); } RegisterMessage(long requestId, String procedure); RegisterMessage(long requestId, String procedure, boolean discloseCaller); static RegisterMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); String getProcedure(); boolean isDiscloseCaller(); @Override String toString(); static final int CODE; }
@Test public void deserializeTest() throws IOException { String json = "[64, 25349185, {}, \"com.myapp.myprocedure\"]"; RegisterMessage registerMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(registerMessage.getCode()).isEqualTo(64); assertThat(registerMessage.getRequestId()).isEqualTo(25349185L); assertThat(registerMessage.getProcedure()).isEqualTo("com.myapp.myprocedure"); assertThat(registerMessage.isDiscloseCaller()).isFalse(); json = "[64, 927639114088448, {\"disclose_caller\":true},\"com.maypp.add2\"]"; registerMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(registerMessage.getCode()).isEqualTo(64); assertThat(registerMessage.getRequestId()).isEqualTo(927639114088448L); assertThat(registerMessage.getProcedure()).isEqualTo("com.maypp.add2"); assertThat(registerMessage.isDiscloseCaller()).isTrue(); }
public static RegisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseCaller = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseCaller = (boolean) options.getOrDefault("disclose_caller", false); } jp.nextToken(); String procedure = jp.getValueAsString(); return new RegisterMessage(request, procedure, discloseCaller); }
RegisterMessage extends WampMessage { public static RegisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseCaller = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseCaller = (boolean) options.getOrDefault("disclose_caller", false); } jp.nextToken(); String procedure = jp.getValueAsString(); return new RegisterMessage(request, procedure, discloseCaller); } }
RegisterMessage extends WampMessage { public static RegisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseCaller = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseCaller = (boolean) options.getOrDefault("disclose_caller", false); } jp.nextToken(); String procedure = jp.getValueAsString(); return new RegisterMessage(request, procedure, discloseCaller); } RegisterMessage(long requestId, String procedure); RegisterMessage(long requestId, String procedure, boolean discloseCaller); }
RegisterMessage extends WampMessage { public static RegisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseCaller = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseCaller = (boolean) options.getOrDefault("disclose_caller", false); } jp.nextToken(); String procedure = jp.getValueAsString(); return new RegisterMessage(request, procedure, discloseCaller); } RegisterMessage(long requestId, String procedure); RegisterMessage(long requestId, String procedure, boolean discloseCaller); static RegisterMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); String getProcedure(); boolean isDiscloseCaller(); @Override String toString(); }
RegisterMessage extends WampMessage { public static RegisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean discloseCaller = false; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { discloseCaller = (boolean) options.getOrDefault("disclose_caller", false); } jp.nextToken(); String procedure = jp.getValueAsString(); return new RegisterMessage(request, procedure, discloseCaller); } RegisterMessage(long requestId, String procedure); RegisterMessage(long requestId, String procedure, boolean discloseCaller); static RegisterMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); String getProcedure(); boolean isDiscloseCaller(); @Override String toString(); static final int CODE; }
@Test public void serializeTest() { UnsubscribeMessage unsubscribeMessage = new UnsubscribeMessage(1, 2); assertThat(unsubscribeMessage.getCode()).isEqualTo(34); assertThat(unsubscribeMessage.getRequestId()).isEqualTo(1); assertThat(unsubscribeMessage.getSubscriptionId()).isEqualTo(2); String json = serializeToJson(unsubscribeMessage); assertThat(json).isEqualTo("[34,1,2]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); }
UnsubscribeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); } }
UnsubscribeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); } UnsubscribeMessage(long requestId, long subscriptionId); }
UnsubscribeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); } UnsubscribeMessage(long requestId, long subscriptionId); static UnsubscribeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getSubscriptionId(); @Override String toString(); }
UnsubscribeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); } UnsubscribeMessage(long requestId, long subscriptionId); static UnsubscribeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getSubscriptionId(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[34, 85346237, 5512315355]"; UnsubscribeMessage unsubscribeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(unsubscribeMessage.getCode()).isEqualTo(34); assertThat(unsubscribeMessage.getRequestId()).isEqualTo(85346237L); assertThat(unsubscribeMessage.getSubscriptionId()).isEqualTo(5512315355L); }
public static UnsubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new UnsubscribeMessage(request, subscription); }
UnsubscribeMessage extends WampMessage { public static UnsubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new UnsubscribeMessage(request, subscription); } }
UnsubscribeMessage extends WampMessage { public static UnsubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new UnsubscribeMessage(request, subscription); } UnsubscribeMessage(long requestId, long subscriptionId); }
UnsubscribeMessage extends WampMessage { public static UnsubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new UnsubscribeMessage(request, subscription); } UnsubscribeMessage(long requestId, long subscriptionId); static UnsubscribeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getSubscriptionId(); @Override String toString(); }
UnsubscribeMessage extends WampMessage { public static UnsubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new UnsubscribeMessage(request, subscription); } UnsubscribeMessage(long requestId, long subscriptionId); static UnsubscribeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getSubscriptionId(); @Override String toString(); }
@Test public void serializeTest() { UnregisteredMessage unregisteredMessage = new UnregisteredMessage(13); assertThat(unregisteredMessage.getCode()).isEqualTo(67); assertThat(unregisteredMessage.getRequestId()).isEqualTo(13); assertThat(unregisteredMessage.getRegistrationId()).isNull(); assertThat(unregisteredMessage.getReason()).isNull(); String json = serializeToJson(unregisteredMessage); assertThat(json).isEqualTo("[67,13]"); unregisteredMessage = new UnregisteredMessage(13, 333L, "a reason"); assertThat(unregisteredMessage.getCode()).isEqualTo(67); assertThat(unregisteredMessage.getRequestId()).isEqualTo(13); assertThat(unregisteredMessage.getRegistrationId()).isEqualTo(333); assertThat(unregisteredMessage.getReason()).isEqualTo("a reason"); json = serializeToJson(unregisteredMessage); assertThat(json) .isEqualTo("[67,13,{\"reason\":\"a reason\",\"registration\":333}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.registrationId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.registrationId != null) { generator.writeNumberField("registration", this.registrationId); } generator.writeEndObject(); } }
UnregisteredMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.registrationId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.registrationId != null) { generator.writeNumberField("registration", this.registrationId); } generator.writeEndObject(); } } }
UnregisteredMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.registrationId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.registrationId != null) { generator.writeNumberField("registration", this.registrationId); } generator.writeEndObject(); } } UnregisteredMessage(long requestId); UnregisteredMessage(long requestId, @Nullable Long registrationId, @Nullable String reason); UnregisteredMessage(UnregisterMessage unregisterMessage); }
UnregisteredMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.registrationId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.registrationId != null) { generator.writeNumberField("registration", this.registrationId); } generator.writeEndObject(); } } UnregisteredMessage(long requestId); UnregisteredMessage(long requestId, @Nullable Long registrationId, @Nullable String reason); UnregisteredMessage(UnregisterMessage unregisterMessage); static UnregisteredMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable Long getRegistrationId(); @Nullable String getReason(); @Override String toString(); }
UnregisteredMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); if (this.registrationId != null || this.reason != null) { generator.writeStartObject(); if (this.reason != null) { generator.writeStringField("reason", this.reason); } if (this.registrationId != null) { generator.writeNumberField("registration", this.registrationId); } generator.writeEndObject(); } } UnregisteredMessage(long requestId); UnregisteredMessage(long requestId, @Nullable Long registrationId, @Nullable String reason); UnregisteredMessage(UnregisterMessage unregisterMessage); static UnregisteredMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable Long getRegistrationId(); @Nullable String getReason(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[67, 788923562]"; UnregisteredMessage unregisteredMessage = WampMessage .deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(unregisteredMessage.getCode()).isEqualTo(67); assertThat(unregisteredMessage.getRequestId()).isEqualTo(788923562L); assertThat(unregisteredMessage.getRegistrationId()).isNull(); assertThat(unregisteredMessage.getReason()).isNull(); json = "[67, 0, {\"registration\":334,\"reason\":\"another reason\"}]"; unregisteredMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(unregisteredMessage.getCode()).isEqualTo(67); assertThat(unregisteredMessage.getRequestId()).isEqualTo(0); assertThat(unregisteredMessage.getRegistrationId()).isEqualTo(334); assertThat(unregisteredMessage.getReason()).isEqualTo("another reason"); }
public static UnregisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long registrationId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object registrationObj = details.get("registration"); if (registrationObj != null) { registrationId = ((Number) registrationObj).longValue(); } } return new UnregisteredMessage(request, registrationId, reason); }
UnregisteredMessage extends WampMessage { public static UnregisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long registrationId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object registrationObj = details.get("registration"); if (registrationObj != null) { registrationId = ((Number) registrationObj).longValue(); } } return new UnregisteredMessage(request, registrationId, reason); } }
UnregisteredMessage extends WampMessage { public static UnregisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long registrationId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object registrationObj = details.get("registration"); if (registrationObj != null) { registrationId = ((Number) registrationObj).longValue(); } } return new UnregisteredMessage(request, registrationId, reason); } UnregisteredMessage(long requestId); UnregisteredMessage(long requestId, @Nullable Long registrationId, @Nullable String reason); UnregisteredMessage(UnregisterMessage unregisterMessage); }
UnregisteredMessage extends WampMessage { public static UnregisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long registrationId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object registrationObj = details.get("registration"); if (registrationObj != null) { registrationId = ((Number) registrationObj).longValue(); } } return new UnregisteredMessage(request, registrationId, reason); } UnregisteredMessage(long requestId); UnregisteredMessage(long requestId, @Nullable Long registrationId, @Nullable String reason); UnregisteredMessage(UnregisterMessage unregisterMessage); static UnregisteredMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable Long getRegistrationId(); @Nullable String getReason(); @Override String toString(); }
UnregisteredMessage extends WampMessage { public static UnregisteredMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); Long registrationId = null; String reason = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { Map<String, Object> details = ParserUtil.readObject(jp); reason = (String) details.get("reason"); Object registrationObj = details.get("registration"); if (registrationObj != null) { registrationId = ((Number) registrationObj).longValue(); } } return new UnregisteredMessage(request, registrationId, reason); } UnregisteredMessage(long requestId); UnregisteredMessage(long requestId, @Nullable Long registrationId, @Nullable String reason); UnregisteredMessage(UnregisterMessage unregisterMessage); static UnregisteredMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable Long getRegistrationId(); @Nullable String getReason(); @Override String toString(); }
@Test public void serializeTest() { YieldMessage yieldMessage = new YieldMessage(111, null, null); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(111); assertThat(yieldMessage.getArguments()).isNull(); assertThat(yieldMessage.getArgumentsKw()).isNull(); String json = serializeToJson(yieldMessage); assertThat(json).isEqualTo("[70,111,{}]"); yieldMessage = new YieldMessage(111, Arrays.asList("Hello world"), null); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(111); assertThat(yieldMessage.getArguments()).containsExactly("Hello world"); assertThat(yieldMessage.getArgumentsKw()).isNull(); json = serializeToJson(yieldMessage); assertThat(json).isEqualTo("[70,111,{},[\"Hello world\"]]"); Map<String, Object> argumentsKw = new HashMap<>(); argumentsKw.put("firstname", "John"); argumentsKw.put("surname", "Doe"); yieldMessage = new YieldMessage(111, Arrays.asList("johnny"), argumentsKw); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(111); assertThat(yieldMessage.getArguments()).containsExactly("johnny"); assertThat(yieldMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = serializeToJson(yieldMessage); assertThat(json).isEqualTo( "[70,111,{},[\"johnny\"],{\"firstname\":\"John\",\"surname\":\"Doe\"}]"); argumentsKw = new HashMap<>(); argumentsKw.put("firstname", "John"); argumentsKw.put("surname", "Doe"); yieldMessage = new YieldMessage(111, null, argumentsKw); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(111); assertThat(yieldMessage.getArguments()).isNull(); assertThat(yieldMessage.getArgumentsKw()).containsExactly( MapEntry.entry("firstname", "John"), MapEntry.entry("surname", "Doe")); json = serializeToJson(yieldMessage); assertThat(json) .isEqualTo("[70,111,{},[],{\"firstname\":\"John\",\"surname\":\"Doe\"}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } }
YieldMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } }
YieldMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } YieldMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); }
YieldMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } YieldMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); static YieldMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
YieldMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); generator.writeEndObject(); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } YieldMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); static YieldMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
@Test public void testToInteger() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("IntegerParam", Integer.class); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, null)).isNull(); assertThat(this.invocableHandlerMethod.convert(param, (byte) 1)) .isEqualTo(Integer.valueOf(1)); assertThat(this.invocableHandlerMethod.convert(param, (short) 2)) .isEqualTo(Integer.valueOf(2)); assertThat(this.invocableHandlerMethod.convert(param, 3)) .isEqualTo(Integer.valueOf(3)); assertThat(this.invocableHandlerMethod.convert(param, 4L)) .isEqualTo(Integer.valueOf(4)); assertThat(this.invocableHandlerMethod.convert(param, 5.5f)) .isEqualTo(Integer.valueOf(5)); assertThat(this.invocableHandlerMethod.convert(param, 6.6)) .isEqualTo(Integer.valueOf(6)); assertThat(this.invocableHandlerMethod.convert(param, new BigDecimal("3.141"))) .isEqualTo(Integer.valueOf(3)); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void deserializeTest() throws IOException { String json = "[70, 6131533, {}]"; YieldMessage yieldMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(6131533L); assertThat(yieldMessage.getArguments()).isNull(); assertThat(yieldMessage.getArgumentsKw()).isNull(); json = "[70, 6131533, {}, [\"Hello, world!\"]]"; yieldMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(6131533L); assertThat(yieldMessage.getArguments()).containsExactly("Hello, world!"); assertThat(yieldMessage.getArgumentsKw()).isNull(); json = "[70, 6131533, {}, [30]]"; yieldMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(6131533L); assertThat(yieldMessage.getArguments()).containsExactly(30); assertThat(yieldMessage.getArgumentsKw()).isNull(); json = "[70, 6131533, {}, [], {\"userid\": 123, \"karma\": 10}]"; yieldMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(6131533L); assertThat(yieldMessage.getArguments()).isEmpty(); assertThat(yieldMessage.getArgumentsKw()) .containsOnly(MapEntry.entry("userid", 123), MapEntry.entry("karma", 10)); json = "[70, 6131533, {}, [\"a\",\"b\",\"c\"], {\"userid\": 123, \"karma\": 10}]"; yieldMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(yieldMessage.getCode()).isEqualTo(70); assertThat(yieldMessage.getRequestId()).isEqualTo(6131533L); assertThat(yieldMessage.getArguments()).containsExactly("a", "b", "c"); assertThat(yieldMessage.getArgumentsKw()) .containsOnly(MapEntry.entry("userid", 123), MapEntry.entry("karma", 10)); }
public static YieldMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new YieldMessage(request, arguments, argumentsKw); }
YieldMessage extends WampMessage { public static YieldMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new YieldMessage(request, arguments, argumentsKw); } }
YieldMessage extends WampMessage { public static YieldMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new YieldMessage(request, arguments, argumentsKw); } YieldMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); }
YieldMessage extends WampMessage { public static YieldMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new YieldMessage(request, arguments, argumentsKw); } YieldMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); static YieldMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
YieldMessage extends WampMessage { public static YieldMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); ParserUtil.readObject(jp); List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new YieldMessage(request, arguments, argumentsKw); } YieldMessage(long requestId, @Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw); static YieldMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
@Test public void serializeTest() { UnregisterMessage unregisterMessage = new UnregisterMessage(14, 23); assertThat(unregisterMessage.getCode()).isEqualTo(66); assertThat(unregisterMessage.getRequestId()).isEqualTo(14); assertThat(unregisterMessage.getRegistrationId()).isEqualTo(23); String json = serializeToJson(unregisterMessage); assertThat(json).isEqualTo("[66,14,23]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); }
UnregisterMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); } }
UnregisterMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); } UnregisterMessage(long requestId, long registrationId); }
UnregisterMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); } UnregisterMessage(long requestId, long registrationId); static UnregisterMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Override String toString(); }
UnregisterMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.registrationId); } UnregisterMessage(long requestId, long registrationId); static UnregisterMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[66, 788923562, 2103333224]"; UnregisterMessage unregisterMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(unregisterMessage.getCode()).isEqualTo(66); assertThat(unregisterMessage.getRequestId()).isEqualTo(788923562L); assertThat(unregisterMessage.getRegistrationId()).isEqualTo(2103333224L); }
public static UnregisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new UnregisterMessage(request, registration); }
UnregisterMessage extends WampMessage { public static UnregisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new UnregisterMessage(request, registration); } }
UnregisterMessage extends WampMessage { public static UnregisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new UnregisterMessage(request, registration); } UnregisterMessage(long requestId, long registrationId); }
UnregisterMessage extends WampMessage { public static UnregisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new UnregisterMessage(request, registration); } UnregisterMessage(long requestId, long registrationId); static UnregisterMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Override String toString(); }
UnregisterMessage extends WampMessage { public static UnregisterMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long registration = jp.getLongValue(); return new UnregisterMessage(request, registration); } UnregisterMessage(long requestId, long registrationId); static UnregisterMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getRegistrationId(); @Override String toString(); }
@Test public void serializeTest() { SubscribeMessage subscribeMessage = new SubscribeMessage(1, "topic", MatchPolicy.PREFIX, false); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(1); assertThat(subscribeMessage.getTopic()).isEqualTo("topic"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.PREFIX); assertThat(subscribeMessage.isGetRetained()).isFalse(); String json = serializeToJson(subscribeMessage); assertThat(json).isEqualTo("[32,1,{\"match\":\"prefix\"},\"topic\"]"); subscribeMessage = new SubscribeMessage(2, "topic2"); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(2); assertThat(subscribeMessage.getTopic()).isEqualTo("topic2"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.EXACT); assertThat(subscribeMessage.isGetRetained()).isFalse(); json = serializeToJson(subscribeMessage); assertThat(json).isEqualTo("[32,2,{},\"topic2\"]"); subscribeMessage = new SubscribeMessage(2, "topic2", true); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(2); assertThat(subscribeMessage.getTopic()).isEqualTo("topic2"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.EXACT); assertThat(subscribeMessage.isGetRetained()).isTrue(); json = serializeToJson(subscribeMessage); assertThat(json).isEqualTo("[32,2,{\"get_retained\":true},\"topic2\"]"); subscribeMessage = new SubscribeMessage(2, "topic2", MatchPolicy.WILDCARD, true); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(2); assertThat(subscribeMessage.getTopic()).isEqualTo("topic2"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.WILDCARD); assertThat(subscribeMessage.isGetRetained()).isTrue(); json = serializeToJson(subscribeMessage); assertThat(json).isEqualTo( "[32,2,{\"match\":\"wildcard\",\"get_retained\":true},\"topic2\"]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.matchPolicy != MatchPolicy.EXACT) { generator.writeStringField("match", this.matchPolicy.getExternalValue()); } if (this.getRetained) { generator.writeBooleanField("get_retained", this.getRetained); } generator.writeEndObject(); generator.writeString(this.topic); }
SubscribeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.matchPolicy != MatchPolicy.EXACT) { generator.writeStringField("match", this.matchPolicy.getExternalValue()); } if (this.getRetained) { generator.writeBooleanField("get_retained", this.getRetained); } generator.writeEndObject(); generator.writeString(this.topic); } }
SubscribeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.matchPolicy != MatchPolicy.EXACT) { generator.writeStringField("match", this.matchPolicy.getExternalValue()); } if (this.getRetained) { generator.writeBooleanField("get_retained", this.getRetained); } generator.writeEndObject(); generator.writeString(this.topic); } SubscribeMessage(long requestId, String topic); SubscribeMessage(long requestId, String topic, boolean get_retained); SubscribeMessage(long requestId, String topic, MatchPolicy match); SubscribeMessage(long requestId, String topic, MatchPolicy match, boolean getRetained); }
SubscribeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.matchPolicy != MatchPolicy.EXACT) { generator.writeStringField("match", this.matchPolicy.getExternalValue()); } if (this.getRetained) { generator.writeBooleanField("get_retained", this.getRetained); } generator.writeEndObject(); generator.writeString(this.topic); } SubscribeMessage(long requestId, String topic); SubscribeMessage(long requestId, String topic, boolean get_retained); SubscribeMessage(long requestId, String topic, MatchPolicy match); SubscribeMessage(long requestId, String topic, MatchPolicy match, boolean getRetained); static SubscribeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); MatchPolicy getMatchPolicy(); String getTopic(); boolean isGetRetained(); @Override String toString(); }
SubscribeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.matchPolicy != MatchPolicy.EXACT) { generator.writeStringField("match", this.matchPolicy.getExternalValue()); } if (this.getRetained) { generator.writeBooleanField("get_retained", this.getRetained); } generator.writeEndObject(); generator.writeString(this.topic); } SubscribeMessage(long requestId, String topic); SubscribeMessage(long requestId, String topic, boolean get_retained); SubscribeMessage(long requestId, String topic, MatchPolicy match); SubscribeMessage(long requestId, String topic, MatchPolicy match, boolean getRetained); static SubscribeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); MatchPolicy getMatchPolicy(); String getTopic(); boolean isGetRetained(); @Override String toString(); static final int CODE; }
@Test public void deserializeTest() throws IOException { String json = "[32,1,{\"match\":\"prefix\"},\"topic\"]"; SubscribeMessage subscribeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(1); assertThat(subscribeMessage.getTopic()).isEqualTo("topic"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.PREFIX); assertThat(subscribeMessage.isGetRetained()).isFalse(); json = "[32,2,{},\"topic2\"]"; subscribeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(2); assertThat(subscribeMessage.getTopic()).isEqualTo("topic2"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.EXACT); assertThat(subscribeMessage.isGetRetained()).isFalse(); json = "[32,2,{\"get_retained\":false},\"topic2\"]"; subscribeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(2); assertThat(subscribeMessage.getTopic()).isEqualTo("topic2"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.EXACT); assertThat(subscribeMessage.isGetRetained()).isFalse(); json = "[32,2,{\"get_retained\":true},\"topic2\"]"; subscribeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(2); assertThat(subscribeMessage.getTopic()).isEqualTo("topic2"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.EXACT); assertThat(subscribeMessage.isGetRetained()).isTrue(); json = "[32,2,{\"match\":\"wildcard\",\"get_retained\":true},\"topic2\"]"; subscribeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(subscribeMessage.getCode()).isEqualTo(32); assertThat(subscribeMessage.getRequestId()).isEqualTo(2); assertThat(subscribeMessage.getTopic()).isEqualTo("topic2"); assertThat(subscribeMessage.getMatchPolicy()).isEqualTo(MatchPolicy.WILDCARD); assertThat(subscribeMessage.isGetRetained()).isTrue(); }
public static SubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); MatchPolicy match = MatchPolicy.EXACT; jp.nextToken(); boolean getRetained = false; Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { String extValue = (String) options.get("match"); if (extValue != null) { match = MatchPolicy.fromExtValue(extValue); if (match == null) { match = MatchPolicy.EXACT; } } getRetained = (boolean) options.getOrDefault("get_retained", false); } jp.nextToken(); String topic = jp.getValueAsString(); return new SubscribeMessage(request, topic, match, getRetained); }
SubscribeMessage extends WampMessage { public static SubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); MatchPolicy match = MatchPolicy.EXACT; jp.nextToken(); boolean getRetained = false; Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { String extValue = (String) options.get("match"); if (extValue != null) { match = MatchPolicy.fromExtValue(extValue); if (match == null) { match = MatchPolicy.EXACT; } } getRetained = (boolean) options.getOrDefault("get_retained", false); } jp.nextToken(); String topic = jp.getValueAsString(); return new SubscribeMessage(request, topic, match, getRetained); } }
SubscribeMessage extends WampMessage { public static SubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); MatchPolicy match = MatchPolicy.EXACT; jp.nextToken(); boolean getRetained = false; Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { String extValue = (String) options.get("match"); if (extValue != null) { match = MatchPolicy.fromExtValue(extValue); if (match == null) { match = MatchPolicy.EXACT; } } getRetained = (boolean) options.getOrDefault("get_retained", false); } jp.nextToken(); String topic = jp.getValueAsString(); return new SubscribeMessage(request, topic, match, getRetained); } SubscribeMessage(long requestId, String topic); SubscribeMessage(long requestId, String topic, boolean get_retained); SubscribeMessage(long requestId, String topic, MatchPolicy match); SubscribeMessage(long requestId, String topic, MatchPolicy match, boolean getRetained); }
SubscribeMessage extends WampMessage { public static SubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); MatchPolicy match = MatchPolicy.EXACT; jp.nextToken(); boolean getRetained = false; Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { String extValue = (String) options.get("match"); if (extValue != null) { match = MatchPolicy.fromExtValue(extValue); if (match == null) { match = MatchPolicy.EXACT; } } getRetained = (boolean) options.getOrDefault("get_retained", false); } jp.nextToken(); String topic = jp.getValueAsString(); return new SubscribeMessage(request, topic, match, getRetained); } SubscribeMessage(long requestId, String topic); SubscribeMessage(long requestId, String topic, boolean get_retained); SubscribeMessage(long requestId, String topic, MatchPolicy match); SubscribeMessage(long requestId, String topic, MatchPolicy match, boolean getRetained); static SubscribeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); MatchPolicy getMatchPolicy(); String getTopic(); boolean isGetRetained(); @Override String toString(); }
SubscribeMessage extends WampMessage { public static SubscribeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); MatchPolicy match = MatchPolicy.EXACT; jp.nextToken(); boolean getRetained = false; Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { String extValue = (String) options.get("match"); if (extValue != null) { match = MatchPolicy.fromExtValue(extValue); if (match == null) { match = MatchPolicy.EXACT; } } getRetained = (boolean) options.getOrDefault("get_retained", false); } jp.nextToken(); String topic = jp.getValueAsString(); return new SubscribeMessage(request, topic, match, getRetained); } SubscribeMessage(long requestId, String topic); SubscribeMessage(long requestId, String topic, boolean get_retained); SubscribeMessage(long requestId, String topic, MatchPolicy match); SubscribeMessage(long requestId, String topic, MatchPolicy match, boolean getRetained); static SubscribeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); MatchPolicy getMatchPolicy(); String getTopic(); boolean isGetRetained(); @Override String toString(); static final int CODE; }
@Test public void serializeTest() { GoodbyeMessage goodbyeMessage = new GoodbyeMessage(WampError.GOODBYE_AND_OUT, "theMessage"); assertThat(goodbyeMessage.getCode()).isEqualTo(6); assertThat(goodbyeMessage.getMessage()).isEqualTo("theMessage"); assertThat(goodbyeMessage.getReason()) .isEqualTo(WampError.GOODBYE_AND_OUT.getExternalValue()); String json = serializeToJson(goodbyeMessage); assertThat(json).isEqualTo( "[6,{\"message\":\"theMessage\"},\"wamp.error.goodbye_and_out\"]"); goodbyeMessage = new GoodbyeMessage(WampError.NO_SUCH_PROCEDURE); json = serializeToJson(goodbyeMessage); assertThat(json).isEqualTo("[6,{},\"wamp.error.no_such_procedure\"]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); }
GoodbyeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); } }
GoodbyeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); } GoodbyeMessage(WampError reason, @Nullable String message); GoodbyeMessage(WampError reason); private GoodbyeMessage(String reason, @Nullable String message); }
GoodbyeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); } GoodbyeMessage(WampError reason, @Nullable String message); GoodbyeMessage(WampError reason); private GoodbyeMessage(String reason, @Nullable String message); static GoodbyeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); String getReason(); @Nullable String getMessage(); @Override String toString(); }
GoodbyeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); } GoodbyeMessage(WampError reason, @Nullable String message); GoodbyeMessage(WampError reason); private GoodbyeMessage(String reason, @Nullable String message); static GoodbyeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); String getReason(); @Nullable String getMessage(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[6, {\"message\": \"The host is shutting down now.\"},\"wamp.error.system_shutdown\"]"; GoodbyeMessage goodbyeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(goodbyeMessage.getCode()).isEqualTo(6); assertThat(goodbyeMessage.getMessage()) .isEqualTo("The host is shutting down now."); assertThat(goodbyeMessage.getReason()).isEqualTo("wamp.error.system_shutdown"); json = "[6,{},\"wamp.error.no_such_procedure\"]"; goodbyeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(goodbyeMessage.getCode()).isEqualTo(6); assertThat(goodbyeMessage.getMessage()).isNull(); assertThat(goodbyeMessage.getReason()).isEqualTo("wamp.error.no_such_procedure"); }
public static GoodbyeMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new GoodbyeMessage(jp.getValueAsString(), msg); }
GoodbyeMessage extends WampMessage { public static GoodbyeMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new GoodbyeMessage(jp.getValueAsString(), msg); } }
GoodbyeMessage extends WampMessage { public static GoodbyeMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new GoodbyeMessage(jp.getValueAsString(), msg); } GoodbyeMessage(WampError reason, @Nullable String message); GoodbyeMessage(WampError reason); private GoodbyeMessage(String reason, @Nullable String message); }
GoodbyeMessage extends WampMessage { public static GoodbyeMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new GoodbyeMessage(jp.getValueAsString(), msg); } GoodbyeMessage(WampError reason, @Nullable String message); GoodbyeMessage(WampError reason); private GoodbyeMessage(String reason, @Nullable String message); static GoodbyeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); String getReason(); @Nullable String getMessage(); @Override String toString(); }
GoodbyeMessage extends WampMessage { public static GoodbyeMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new GoodbyeMessage(jp.getValueAsString(), msg); } GoodbyeMessage(WampError reason, @Nullable String message); GoodbyeMessage(WampError reason); private GoodbyeMessage(String reason, @Nullable String message); static GoodbyeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); String getReason(); @Nullable String getMessage(); @Override String toString(); }
@Test public void serializeTest() { List<WampRole> roles = createRoles(); HelloMessage helloMessage = new HelloMessage("aRealm", roles); assertThat(helloMessage.getCode()).isEqualTo(1); assertThat(helloMessage.getRealm()).isEqualTo("aRealm"); assertThat(helloMessage.getRoles()).isEqualTo(roles); String json = serializeToJson(helloMessage); assertThat(json).isEqualTo( "[1,\"aRealm\",{\"roles\":{\"publisher\":{\"features\":{\"publisher_exclusion\":true}},\"subscriber\":{\"features\":{\"subscriber_blackwhite_listing\":true}}}}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); }
HelloMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); } }
HelloMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); } HelloMessage(@Nullable String realm, List<WampRole> roles); }
HelloMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); } HelloMessage(@Nullable String realm, List<WampRole> roles); @SuppressWarnings("unchecked") static HelloMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getRealm(); List<WampRole> getRoles(); @Override String toString(); }
HelloMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); } HelloMessage(@Nullable String realm, List<WampRole> roles); @SuppressWarnings("unchecked") static HelloMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getRealm(); List<WampRole> getRoles(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[1, \"somerealm\", { \"roles\": { \"publisher\": {}, \"subscriber\": {} } }]"; HelloMessage helloMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(helloMessage.getCode()).isEqualTo(1); assertThat(helloMessage.getRealm()).isEqualTo("somerealm"); assertThat(helloMessage.getRoles()).containsOnly(new WampRole("publisher"), new WampRole("subscriber")); json = "[1,\"aRealm\",{\"roles\":{\"publisher\":{\"features\":{\"publisher_exclusion\":true}},\"subscriber\":{\"features\":{\"subscriber_blackwhite_listing\":true}}}}]"; helloMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(helloMessage.getCode()).isEqualTo(1); assertThat(helloMessage.getRealm()).isEqualTo("aRealm"); assertThat(helloMessage.getRoles()).containsOnlyElementsOf(createRoles()); }
@SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); }
HelloMessage extends WampMessage { @SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); } }
HelloMessage extends WampMessage { @SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); } HelloMessage(@Nullable String realm, List<WampRole> roles); }
HelloMessage extends WampMessage { @SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); } HelloMessage(@Nullable String realm, List<WampRole> roles); @SuppressWarnings("unchecked") static HelloMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getRealm(); List<WampRole> getRoles(); @Override String toString(); }
HelloMessage extends WampMessage { @SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); } HelloMessage(@Nullable String realm, List<WampRole> roles); @SuppressWarnings("unchecked") static HelloMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getRealm(); List<WampRole> getRoles(); @Override String toString(); }
@SuppressWarnings({ "unchecked" }) @Test public void serializeTest() throws JsonParseException, JsonMappingException, IOException { List<WampRole> roles = createRoles(); WelcomeMessage welcomeMessage = new WelcomeMessage(9129137332L, roles, "realm"); assertThat(welcomeMessage.getCode()).isEqualTo(2); assertThat(welcomeMessage.getSessionId()).isEqualTo(9129137332L); assertThat(welcomeMessage.getRoles()).isEqualTo(roles); String json = serializeToJson(welcomeMessage); String expected = "[2,9129137332,{\"roles\":{\"dealer\":{\"features\":{\"caller_identification\":true}},\"broker\":{\"features\":{\"subscriber_blackwhite_listing\":true,\"publisher_exclusion\":true,\"publisher_identification\":true,\"pattern_based_subscription\":true}}},\"realm\":\"realm\"}]"; ObjectMapper om = new ObjectMapper(); assertThat(om.readValue(json, List.class)) .isEqualTo(om.readValue(expected, List.class)); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.sessionId); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); if (this.realm != null) { generator.writeStringField("realm", this.realm); } generator.writeEndObject(); }
WelcomeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.sessionId); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); if (this.realm != null) { generator.writeStringField("realm", this.realm); } generator.writeEndObject(); } }
WelcomeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.sessionId); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); if (this.realm != null) { generator.writeStringField("realm", this.realm); } generator.writeEndObject(); } WelcomeMessage(long sessionId, List<WampRole> roles, @Nullable String realm); WelcomeMessage(HelloMessage helloMessage, long sessionId, List<WampRole> roles); }
WelcomeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.sessionId); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); if (this.realm != null) { generator.writeStringField("realm", this.realm); } generator.writeEndObject(); } WelcomeMessage(long sessionId, List<WampRole> roles, @Nullable String realm); WelcomeMessage(HelloMessage helloMessage, long sessionId, List<WampRole> roles); @SuppressWarnings("unchecked") static WelcomeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSessionId(); List<WampRole> getRoles(); @Nullable String getRealm(); @Override String toString(); }
WelcomeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.sessionId); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); if (this.realm != null) { generator.writeStringField("realm", this.realm); } generator.writeEndObject(); } WelcomeMessage(long sessionId, List<WampRole> roles, @Nullable String realm); WelcomeMessage(HelloMessage helloMessage, long sessionId, List<WampRole> roles); @SuppressWarnings("unchecked") static WelcomeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSessionId(); List<WampRole> getRoles(); @Nullable String getRealm(); @Override String toString(); }
@Test(expected = ConversionFailedException.class) public void testToIntegerException() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("IntegerParam", Integer.class); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, "str")).isEqualTo("str"); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void deserializeTest() throws IOException { String json = "[ 2 , 9129137332 , { \"roles\" : { \"broker\" : {} }}]"; WelcomeMessage welcomeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(welcomeMessage.getCode()).isEqualTo(2); assertThat(welcomeMessage.getSessionId()).isEqualTo(9129137332L); assertThat(welcomeMessage.getRoles()).containsExactly(new WampRole("broker")); json = "[2,9129137332,{\"roles\":{\"dealer\":{\"features\":{\"caller_identification\":true}},\"broker\":{\"features\":{\"subscriber_blackwhite_listing\":true,\"publisher_exclusion\":true,\"publisher_identification\":true,\"pattern_based_subscription\":true}}},\"realm\":\"realm\"}]"; welcomeMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(welcomeMessage.getCode()).isEqualTo(2); assertThat(welcomeMessage.getSessionId()).isEqualTo(9129137332L); assertThat(welcomeMessage.getRoles()).containsOnlyElementsOf(createRoles()); }
@SuppressWarnings("unchecked") public static WelcomeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long session = jp.getLongValue(); List<WampRole> roles = new ArrayList<>(); String realm = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } realm = (String) details.get("realm"); } return new WelcomeMessage(session, roles, realm); }
WelcomeMessage extends WampMessage { @SuppressWarnings("unchecked") public static WelcomeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long session = jp.getLongValue(); List<WampRole> roles = new ArrayList<>(); String realm = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } realm = (String) details.get("realm"); } return new WelcomeMessage(session, roles, realm); } }
WelcomeMessage extends WampMessage { @SuppressWarnings("unchecked") public static WelcomeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long session = jp.getLongValue(); List<WampRole> roles = new ArrayList<>(); String realm = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } realm = (String) details.get("realm"); } return new WelcomeMessage(session, roles, realm); } WelcomeMessage(long sessionId, List<WampRole> roles, @Nullable String realm); WelcomeMessage(HelloMessage helloMessage, long sessionId, List<WampRole> roles); }
WelcomeMessage extends WampMessage { @SuppressWarnings("unchecked") public static WelcomeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long session = jp.getLongValue(); List<WampRole> roles = new ArrayList<>(); String realm = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } realm = (String) details.get("realm"); } return new WelcomeMessage(session, roles, realm); } WelcomeMessage(long sessionId, List<WampRole> roles, @Nullable String realm); WelcomeMessage(HelloMessage helloMessage, long sessionId, List<WampRole> roles); @SuppressWarnings("unchecked") static WelcomeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSessionId(); List<WampRole> getRoles(); @Nullable String getRealm(); @Override String toString(); }
WelcomeMessage extends WampMessage { @SuppressWarnings("unchecked") public static WelcomeMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long session = jp.getLongValue(); List<WampRole> roles = new ArrayList<>(); String realm = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } realm = (String) details.get("realm"); } return new WelcomeMessage(session, roles, realm); } WelcomeMessage(long sessionId, List<WampRole> roles, @Nullable String realm); WelcomeMessage(HelloMessage helloMessage, long sessionId, List<WampRole> roles); @SuppressWarnings("unchecked") static WelcomeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSessionId(); List<WampRole> getRoles(); @Nullable String getRealm(); @Override String toString(); }
@Test public void serializeTest() { SubscribedMessage subscribedMessage = new SubscribedMessage(1, 2); assertThat(subscribedMessage.getCode()).isEqualTo(33); assertThat(subscribedMessage.getRequestId()).isEqualTo(1); assertThat(subscribedMessage.getSubscriptionId()).isEqualTo(2); String json = serializeToJson(subscribedMessage); assertThat(json).isEqualTo("[33,1,2]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); }
SubscribedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); } }
SubscribedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); } SubscribedMessage(long requestId, long subscriptionId); SubscribedMessage(SubscribeMessage subscribeMessage, long subscriptionId); }
SubscribedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); } SubscribedMessage(long requestId, long subscriptionId); SubscribedMessage(SubscribeMessage subscribeMessage, long subscriptionId); static SubscribedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getSubscriptionId(); @Override String toString(); }
SubscribedMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeNumber(this.subscriptionId); } SubscribedMessage(long requestId, long subscriptionId); SubscribedMessage(SubscribeMessage subscribeMessage, long subscriptionId); static SubscribedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getSubscriptionId(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[33, 713845233, 5512315355]"; SubscribedMessage subscribedMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(subscribedMessage.getCode()).isEqualTo(33); assertThat(subscribedMessage.getRequestId()).isEqualTo(713845233L); assertThat(subscribedMessage.getSubscriptionId()).isEqualTo(5512315355L); }
public static SubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new SubscribedMessage(request, subscription); }
SubscribedMessage extends WampMessage { public static SubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new SubscribedMessage(request, subscription); } }
SubscribedMessage extends WampMessage { public static SubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new SubscribedMessage(request, subscription); } SubscribedMessage(long requestId, long subscriptionId); SubscribedMessage(SubscribeMessage subscribeMessage, long subscriptionId); }
SubscribedMessage extends WampMessage { public static SubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new SubscribedMessage(request, subscription); } SubscribedMessage(long requestId, long subscriptionId); SubscribedMessage(SubscribeMessage subscribeMessage, long subscriptionId); static SubscribedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getSubscriptionId(); @Override String toString(); }
SubscribedMessage extends WampMessage { public static SubscribedMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); jp.nextToken(); long subscription = jp.getLongValue(); return new SubscribedMessage(request, subscription); } SubscribedMessage(long requestId, long subscriptionId); SubscribedMessage(SubscribeMessage subscribeMessage, long subscriptionId); static SubscribedMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); long getSubscriptionId(); @Override String toString(); }
@SuppressWarnings("resource") @Test public void testReadArray() throws JsonParseException, IOException { ObjectMapper om = new ObjectMapper(); JsonParser jp = om.getFactory().createParser("\"test\""); jp.nextToken(); assertThat(ParserUtil.readArray(jp)).isNull(); jp = om.getFactory().createParser("[1,2,3]"); jp.nextToken(); assertThat(ParserUtil.readArray(jp)).containsExactly(1, 2, 3); jp = om.getFactory().createParser("[[\"k\",\"l\",\"m\"],[\"a\",\"b\",\"c\"]]"); jp.nextToken(); assertThat(ParserUtil.readArray(jp)).containsExactly(Arrays.asList("k", "l", "m"), Arrays.asList("a", "b", "c")); }
@Nullable public static List<Object> readArray(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_ARRAY) { return null; } List<Object> result = new ArrayList<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_ARRAY) { if (token == JsonToken.START_ARRAY) { result.add(readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.add(readObject(jp)); } else { result.add(getValue(jp)); } token = jp.nextToken(); } return result; }
ParserUtil { @Nullable public static List<Object> readArray(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_ARRAY) { return null; } List<Object> result = new ArrayList<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_ARRAY) { if (token == JsonToken.START_ARRAY) { result.add(readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.add(readObject(jp)); } else { result.add(getValue(jp)); } token = jp.nextToken(); } return result; } }
ParserUtil { @Nullable public static List<Object> readArray(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_ARRAY) { return null; } List<Object> result = new ArrayList<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_ARRAY) { if (token == JsonToken.START_ARRAY) { result.add(readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.add(readObject(jp)); } else { result.add(getValue(jp)); } token = jp.nextToken(); } return result; } }
ParserUtil { @Nullable public static List<Object> readArray(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_ARRAY) { return null; } List<Object> result = new ArrayList<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_ARRAY) { if (token == JsonToken.START_ARRAY) { result.add(readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.add(readObject(jp)); } else { result.add(getValue(jp)); } token = jp.nextToken(); } return result; } @Nullable static List<Object> readArray(JsonParser jp); @Nullable static Map<String, Object> readObject(JsonParser jp); }
ParserUtil { @Nullable public static List<Object> readArray(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_ARRAY) { return null; } List<Object> result = new ArrayList<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_ARRAY) { if (token == JsonToken.START_ARRAY) { result.add(readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.add(readObject(jp)); } else { result.add(getValue(jp)); } token = jp.nextToken(); } return result; } @Nullable static List<Object> readArray(JsonParser jp); @Nullable static Map<String, Object> readObject(JsonParser jp); }
@SuppressWarnings({ "resource", "unchecked" }) @Test public void testReadObject() throws JsonParseException, IOException { ObjectMapper om = new ObjectMapper(); JsonParser jp = om.getFactory().createParser("\"test\""); jp.nextToken(); assertThat(ParserUtil.readArray(jp)).isNull(); jp = om.getFactory().createParser("{\"key1\":1,\"key2\":2}"); jp.nextToken(); assertThat(ParserUtil.readObject(jp)).containsOnly(MapEntry.entry("key1", 1), MapEntry.entry("key2", 2)); jp = om.getFactory().createParser("{\"keyA\":1.1,\"keyB\":2.2}"); jp.nextToken(); assertThat(ParserUtil.readObject(jp)).containsOnly(MapEntry.entry("keyA", 1.1), MapEntry.entry("keyB", 2.2)); jp = om.getFactory().createParser("{\"k1\":\"one\",\"k2\":\"two\"}"); jp.nextToken(); assertThat(ParserUtil.readObject(jp)).containsOnly(MapEntry.entry("k1", "one"), MapEntry.entry("k2", "two")); jp = om.getFactory().createParser("{\"k1\":true,\"k2\":false, \"k3\":null}"); jp.nextToken(); assertThat(ParserUtil.readObject(jp)).containsOnly(MapEntry.entry("k1", true), MapEntry.entry("k2", false), MapEntry.entry("k3", null)); jp = om.getFactory().createParser( "{\"o1\":{\"a1\":1,\"a2\":2},\"o2\":{\"b1\":11,\"b2\":22},\"o3\":{\"c1\":111,\"c2\":222}}"); jp.nextToken(); Map<String, Object> m = ParserUtil.readObject(jp); assertThat(m).containsKeys("o1", "o2", "o3"); assertThat((Map<String, Object>) m.get("o1")) .containsOnly(MapEntry.entry("a1", 1), MapEntry.entry("a2", 2)); assertThat((Map<String, Object>) m.get("o2")) .containsOnly(MapEntry.entry("b1", 11), MapEntry.entry("b2", 22)); assertThat((Map<String, Object>) m.get("o3")) .containsOnly(MapEntry.entry("c1", 111), MapEntry.entry("c2", 222)); }
@Nullable public static Map<String, Object> readObject(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_OBJECT) { return null; } Map<String, Object> result = new HashMap<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_OBJECT) { String key = jp.getText(); token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { result.put(key, readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.put(key, readObject(jp)); } else { result.put(key, getValue(jp)); } token = jp.nextToken(); } return result; }
ParserUtil { @Nullable public static Map<String, Object> readObject(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_OBJECT) { return null; } Map<String, Object> result = new HashMap<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_OBJECT) { String key = jp.getText(); token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { result.put(key, readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.put(key, readObject(jp)); } else { result.put(key, getValue(jp)); } token = jp.nextToken(); } return result; } }
ParserUtil { @Nullable public static Map<String, Object> readObject(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_OBJECT) { return null; } Map<String, Object> result = new HashMap<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_OBJECT) { String key = jp.getText(); token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { result.put(key, readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.put(key, readObject(jp)); } else { result.put(key, getValue(jp)); } token = jp.nextToken(); } return result; } }
ParserUtil { @Nullable public static Map<String, Object> readObject(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_OBJECT) { return null; } Map<String, Object> result = new HashMap<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_OBJECT) { String key = jp.getText(); token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { result.put(key, readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.put(key, readObject(jp)); } else { result.put(key, getValue(jp)); } token = jp.nextToken(); } return result; } @Nullable static List<Object> readArray(JsonParser jp); @Nullable static Map<String, Object> readObject(JsonParser jp); }
ParserUtil { @Nullable public static Map<String, Object> readObject(JsonParser jp) throws IOException { if (jp.currentToken() != JsonToken.START_OBJECT) { return null; } Map<String, Object> result = new HashMap<>(); JsonToken token = jp.nextToken(); while (token != JsonToken.END_OBJECT) { String key = jp.getText(); token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { result.put(key, readArray(jp)); } else if (token == JsonToken.START_OBJECT) { result.put(key, readObject(jp)); } else { result.put(key, getValue(jp)); } token = jp.nextToken(); } return result; } @Nullable static List<Object> readArray(JsonParser jp); @Nullable static Map<String, Object> readObject(JsonParser jp); }
@Test public void serializeTest() { AbortMessage abortMessage = new AbortMessage(WampError.NO_SUCH_REGISTRATION, "No such registration"); assertThat(abortMessage.getCode()).isEqualTo(3); assertThat(abortMessage.getMessage()).isEqualTo("No such registration"); assertThat(abortMessage.getReason()).isEqualTo("wamp.error.no_such_registration"); String json = serializeToJson(abortMessage); assertThat(json).isEqualTo( "[3,{\"message\":\"No such registration\"},\"wamp.error.no_such_registration\"]"); abortMessage = new AbortMessage(WampError.NO_SUCH_REGISTRATION); assertThat(abortMessage.getCode()).isEqualTo(3); assertThat(abortMessage.getMessage()).isNull(); assertThat(abortMessage.getReason()).isEqualTo("wamp.error.no_such_registration"); json = serializeToJson(abortMessage); assertThat(json).isEqualTo("[3,{},\"wamp.error.no_such_registration\"]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); }
AbortMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); } }
AbortMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); } AbortMessage(WampError reason, @Nullable String message); AbortMessage(WampError reason); private AbortMessage(String reason, @Nullable String message); }
AbortMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); } AbortMessage(WampError reason, @Nullable String message); AbortMessage(WampError reason); private AbortMessage(String reason, @Nullable String message); static AbortMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getMessage(); @Nullable String getReason(); @Override String toString(); }
AbortMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeStartObject(); if (this.message != null) { generator.writeStringField("message", this.message); } generator.writeEndObject(); generator.writeString(this.reason); } AbortMessage(WampError reason, @Nullable String message); AbortMessage(WampError reason); private AbortMessage(String reason, @Nullable String message); static AbortMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getMessage(); @Nullable String getReason(); @Override String toString(); }
@Test public void deserializeTest() throws IOException { String json = "[3, {\"message\": \"The realm does not exist.\"}, \"wamp.error.no_such_realm\"]"; AbortMessage abortMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(abortMessage.getCode()).isEqualTo(3); assertThat(abortMessage.getMessage()).isEqualTo("The realm does not exist."); assertThat(abortMessage.getReason()).isEqualTo("wamp.error.no_such_realm"); json = "[3, {}, \"wamp.error.no_such_realm\"]"; abortMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(abortMessage.getCode()).isEqualTo(3); assertThat(abortMessage.getMessage()).isNull(); assertThat(abortMessage.getReason()).isEqualTo("wamp.error.no_such_realm"); }
public static AbortMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new AbortMessage(jp.getValueAsString(), msg); }
AbortMessage extends WampMessage { public static AbortMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new AbortMessage(jp.getValueAsString(), msg); } }
AbortMessage extends WampMessage { public static AbortMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new AbortMessage(jp.getValueAsString(), msg); } AbortMessage(WampError reason, @Nullable String message); AbortMessage(WampError reason); private AbortMessage(String reason, @Nullable String message); }
AbortMessage extends WampMessage { public static AbortMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new AbortMessage(jp.getValueAsString(), msg); } AbortMessage(WampError reason, @Nullable String message); AbortMessage(WampError reason); private AbortMessage(String reason, @Nullable String message); static AbortMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getMessage(); @Nullable String getReason(); @Override String toString(); }
AbortMessage extends WampMessage { public static AbortMessage deserialize(JsonParser jp) throws IOException { String msg = null; jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { msg = (String) details.get("message"); } jp.nextToken(); return new AbortMessage(jp.getValueAsString(), msg); } AbortMessage(WampError reason, @Nullable String message); AbortMessage(WampError reason); private AbortMessage(String reason, @Nullable String message); static AbortMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getMessage(); @Nullable String getReason(); @Override String toString(); }
@Test public void testPublishToAll() { this.wampPublisher.publishToAll("topic", 1); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic", Collections.singletonList(1), null, null); }
public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToAllList() { List<String> value = Arrays.asList("a", "b", "c"); this.wampPublisher.publishToAll("topic2", value); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic2", value, null, null); }
public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToAllMap() { Map<String, Integer> mapValue = new HashMap<>(); mapValue.put("one", 1); mapValue.put("two", 2); mapValue.put("three", 3); this.wampPublisher.publishToAll("topic3", mapValue); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic3", mapValue, null, null); }
public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAll(String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testToBigDecimal() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("BigDecimalParam", BigDecimal.class); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, null)).isNull(); assertThat(this.invocableHandlerMethod.convert(param, (byte) 1)) .isEqualTo(new BigDecimal("1")); assertThat(this.invocableHandlerMethod.convert(param, (short) 2)) .isEqualTo(new BigDecimal("2")); assertThat(this.invocableHandlerMethod.convert(param, 3)) .isEqualTo(new BigDecimal("3")); assertThat(this.invocableHandlerMethod.convert(param, 4L)) .isEqualTo(new BigDecimal("4")); assertThat(this.invocableHandlerMethod.convert(param, 5.5f)) .isEqualTo(new BigDecimal("5.5")); assertThat(this.invocableHandlerMethod.convert(param, 6.6)) .isEqualTo(new BigDecimal("6.6")); assertThat(this.invocableHandlerMethod.convert(param, new BigDecimal("3.141"))) .isEqualTo(new BigDecimal("3.141")); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void testPublishTo() { this.wampPublisher.publishTo(Collections.singleton(123L), "topic", 1); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic", Collections.singletonList(1), Collections.singleton(123L), null); }
public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToOneCollection() { this.wampPublisher.publishTo(124L, "topic1", Arrays.asList(1, 2, 3, 4)); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic1", Arrays.asList(1, 2, 3, 4), Collections.singleton(124L), null); }
public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToOneMap() { Map<String, Object> data = new HashMap<>(); data.put("one", 1); data.put("two", 2); this.wampPublisher.publishTo(125L, "topic2", data); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic2", data, Collections.singleton(125L), null); }
public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToList() { List<String> value = Arrays.asList("a", "b", "c"); this.wampPublisher.publishTo(Collections.singleton(123L), "topic2", value); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic2", value, Collections.singleton(123L), null); }
public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToMap() { Map<String, Integer> mapValue = new HashMap<>(); mapValue.put("one", 1); mapValue.put("two", 2); mapValue.put("three", 3); this.wampPublisher.publishTo(Collections.singleton(123L), "topic3", mapValue); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic3", mapValue, Collections.singleton(123L), null); }
public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .eligible(CollectionHelper.toSet(eligibleWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToAllExcept() { this.wampPublisher.publishToAllExcept(Collections.singleton(123L), "topic", 1); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic", Collections.singletonList(1), null, Collections.singleton(123L)); }
public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToAllExceptOne() { this.wampPublisher.publishToAllExcept(124, "topic1", 2); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic1", Collections.singletonList(2), null, Collections.singleton(124L)); }
public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToAllExceptOneCollection() { this.wampPublisher.publishToAllExcept(125, "topic2", Arrays.asList(1, 2, 3)); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic2", Arrays.asList(1, 2, 3), null, Collections.singleton(125L)); }
public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToAllExceptOneMap() { Map<String, Integer> mapValue = new HashMap<>(); mapValue.put("one", 1); mapValue.put("two", 2); mapValue.put("three", 3); this.wampPublisher.publishToAllExcept(126, "topic3", mapValue); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic3", mapValue, null, Collections.singleton(126L)); }
public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void testPublishToAllExceptList() { List<String> value = Arrays.asList("a", "b", "c"); this.wampPublisher.publishToAllExcept(Collections.singleton(123L), "topic2", value); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic2", value, null, Collections.singleton(123L)); }
public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test(expected = ConversionFailedException.class) public void testToBigDecimalException() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("BigDecimalParam", BigDecimal.class); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, "str")).isEqualTo("str"); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void testPublishToAllExceptMap() { Map<String, Integer> mapValue = new HashMap<>(); mapValue.put("one", 1); mapValue.put("two", 2); mapValue.put("three", 3); this.wampPublisher.publishToAllExcept(Collections.singleton(123L), "topic3", mapValue); Mockito.verify(this.clientOutboundChannel, Mockito.times(1)) .send(this.messageCaptor.capture()); PublishMessage publishMessage = this.messageCaptor.getValue(); assertPublishMessage(publishMessage, "topic3", mapValue, null, Collections.singleton(123L)); }
public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
WampPublisher { public <T> void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments) { publish(publishMessageBuilder(topic).arguments(CollectionHelper.toList(arguments)) .exclude(CollectionHelper.toSet(excludeWampSessionIds)).build()); } WampPublisher(MessageChannel clientInboundChannel); void publish(PublishMessage publishMessage); void publishToAll(String topic, @Nullable T... arguments); void publishToAll(String topic, @Nullable Collection<T> arguments); void publishToAll(String topic, @Nullable Map<String, T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable T... arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishTo(Collection<Long> eligibleWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable T... arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Collection<T> arguments); void publishTo(long eligibleWampSessionId, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable T... arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(Collection<Long> excludeWampSessionIds, String topic, @Nullable Map<String, T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable T... arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Collection<T> arguments); void publishToAllExcept(long excludeWampSessionId, String topic, @Nullable Map<String, T> arguments); Builder publishMessageBuilder(String topic); }
@Test public void supportsParameterTest() { assertThat(this.resolver.supportsParameter(this.wampSessionIdParameter)).isTrue(); assertThat(this.resolver.supportsParameter(this.stringParameter)).isFalse(); }
@Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(WampSessionId.class); }
WampSessionIdMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(WampSessionId.class); } }
WampSessionIdMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(WampSessionId.class); } }
WampSessionIdMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(WampSessionId.class); } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
WampSessionIdMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(WampSessionId.class); } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
@Test public void resolveArgumentTest() throws Exception { CallMessage callMessage = new CallMessage(1, "call"); callMessage.setHeader(WampMessageHeader.WAMP_SESSION_ID, 23L); assertThat( this.resolver.resolveArgument(this.wampSessionIdParameter, callMessage)) .isEqualTo(23L); }
@Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message.getHeaders().get(WampMessageHeader.WAMP_SESSION_ID.name()); }
WampSessionIdMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message.getHeaders().get(WampMessageHeader.WAMP_SESSION_ID.name()); } }
WampSessionIdMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message.getHeaders().get(WampMessageHeader.WAMP_SESSION_ID.name()); } }
WampSessionIdMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message.getHeaders().get(WampMessageHeader.WAMP_SESSION_ID.name()); } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
WampSessionIdMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message.getHeaders().get(WampMessageHeader.WAMP_SESSION_ID.name()); } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
@Test public void supportsParameterTest() { assertThat(this.resolver.supportsParameter(this.principalParameter)).isTrue(); assertThat(this.resolver.supportsParameter(this.stringParameter)).isFalse(); }
@Override public boolean supportsParameter(MethodParameter parameter) { Class<?> paramType = parameter.getParameterType(); return Principal.class.isAssignableFrom(paramType); }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { Class<?> paramType = parameter.getParameterType(); return Principal.class.isAssignableFrom(paramType); } }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { Class<?> paramType = parameter.getParameterType(); return Principal.class.isAssignableFrom(paramType); } }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { Class<?> paramType = parameter.getParameterType(); return Principal.class.isAssignableFrom(paramType); } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { Class<?> paramType = parameter.getParameterType(); return Principal.class.isAssignableFrom(paramType); } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
@Test public void resolveArgumentTest() throws Exception { CallMessage callMessage = new CallMessage(1, "call"); TestPrincipal testPrincipal = new TestPrincipal("testPrincipal"); callMessage.setHeader(WampMessageHeader.PRINCIPAL, testPrincipal); assertThat(this.resolver.resolveArgument(this.principalParameter, callMessage)) .isEqualTo(testPrincipal); }
@Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; } }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; } }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
@Test(expected = MessageHandlingException.class) public void missingPrincipalTest() throws Exception { CallMessage callMessage = new CallMessage(1, "call"); TestPrincipal testPrincipal = new TestPrincipal("testPrincipal"); assertThat(this.resolver.resolveArgument(this.principalParameter, callMessage)) .isEqualTo(testPrincipal); }
@Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; } }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; } }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Principal user = ((WampMessage) message).getPrincipal(); if (user == null) { throw new MessageHandlingException(message, "No \"PRINCIPAL\" header in message"); } return user; } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
@Test public void supportsParameterTest() { assertThat(this.resolver.supportsParameter(this.messageParameter)).isTrue(); assertThat(this.resolver.supportsParameter(this.stringParameter)).isFalse(); }
@Override public boolean supportsParameter(MethodParameter parameter) { return WampMessage.class.isAssignableFrom(parameter.getParameterType()); }
WampMessageMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { return WampMessage.class.isAssignableFrom(parameter.getParameterType()); } }
WampMessageMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { return WampMessage.class.isAssignableFrom(parameter.getParameterType()); } }
WampMessageMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { return WampMessage.class.isAssignableFrom(parameter.getParameterType()); } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
WampMessageMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { return WampMessage.class.isAssignableFrom(parameter.getParameterType()); } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
@Test public void resolveArgumentTest() throws Exception { CallMessage callMessage = new CallMessage(1, "call"); assertThat(this.resolver.resolveArgument(this.messageParameter, callMessage)) .isEqualTo(callMessage); }
@Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message; }
WampMessageMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message; } }
WampMessageMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message; } }
WampMessageMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message; } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
WampMessageMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return message; } @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, Message<?> message); }
@Test public void testEnabledDealerFeatures() { Features feat = new Features(); assertThat(feat.enabledDealerFeatures()) .containsExactly(Feature.DEALER_CALLER_IDENTIFICATION); feat.disable(Feature.DEALER_CALLER_IDENTIFICATION); assertThat(feat.enabledDealerFeatures()).isEmpty(); }
public List<Feature> enabledDealerFeatures() { List<Feature> dealerFeatures = new ArrayList<>(); if (isEnabled(Feature.DEALER_CALLER_IDENTIFICATION)) { dealerFeatures.add(Feature.DEALER_CALLER_IDENTIFICATION); } return dealerFeatures; }
Features { public List<Feature> enabledDealerFeatures() { List<Feature> dealerFeatures = new ArrayList<>(); if (isEnabled(Feature.DEALER_CALLER_IDENTIFICATION)) { dealerFeatures.add(Feature.DEALER_CALLER_IDENTIFICATION); } return dealerFeatures; } }
Features { public List<Feature> enabledDealerFeatures() { List<Feature> dealerFeatures = new ArrayList<>(); if (isEnabled(Feature.DEALER_CALLER_IDENTIFICATION)) { dealerFeatures.add(Feature.DEALER_CALLER_IDENTIFICATION); } return dealerFeatures; } }
Features { public List<Feature> enabledDealerFeatures() { List<Feature> dealerFeatures = new ArrayList<>(); if (isEnabled(Feature.DEALER_CALLER_IDENTIFICATION)) { dealerFeatures.add(Feature.DEALER_CALLER_IDENTIFICATION); } return dealerFeatures; } void disable(Feature feature); boolean isEnabled(Feature feature); boolean isDisabled(Feature feature); List<Feature> enabledDealerFeatures(); List<Feature> enabledBrokerFeatures(); }
Features { public List<Feature> enabledDealerFeatures() { List<Feature> dealerFeatures = new ArrayList<>(); if (isEnabled(Feature.DEALER_CALLER_IDENTIFICATION)) { dealerFeatures.add(Feature.DEALER_CALLER_IDENTIFICATION); } return dealerFeatures; } void disable(Feature feature); boolean isEnabled(Feature feature); boolean isDisabled(Feature feature); List<Feature> enabledDealerFeatures(); List<Feature> enabledBrokerFeatures(); }
@Test public void testEnabledBrokerFeatures() { Features feat = new Features(); assertThat(feat.enabledBrokerFeatures()).containsExactly( Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING, Feature.BROKER_PUBLISHER_EXCLUSION, Feature.BROKER_PUBLISHER_IDENTIFICATION, Feature.BROKER_PATTERN_BASED_SUBSCRIPTION, Feature.BROKER_EVENT_RETENTION); feat.disable(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING); assertThat(feat.enabledBrokerFeatures()).containsExactly( Feature.BROKER_PUBLISHER_EXCLUSION, Feature.BROKER_PUBLISHER_IDENTIFICATION, Feature.BROKER_PATTERN_BASED_SUBSCRIPTION, Feature.BROKER_EVENT_RETENTION); feat.disable(Feature.BROKER_PUBLISHER_EXCLUSION); assertThat(feat.enabledBrokerFeatures()).containsExactly( Feature.BROKER_PUBLISHER_IDENTIFICATION, Feature.BROKER_PATTERN_BASED_SUBSCRIPTION, Feature.BROKER_EVENT_RETENTION); feat.disable(Feature.BROKER_PUBLISHER_IDENTIFICATION); assertThat(feat.enabledBrokerFeatures()).containsExactly( Feature.BROKER_PATTERN_BASED_SUBSCRIPTION, Feature.BROKER_EVENT_RETENTION); feat.disable(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION); assertThat(feat.enabledBrokerFeatures()) .containsExactly(Feature.BROKER_EVENT_RETENTION); feat.disable(Feature.BROKER_EVENT_RETENTION); assertThat(feat.enabledBrokerFeatures()).isEmpty(); }
public List<Feature> enabledBrokerFeatures() { List<Feature> brokerFeatures = new ArrayList<>(); if (isEnabled(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING)) { brokerFeatures.add(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING); } if (isEnabled(Feature.BROKER_PUBLISHER_EXCLUSION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_EXCLUSION); } if (isEnabled(Feature.BROKER_PUBLISHER_IDENTIFICATION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_IDENTIFICATION); } if (isEnabled(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION)) { brokerFeatures.add(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION); } if (isEnabled(Feature.BROKER_EVENT_RETENTION)) { brokerFeatures.add(Feature.BROKER_EVENT_RETENTION); } return brokerFeatures; }
Features { public List<Feature> enabledBrokerFeatures() { List<Feature> brokerFeatures = new ArrayList<>(); if (isEnabled(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING)) { brokerFeatures.add(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING); } if (isEnabled(Feature.BROKER_PUBLISHER_EXCLUSION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_EXCLUSION); } if (isEnabled(Feature.BROKER_PUBLISHER_IDENTIFICATION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_IDENTIFICATION); } if (isEnabled(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION)) { brokerFeatures.add(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION); } if (isEnabled(Feature.BROKER_EVENT_RETENTION)) { brokerFeatures.add(Feature.BROKER_EVENT_RETENTION); } return brokerFeatures; } }
Features { public List<Feature> enabledBrokerFeatures() { List<Feature> brokerFeatures = new ArrayList<>(); if (isEnabled(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING)) { brokerFeatures.add(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING); } if (isEnabled(Feature.BROKER_PUBLISHER_EXCLUSION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_EXCLUSION); } if (isEnabled(Feature.BROKER_PUBLISHER_IDENTIFICATION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_IDENTIFICATION); } if (isEnabled(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION)) { brokerFeatures.add(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION); } if (isEnabled(Feature.BROKER_EVENT_RETENTION)) { brokerFeatures.add(Feature.BROKER_EVENT_RETENTION); } return brokerFeatures; } }
Features { public List<Feature> enabledBrokerFeatures() { List<Feature> brokerFeatures = new ArrayList<>(); if (isEnabled(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING)) { brokerFeatures.add(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING); } if (isEnabled(Feature.BROKER_PUBLISHER_EXCLUSION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_EXCLUSION); } if (isEnabled(Feature.BROKER_PUBLISHER_IDENTIFICATION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_IDENTIFICATION); } if (isEnabled(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION)) { brokerFeatures.add(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION); } if (isEnabled(Feature.BROKER_EVENT_RETENTION)) { brokerFeatures.add(Feature.BROKER_EVENT_RETENTION); } return brokerFeatures; } void disable(Feature feature); boolean isEnabled(Feature feature); boolean isDisabled(Feature feature); List<Feature> enabledDealerFeatures(); List<Feature> enabledBrokerFeatures(); }
Features { public List<Feature> enabledBrokerFeatures() { List<Feature> brokerFeatures = new ArrayList<>(); if (isEnabled(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING)) { brokerFeatures.add(Feature.BROKER_SUBSCRIBER_BLACKWHITE_LISTING); } if (isEnabled(Feature.BROKER_PUBLISHER_EXCLUSION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_EXCLUSION); } if (isEnabled(Feature.BROKER_PUBLISHER_IDENTIFICATION)) { brokerFeatures.add(Feature.BROKER_PUBLISHER_IDENTIFICATION); } if (isEnabled(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION)) { brokerFeatures.add(Feature.BROKER_PATTERN_BASED_SUBSCRIPTION); } if (isEnabled(Feature.BROKER_EVENT_RETENTION)) { brokerFeatures.add(Feature.BROKER_EVENT_RETENTION); } return brokerFeatures; } void disable(Feature feature); boolean isEnabled(Feature feature); boolean isDisabled(Feature feature); List<Feature> enabledDealerFeatures(); List<Feature> enabledBrokerFeatures(); }
@SuppressWarnings("rawtypes") @Test public void testToOptional() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("OptionalParam", Optional.class); MethodParameter param = new MethodParameter(testMethod, 0); Object value = this.invocableHandlerMethod.convert(param, null); assertThat(value).isEqualTo(Optional.empty()); value = this.invocableHandlerMethod.convert(param, "str"); assertThat(value).isInstanceOf(Optional.class); assertThat(((Optional) value).get()).isEqualTo("str"); value = this.invocableHandlerMethod.convert(param, (byte) 1); assertThat(value).isInstanceOf(Optional.class); assertThat(((Optional) value).get()).isEqualTo((byte) 1); value = this.invocableHandlerMethod.convert(param, (short) 2); assertThat(value).isInstanceOf(Optional.class); assertThat(((Optional) value).get()).isEqualTo((short) 2); value = this.invocableHandlerMethod.convert(param, 3); assertThat(value).isInstanceOf(Optional.class); assertThat(((Optional) value).get()).isEqualTo(3); value = this.invocableHandlerMethod.convert(param, 4L); assertThat(value).isInstanceOf(Optional.class); assertThat(((Optional) value).get()).isEqualTo(4L); value = this.invocableHandlerMethod.convert(param, 5.5f); assertThat(value).isInstanceOf(Optional.class); assertThat(((Optional) value).get()).isEqualTo(5.5f); value = this.invocableHandlerMethod.convert(param, 6.6); assertThat(value).isInstanceOf(Optional.class); assertThat(((Optional) value).get()).isEqualTo(6.6); value = this.invocableHandlerMethod.convert(param, new BigDecimal("3.141")); assertThat(value).isInstanceOf(Optional.class); assertThat(((Optional) value).get()).isEqualTo(new BigDecimal("3.141")); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void testDto() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("dtoParam", TestDto.class); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, null)).isNull(); TestDto dto = new TestDto(); dto.setV1("str"); dto.setV2(1); dto.setV3(Integer.valueOf(2)); dto.setV4(new BigDecimal("3.1")); assertThat(this.invocableHandlerMethod.convert(param, dto)).isEqualTo(dto); Map<String, Object> fromJson = new HashMap<>(); fromJson.put("v1", "str"); fromJson.put("v2", 1); fromJson.put("v3", 2); fromJson.put("v4", "3.1"); assertThat(this.invocableHandlerMethod.convert(param, fromJson)).isEqualTo(dto); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testToList() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("listParam", List.class); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, null)).isNull(); assertThat((List) this.invocableHandlerMethod.convert(param, "1")).hasSize(1) .containsExactly("1"); assertThat( (List) this.invocableHandlerMethod.convert(param, Arrays.asList(1, 2, 3))) .hasSize(3).containsExactly("1", "2", "3"); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers( HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer( ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments, Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
@Test public void duplicateChangeSetException() throws Exception { DuplicateChangeSetException duplicateChangeSetException = new DuplicateChangeSetException("MESSAGE HERE"); assertEquals("MESSAGE HERE", duplicateChangeSetException.getMessage()); }
public DuplicateChangeSetException(String message) { super(message); }
DuplicateChangeSetException extends LiquibaseException { public DuplicateChangeSetException(String message) { super(message); } }
DuplicateChangeSetException extends LiquibaseException { public DuplicateChangeSetException(String message) { super(message); } DuplicateChangeSetException(String message); }
DuplicateChangeSetException extends LiquibaseException { public DuplicateChangeSetException(String message) { super(message); } DuplicateChangeSetException(String message); }
DuplicateChangeSetException extends LiquibaseException { public DuplicateChangeSetException(String message) { super(message); } DuplicateChangeSetException(String message); }
@Test public void createNode_addColumnChange() throws Exception { AddColumnChange refactoring = new AddColumnChange(); refactoring.setTableName("TAB"); ColumnConfig column = new ColumnConfig(); column.setName("NEWCOL"); column.setType("TYP"); refactoring.addColumn(column); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(refactoring); assertEquals("addColumn", node.getTagName()); assertEquals("TAB", node.getAttribute("tableName")); NodeList columns = node.getElementsByTagName("column"); assertEquals(1, columns.getLength()); assertEquals("column", ((Element) columns.item(0)).getTagName()); assertEquals("NEWCOL", ((Element) columns.item(0)).getAttribute("name")); assertEquals("TYP", ((Element) columns.item(0)).getAttribute("type")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_AddDefaultValueChange() throws Exception { AddDefaultValueChange change = new AddDefaultValueChange(); change.setSchemaName("SCHEMA_NAME"); change.setTableName("TABLE_NAME"); change.setColumnName("COLUMN_NAME"); change.setDefaultValue("DEF STRING"); change.setDefaultValueNumeric("42"); change.setDefaultValueBoolean(true); change.setDefaultValueDate("2007-01-02"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("addDefaultValue", node.getTagName()); assertEquals("SCHEMA_NAME", node.getAttribute("schemaName")); assertEquals("TABLE_NAME", node.getAttribute("tableName")); assertEquals("COLUMN_NAME", node.getAttribute("columnName")); assertEquals("DEF STRING", node.getAttribute("defaultValue")); assertEquals("42", node.getAttribute("defaultValueNumeric")); assertEquals("true", node.getAttribute("defaultValueBoolean")); assertEquals("2007-01-02", node.getAttribute("defaultValueDate")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_AddForeignKeyConstraintChange() throws Exception { AddForeignKeyConstraintChange change = new AddForeignKeyConstraintChange(); change.setConstraintName("FK_NAME"); change.setBaseTableSchemaName("BASE_SCHEMA_NAME"); change.setBaseTableName("BASE_TABLE_NAME"); change.setBaseColumnNames("BASE_COL_NAME"); change.setReferencedTableSchemaName("REF_SCHEMA_NAME"); change.setReferencedTableName("REF_TABLE_NAME"); change.setReferencedColumnNames("REF_COL_NAME"); change.setDeferrable(true); change.setOnDelete("CASCADE"); change.setOnUpdate("CASCADE"); change.setInitiallyDeferred(true); change.setReferencesUniqueColumn(false); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("addForeignKeyConstraint", node.getTagName()); assertEquals("FK_NAME", node.getAttribute("constraintName")); assertEquals("BASE_SCHEMA_NAME", node.getAttribute("baseTableSchemaName")); assertEquals("BASE_TABLE_NAME", node.getAttribute("baseTableName")); assertEquals("BASE_COL_NAME", node.getAttribute("baseColumnNames")); assertEquals("REF_SCHEMA_NAME", node.getAttribute("referencedTableSchemaName")); assertEquals("REF_TABLE_NAME", node.getAttribute("referencedTableName")); assertEquals("REF_COL_NAME", node.getAttribute("referencedColumnNames")); assertEquals("true", node.getAttribute("deferrable")); assertEquals("true", node.getAttribute("initiallyDeferred")); assertEquals("false", node.getAttribute("referencesUniqueColumn")); assertEquals("CASCADE", node.getAttribute("onDelete")); assertEquals("CASCADE", node.getAttribute("onUpdate")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_AddNotNullConstraintChange() throws Exception { AddNotNullConstraintChange change = new AddNotNullConstraintChange(); change.setTableName("TABLE_NAME"); change.setColumnName("COL_HERE"); change.setDefaultNullValue("DEFAULT_VALUE"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("addNotNullConstraint", node.getTagName()); assertEquals("TABLE_NAME", node.getAttribute("tableName")); assertEquals("COL_HERE", node.getAttribute("columnName")); assertEquals("DEFAULT_VALUE", node.getAttribute("defaultNullValue")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_AddPrimaryKeyChange() throws Exception { AddPrimaryKeyChange change = new AddPrimaryKeyChange(); change.setSchemaName("SCHEMA_NAME"); change.setTableName("TABLE_NAME"); change.setColumnNames("COL_HERE"); change.setConstraintName("PK_NAME"); change.setTablespace("TABLESPACE_NAME"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("addPrimaryKey", node.getTagName()); assertEquals("SCHEMA_NAME", node.getAttribute("schemaName")); assertEquals("TABLE_NAME", node.getAttribute("tableName")); assertEquals("COL_HERE", node.getAttribute("columnNames")); assertEquals("PK_NAME", node.getAttribute("constraintName")); assertEquals("TABLESPACE_NAME", node.getAttribute("tablespace")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_AddUniqueConstraintChange() throws Exception { AddUniqueConstraintChange change = new AddUniqueConstraintChange(); change.setSchemaName("SCHEMA_NAME"); change.setTableName("TABLE_NAME"); change.setColumnNames("COL_HERE"); change.setConstraintName("PK_NAME"); change.setTablespace("TABLESPACE_NAME"); change.setDeferrable(true); change.setInitiallyDeferred(true); change.setDisabled(true); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("addUniqueConstraint", node.getTagName()); assertEquals("SCHEMA_NAME", node.getAttribute("schemaName")); assertEquals("TABLE_NAME", node.getAttribute("tableName")); assertEquals("COL_HERE", node.getAttribute("columnNames")); assertEquals("PK_NAME", node.getAttribute("constraintName")); assertEquals("TABLESPACE_NAME", node.getAttribute("tablespace")); assertEquals("TABLESPACE_NAME", node.getAttribute("tablespace")); assertEquals("true", node.getAttribute("deferrable")); assertEquals("true", node.getAttribute("initiallyDeferred")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_AlterSequenceChange_nullValues() throws Exception { AlterSequenceChange refactoring = new AlterSequenceChange(); refactoring.setSequenceName("SEQ_NAME"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(refactoring); assertEquals("alterSequence", node.getNodeName()); assertEquals("SEQ_NAME", node.getAttribute("sequenceName")); assertFalse(node.hasAttribute("incrementBy")); assertFalse(node.hasAttribute("maxValue")); assertFalse(node.hasAttribute("minValue")); assertFalse(node.hasAttribute("ordered")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_AlterSequenceChange() throws Exception { AlterSequenceChange refactoring = new AlterSequenceChange(); refactoring.setSchemaName("SCHEMA_NAME"); refactoring.setSequenceName("SEQ_NAME"); refactoring.setIncrementBy(new BigInteger("1")); refactoring.setMaxValue(new BigInteger("2")); refactoring.setMinValue(new BigInteger("3")); refactoring.setOrdered(true); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(refactoring); assertEquals("alterSequence", node.getNodeName()); assertEquals("SCHEMA_NAME", node.getAttribute("schemaName")); assertEquals("SEQ_NAME", node.getAttribute("sequenceName")); assertEquals("1", node.getAttribute("incrementBy")); assertEquals("2", node.getAttribute("maxValue")); assertEquals("3", node.getAttribute("minValue")); assertEquals("true", node.getAttribute("ordered")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_ColumnConfig() throws Exception { ColumnConfig column = new ColumnConfig(); column.setName("id"); column.setType("varchar(255)"); column.setDefaultValue("test Value"); column.setValue("some value here"); ConstraintsConfig constraints = new ConstraintsConfig(); constraints.setDeferrable(Boolean.TRUE); constraints.setDeleteCascade(true); constraints.setForeignKeyName("FK_NAME"); constraints.setInitiallyDeferred(true); constraints.setNullable(false); constraints.setPrimaryKey(true); constraints.setReferences("state(id)"); constraints.setUnique(true); column.setConstraints(constraints); Element element = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(column); assertEquals("column", element.getTagName()); assertEquals("id", element.getAttribute("name")); assertEquals("varchar(255)", element.getAttribute("type")); assertEquals("test Value", element.getAttribute("defaultValue")); assertEquals("some value here", element.getAttribute("value")); Element constraintsElement = (Element) element.getChildNodes().item(0); assertEquals(8, constraintsElement.getAttributes().getLength()); assertEquals("true", constraintsElement.getAttribute("deferrable")); assertEquals("true", constraintsElement.getAttribute("deleteCascade")); assertEquals("FK_NAME", constraintsElement.getAttribute("foreignKeyName")); assertEquals("true", constraintsElement.getAttribute("initiallyDeferred")); assertEquals("false", constraintsElement.getAttribute("nullable")); assertEquals("true", constraintsElement.getAttribute("primaryKey")); assertEquals("state(id)", constraintsElement.getAttribute("references")); assertEquals("true", constraintsElement.getAttribute("unique")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_CreateIndexChange() throws Exception { CreateIndexChange refactoring = new CreateIndexChange(); refactoring.setIndexName("IDX_TEST"); refactoring.setTableName("TAB_NAME"); ColumnConfig column1 = new ColumnConfig(); column1.setName("COL1"); refactoring.addColumn(column1); ColumnConfig column2 = new ColumnConfig(); column2.setName("COL2"); refactoring.addColumn(column2); Element element = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(refactoring); assertEquals("createIndex", element.getTagName()); assertEquals("IDX_TEST", element.getAttribute("indexName")); assertEquals("TAB_NAME", element.getAttribute("tableName")); assertEquals(2, element.getChildNodes().getLength()); assertEquals("column", ((Element) element.getChildNodes().item(0)).getTagName()); assertEquals("COL1", ((Element) element.getChildNodes().item(0)).getAttribute("name")); assertEquals("column", ((Element) element.getChildNodes().item(1)).getTagName()); assertEquals("COL2", ((Element) element.getChildNodes().item(1)).getAttribute("name")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void multiLineAfterSQL() { String sql = "some sql"; String comment = "" ; String total = sql + comment; String result = StringUtils.stripComments(total); assertEquals(sql.trim(),result); }
public static String stripComments(String multiLineSQL) { String strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*\n").matcher(multiLineSQL).replaceAll("$1\n"); strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*$").matcher(strippedSingleLines).replaceAll("$1\n"); return Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL).matcher(strippedSingleLines).replaceAll("").trim(); }
StringUtils { public static String stripComments(String multiLineSQL) { String strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*\n").matcher(multiLineSQL).replaceAll("$1\n"); strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*$").matcher(strippedSingleLines).replaceAll("$1\n"); return Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL).matcher(strippedSingleLines).replaceAll("").trim(); } }
StringUtils { public static String stripComments(String multiLineSQL) { String strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*\n").matcher(multiLineSQL).replaceAll("$1\n"); strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*$").matcher(strippedSingleLines).replaceAll("$1\n"); return Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL).matcher(strippedSingleLines).replaceAll("").trim(); } }
StringUtils { public static String stripComments(String multiLineSQL) { String strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*\n").matcher(multiLineSQL).replaceAll("$1\n"); strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*$").matcher(strippedSingleLines).replaceAll("$1\n"); return Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL).matcher(strippedSingleLines).replaceAll("").trim(); } static String trimToEmpty(String string); static String trimToNull(String string); static String[] processMutliLineSQL(String multiLineSQL,boolean stripComments, boolean splitStatements, String endDelimiter); static String[] splitSQL(String multiLineSQL, String endDelimiter); static String stripComments(String multiLineSQL); static String join(String[] array, String delimiter); static String join(Collection<String> collection, String delimiter); static List<String> splitAndTrim(String s, String regex); static String repeat(String string, int times); static String join(Integer[] array, String delimiter); static String join(int[] array, String delimiter); }
StringUtils { public static String stripComments(String multiLineSQL) { String strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*\n").matcher(multiLineSQL).replaceAll("$1\n"); strippedSingleLines = Pattern.compile("(.*?)\\s*\\-\\-.*$").matcher(strippedSingleLines).replaceAll("$1\n"); return Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL).matcher(strippedSingleLines).replaceAll("").trim(); } static String trimToEmpty(String string); static String trimToNull(String string); static String[] processMutliLineSQL(String multiLineSQL,boolean stripComments, boolean splitStatements, String endDelimiter); static String[] splitSQL(String multiLineSQL, String endDelimiter); static String stripComments(String multiLineSQL); static String join(String[] array, String delimiter); static String join(Collection<String> collection, String delimiter); static List<String> splitAndTrim(String s, String regex); static String repeat(String string, int times); static String join(Integer[] array, String delimiter); static String join(int[] array, String delimiter); }
@Test public void createNode_CreateProcedureChange() throws Exception { CreateProcedureChange refactoring = new CreateProcedureChange(); refactoring.setProcedureBody("CREATE PROC PROCBODY HERE"); refactoring.setComments("Comments go here"); Element element = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(refactoring); assertEquals("createProcedure", element.getTagName()); assertEquals("CREATE PROC PROCBODY HERE", element.getTextContent()); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_CreateSequenceChange() throws Exception { CreateSequenceChange change = new CreateSequenceChange(); change.setSequenceName("SEQ_NAME"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("createSequence", node.getNodeName()); assertEquals("SEQ_NAME", node.getAttribute("sequenceName")); assertFalse(node.hasAttribute("incrementBy")); assertFalse(node.hasAttribute("maxValue")); assertFalse(node.hasAttribute("minValue")); assertFalse(node.hasAttribute("ordered")); assertFalse(node.hasAttribute("startValue")); assertFalse(node.hasAttribute("cycle")); change.setIncrementBy(new BigInteger("1")); change.setMaxValue(new BigInteger("2")); change.setMinValue(new BigInteger("3")); change.setOrdered(true); change.setStartValue(new BigInteger("4")); change.setCycle(true); node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("createSequence", node.getNodeName()); assertEquals("SEQ_NAME", node.getAttribute("sequenceName")); assertEquals("1", node.getAttribute("incrementBy")); assertEquals("2", node.getAttribute("maxValue")); assertEquals("3", node.getAttribute("minValue")); assertEquals("true", node.getAttribute("ordered")); assertEquals("4", node.getAttribute("startValue")); assertEquals("true", node.getAttribute("cycle")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_CreateTableChange() throws Exception { CreateTableChange change = new CreateTableChange(); change.setTableName("TABLE_NAME"); ColumnConfig column1 = new ColumnConfig(); column1.setName("id"); column1.setType("int"); ConstraintsConfig column1constraints = new ConstraintsConfig(); column1constraints.setPrimaryKey(true); column1constraints.setNullable(false); column1.setConstraints(column1constraints); change.addColumn(column1); ColumnConfig column2 = new ColumnConfig(); column2.setName("name"); column2.setType("varchar(255)"); change.addColumn(column2); ColumnConfig column3 = new ColumnConfig(); column3.setName("state_id"); ConstraintsConfig column3constraints = new ConstraintsConfig(); column3constraints.setNullable(false); column3constraints.setInitiallyDeferred(true); column3constraints.setDeferrable(true); column3constraints.setForeignKeyName("fk_tab_ref"); column3constraints.setReferences("state(id)"); column3.setConstraints(column3constraints); change.addColumn(column3); ColumnConfig column4 = new ColumnConfig(); column4.setName("phone"); column4.setType("varchar(255)"); column4.setDefaultValue("NOPHONE"); change.addColumn(column4); ColumnConfig column5 = new ColumnConfig(); column5.setName("phone2"); column5.setType("varchar(255)"); ConstraintsConfig column5constraints = new ConstraintsConfig(); column5constraints.setUnique(true); column5.setConstraints(column5constraints); change.addColumn(column5); Element element = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("createTable", element.getTagName()); assertEquals(5, element.getChildNodes().getLength()); Element columnElement = ((Element) element.getChildNodes().item(0)); assertEquals("column", columnElement.getTagName()); assertEquals("id", columnElement.getAttribute("name")); assertEquals("int", columnElement.getAttribute("type")); Element constraintsElement = (Element) columnElement.getChildNodes().item(0); assertEquals("constraints", constraintsElement.getTagName()); assertEquals(2, constraintsElement.getAttributes().getLength()); assertEquals("true", constraintsElement.getAttribute("primaryKey")); assertEquals("false", constraintsElement.getAttribute("nullable")); columnElement = ((Element) element.getChildNodes().item(1)); assertEquals("column", columnElement.getTagName()); assertEquals("name", columnElement.getAttribute("name")); assertEquals("varchar(255)", columnElement.getAttribute("type")); columnElement = ((Element) element.getChildNodes().item(2)); assertEquals("column", columnElement.getTagName()); assertEquals("state_id", columnElement.getAttribute("name")); constraintsElement = (Element) columnElement.getChildNodes().item(0); assertEquals("constraints", constraintsElement.getTagName()); assertEquals(5, constraintsElement.getAttributes().getLength()); assertEquals("false", constraintsElement.getAttribute("nullable")); assertEquals("true", constraintsElement.getAttribute("deferrable")); assertEquals("true", constraintsElement.getAttribute("initiallyDeferred")); assertEquals("fk_tab_ref", constraintsElement.getAttribute("foreignKeyName")); assertEquals("state(id)", constraintsElement.getAttribute("references")); columnElement = ((Element) element.getChildNodes().item(3)); assertEquals("column", columnElement.getTagName()); assertEquals("phone", columnElement.getAttribute("name")); assertEquals("varchar(255)", columnElement.getAttribute("type")); columnElement = ((Element) element.getChildNodes().item(4)); assertEquals("column", columnElement.getTagName()); assertEquals("phone2", columnElement.getAttribute("name")); assertEquals("varchar(255)", columnElement.getAttribute("type")); constraintsElement = (Element) columnElement.getChildNodes().item(0); assertEquals("constraints", constraintsElement.getTagName()); assertEquals(1, constraintsElement.getAttributes().getLength()); assertEquals("true", constraintsElement.getAttribute("unique")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNodeDropColumnChange() throws Exception { DropColumnChange change = new DropColumnChange(); change.setTableName("TABLE_NAME"); change.setColumnName("COL_NAME"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("dropColumn", node.getTagName()); assertFalse(node.hasAttribute("schemaName")); assertEquals("TABLE_NAME", node.getAttribute("tableName")); assertEquals("COL_NAME", node.getAttribute("columnName")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_DropColumnChange_withSchema() throws Exception { DropColumnChange change = new DropColumnChange(); change.setSchemaName("SCHEMA_NAME"); change.setTableName("TABLE_NAME"); change.setColumnName("COL_NAME"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("dropColumn", node.getTagName()); assertEquals("SCHEMA_NAME", node.getAttribute("schemaName")); assertEquals("TABLE_NAME", node.getAttribute("tableName")); assertEquals("COL_NAME", node.getAttribute("columnName")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_DropDefaultValueChange() throws Exception { DropDefaultValueChange change = new DropDefaultValueChange(); change.setTableName("TABLE_NAME"); change.setColumnName("COL_NAME"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("dropDefaultValue", node.getTagName()); assertFalse(node.hasAttribute("schemaName")); assertEquals("TABLE_NAME", node.getAttribute("tableName")); assertEquals("COL_NAME", node.getAttribute("columnName")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_DropDefaultValueChange_withSchema() throws Exception { DropDefaultValueChange change = new DropDefaultValueChange(); change.setSchemaName("SCHEMA_NAME"); change.setTableName("TABLE_NAME"); change.setColumnName("COL_NAME"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("dropDefaultValue", node.getTagName()); assertEquals("SCHEMA_NAME", node.getAttribute("schemaName")); assertEquals("TABLE_NAME", node.getAttribute("tableName")); assertEquals("COL_NAME", node.getAttribute("columnName")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
@Test public void createNode_DropForeignKeyConstraintChange() throws Exception { DropForeignKeyConstraintChange change = new DropForeignKeyConstraintChange(); change.setBaseTableSchemaName("SCHEMA_NAME"); change.setBaseTableName("TABLE_NAME"); change.setConstraintName("FK_NAME"); Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("dropForeignKeyConstraint", node.getTagName()); assertEquals("SCHEMA_NAME", node.getAttribute("baseTableSchemaName")); assertEquals("TABLE_NAME", node.getAttribute("baseTableName")); assertEquals("FK_NAME", node.getAttribute("constraintName")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }