public TypedValueSerializer<?> getSerializer(TypedValue value) { if (value instanceof ObjectValue) { ObjectValue objectValue = (ObjectValue) value; if (objectValue.getSerializationDataFormat() != null && !objectValue.isDeserialized()) { return new FallbackSpinObjectValueSerializer(objectValue.getSerializationDataFormat()); } } return null; } }
public Map<String, Object> getValueInfo(TypedValue typedValue) { if(!(typedValue instanceof ObjectValue)) { throw new IllegalArgumentException("Value not of type Object."); } ObjectValue objectValue = (ObjectValue) typedValue; Map<String, Object> valueInfo = new HashMap<String, Object>(); String serializationDataFormat = objectValue.getSerializationDataFormat(); if(serializationDataFormat != null) { valueInfo.put(VALUE_INFO_SERIALIZATION_DATA_FORMAT, serializationDataFormat); } String objectTypeName = objectValue.getObjectTypeName(); if(objectTypeName != null) { valueInfo.put(VALUE_INFO_OBJECT_TYPE_NAME, objectTypeName); } if (objectValue.isTransient()) { valueInfo.put(VALUE_INFO_TRANSIENT, objectValue.isTransient()); } return valueInfo; }
public static void assertObjectValueSerializedJava(ObjectValue typedValue, Object value) { assertEquals(Variables.SerializationDataFormats.JAVA.getName(), typedValue.getSerializationDataFormat()); try { // validate this is the base 64 encoded string representation of the serialized value of the java object String valueSerialized = typedValue.getValueSerialized(); byte[] decodedObject = Base64.decodeBase64(valueSerialized.getBytes(Charset.forName("UTF-8"))); ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(decodedObject)); assertEquals(value, objectInputStream.readObject()); } catch(IOException e) { throw new RuntimeException(e); } catch(ClassNotFoundException e) { throw new RuntimeException(e); } }
if (objectValue.getSerializationDataFormat() != null) { return false; if (!serializationFormat.equals(objectValue.getSerializationDataFormat())) { return false;
public static MockObjectValue fromObjectValue(ObjectValue objectValue) { MockObjectValue result = new MockObjectValue(objectValue.getValue()); result.isDeserialized = objectValue.isDeserialized(); result.objectTypeName = objectValue.getObjectTypeName(); result.serializationDataFormat = objectValue.getSerializationDataFormat(); result.serializedValue = objectValue.getValueSerialized(); result.type = objectValue.getType(); return result; }
assertEquals(serializedObject, variableTyped.getValueSerialized()); assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName()); assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
assertEquals(serializedObject, variableTyped.getValueSerialized()); assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName()); assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
assertEquals(serializedObject, variableTyped.getValueSerialized()); assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName()); assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
public static void assertObjectValueSerializedNull(ObjectValue typedValue) { assertNotNull(typedValue); assertFalse(typedValue.isDeserialized()); assertNotNull(typedValue.getSerializationDataFormat()); assertNull(typedValue.getValueSerialized()); assertNull(typedValue.getObjectTypeName()); }
assertEquals(serializedObject, variableTyped.getValueSerialized()); assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName()); assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
assertEquals(serializedObject, variableTyped.getValueSerialized()); assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName()); assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
assertEquals(serializedObject, variableTyped.getValueSerialized()); assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName()); assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
@SuppressWarnings("unchecked") protected void verifySerializedValue(Map<String, Object> serializedValue) { ObjectValue exampleValue = MockProvider.EXAMPLE_HISTORIC_DECISION_SERIALIZED_VALUE; assertThat(serializedValue, hasEntry("type", (Object) VariableValueDto.toRestApiTypeName(exampleValue.getType().getName()))); assertThat(serializedValue, hasEntry("value", exampleValue.getValue())); Map<String, String> valueInfo = (Map<String, String>) serializedValue.get("valueInfo"); assertThat(valueInfo, hasEntry("serializationDataFormat", exampleValue.getSerializationDataFormat())); assertThat(valueInfo, hasEntry("objectTypeName", exampleValue.getObjectTypeName())); }
public TypedValueSerializer<?> getSerializer(TypedValue value) { if (value instanceof ObjectValue) { ObjectValue objectValue = (ObjectValue) value; if (objectValue.getSerializationDataFormat() != null && !objectValue.isDeserialized()) { return new FallbackSpinObjectValueSerializer(objectValue.getSerializationDataFormat()); } } return null; } }
public static void assertObjectValueDeserializedNull(ObjectValue typedValue) { assertNotNull(typedValue); assertTrue(typedValue.isDeserialized()); assertNotNull(typedValue.getSerializationDataFormat()); assertNull(typedValue.getValue()); assertNull(typedValue.getValueSerialized()); assertNull(typedValue.getObjectType()); assertNull(typedValue.getObjectTypeName()); }
@Test public void testFallbackSerializerDoesNotOverrideRegularSerializer() { // given // that the process engine is configured with a serializer for a certain format // and a fallback serializer factory for the same format ProcessEngineConfigurationImpl engineConfiguration = new StandaloneInMemProcessEngineConfiguration() .setJdbcUrl("jdbc:h2:mem:camunda-forceclose") .setProcessEngineName("engine-forceclose"); engineConfiguration.setCustomPreVariableSerializers(Arrays.<TypedValueSerializer>asList(new ExampleConstantSerializer())); engineConfiguration.setFallbackSerializerFactory(new ExampleSerializerFactory()); processEngine = engineConfiguration.buildProcessEngine(); deployOneTaskProcess(processEngine); // when setting a variable that no regular serializer can handle ObjectValue objectValue = Variables.objectValue("foo").serializationDataFormat(ExampleSerializer.FORMAT).create(); ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValueTyped("var", objectValue)); ObjectValue fetchedValue = processEngine.getRuntimeService().getVariableTyped(pi.getId(), "var", true); // then the fallback serializer is used Assert.assertNotNull(fetchedValue); Assert.assertEquals(ExampleSerializer.FORMAT, fetchedValue.getSerializationDataFormat()); Assert.assertEquals(ExampleConstantSerializer.DESERIALIZED_VALUE, fetchedValue.getValue()); }
@Test @Deployment(resources = ONE_TASK_PROCESS) public void testSetJavaObjectNullSerializedObjectTypeName() throws Exception { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); String typeName = "some.type.Name"; // set null value as "serialized" object runtimeService.setVariable(instance.getId(), "nullObject", serializedObjectValue() .serializationDataFormat(JAVA_DATA_FORMAT) .objectTypeName(typeName) // This time an objectTypeName is provided .create()); // get null value via untyped api assertNull(runtimeService.getVariable(instance.getId(), "nullObject")); // get null via typed api ObjectValue deserializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject"); assertNotNull(deserializedTypedValue); assertTrue(deserializedTypedValue.isDeserialized()); assertEquals(JAVA_DATA_FORMAT, deserializedTypedValue.getSerializationDataFormat()); assertNull(deserializedTypedValue.getValue()); assertNull(deserializedTypedValue.getValueSerialized()); assertNull(deserializedTypedValue.getObjectType()); assertEquals(typeName, deserializedTypedValue.getObjectTypeName()); ObjectValue serializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject", false); assertNotNull(serializedTypedValue); assertFalse(serializedTypedValue.isDeserialized()); assertEquals(JAVA_DATA_FORMAT, serializedTypedValue.getSerializationDataFormat()); assertNull(serializedTypedValue.getValueSerialized()); assertEquals(typeName, serializedTypedValue.getObjectTypeName()); }
@Test public void testFallbackSerializer() { // given // that the process engine is configured with a fallback serializer factory ProcessEngineConfigurationImpl engineConfiguration = new StandaloneInMemProcessEngineConfiguration() .setJdbcUrl("jdbc:h2:mem:camunda-forceclose") .setProcessEngineName("engine-forceclose"); engineConfiguration.setFallbackSerializerFactory(new ExampleSerializerFactory()); processEngine = engineConfiguration.buildProcessEngine(); deployOneTaskProcess(processEngine); // when setting a variable that no regular serializer can handle ObjectValue objectValue = Variables.objectValue("foo").serializationDataFormat(ExampleSerializer.FORMAT).create(); ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValueTyped("var", objectValue)); ObjectValue fetchedValue = processEngine.getRuntimeService().getVariableTyped(pi.getId(), "var", true); // then the fallback serializer is used Assert.assertNotNull(fetchedValue); Assert.assertEquals(ExampleSerializer.FORMAT, fetchedValue.getSerializationDataFormat()); Assert.assertEquals("foo", fetchedValue.getValue()); }
public void execute(DelegateExecution execution) throws Exception { // validate integer variable Integer expectedIntValue = 1234; assertEquals(expectedIntValue, execution.getVariable("anIntegerVariable")); assertEquals(expectedIntValue, execution.getVariableTyped("anIntegerVariable").getValue()); assertEquals(ValueType.INTEGER, execution.getVariableTyped("anIntegerVariable").getType()); assertNull(execution.getVariableLocal("anIntegerVariable")); assertNull(execution.getVariableLocalTyped("anIntegerVariable")); // set an additional local variable execution.setVariableLocal("aStringVariable", "aStringValue"); String expectedStringValue = "aStringValue"; assertEquals(expectedStringValue, execution.getVariable("aStringVariable")); assertEquals(expectedStringValue, execution.getVariableTyped("aStringVariable").getValue()); assertEquals(ValueType.STRING, execution.getVariableTyped("aStringVariable").getType()); assertEquals(expectedStringValue, execution.getVariableLocal("aStringVariable")); assertEquals(expectedStringValue, execution.getVariableLocalTyped("aStringVariable").getValue()); assertEquals(ValueType.STRING, execution.getVariableLocalTyped("aStringVariable").getType()); SimpleSerializableBean objectValue = (SimpleSerializableBean) execution.getVariable("anObjectValue"); assertNotNull(objectValue); assertEquals(10, objectValue.getIntProperty()); ObjectValue variableTyped = execution.getVariableTyped("anObjectValue"); assertEquals(10, variableTyped.getValue(SimpleSerializableBean.class).getIntProperty()); assertEquals(Variables.SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat()); objectValue = (SimpleSerializableBean) execution.getVariable("anUntypedObjectValue"); assertNotNull(objectValue); assertEquals(30, objectValue.getIntProperty()); variableTyped = execution.getVariableTyped("anUntypedObjectValue"); assertEquals(30, variableTyped.getValue(SimpleSerializableBean.class).getIntProperty()); assertEquals(Context.getProcessEngineConfiguration().getDefaultSerializationFormat(), variableTyped.getSerializationDataFormat()); }
public static void assertObjectValueDeserializedNull(ObjectValue typedValue) { assertNotNull(typedValue); assertTrue(typedValue.isDeserialized()); assertNotNull(typedValue.getSerializationDataFormat()); assertNull(typedValue.getValue()); assertNull(typedValue.getValueSerialized()); assertNull(typedValue.getObjectType()); assertNull(typedValue.getObjectTypeName()); }