public void writeValue(T value, ValueFields valueFields) { String serializedStringValue = value.getValueSerialized(); byte[] serializedByteValue = null; if(value.isDeserialized()) { Object objectToSerialize = value.getValue(); if(objectToSerialize != null) { // serialize to byte array try { serializedByteValue = serializeToByteArray(objectToSerialize); serializedStringValue = getSerializedStringValue(serializedByteValue); } catch(Exception e) { throw new ProcessEngineException("Cannot serialize object in variable '"+valueFields.getName()+"': "+e.getMessage(), e); } } } else { if (serializedStringValue != null) { serializedByteValue = getSerializedBytesValue(serializedStringValue); } } // write value and type to fields. writeToValueFields(value, valueFields, serializedByteValue); // update the ObjectValue to keep it consistent with value fields. updateTypedValue(value, serializedStringValue); }
protected boolean canWriteValue(TypedValue typedValue) { if (!(typedValue instanceof SerializableValue) && !(typedValue instanceof UntypedValueImpl)) { return false; } if (typedValue instanceof SerializableValue) { SerializableValue serializableValue = (SerializableValue) typedValue; String requestedDataFormat = serializableValue.getSerializationDataFormat(); if (!serializableValue.isDeserialized()) { // serialized object => dataformat must match return serializationDataFormat.equals(requestedDataFormat); } else { final boolean canSerialize = typedValue.getValue() == null || canSerializeValue(typedValue.getValue()); return canSerialize && (requestedDataFormat == null || serializationDataFormat.equals(requestedDataFormat)); } } else { return typedValue.getValue() == null || canSerializeValue(typedValue.getValue()); } }
String actualJsonString = serializedValue.getValueSerialized();
public TypedValue getTypedValue(boolean deserializeValue) { if (cachedValue != null && cachedValue instanceof SerializableValue && Context.getCommandContext() != null) { SerializableValue serializableValue = (SerializableValue) cachedValue; if(deserializeValue && !serializableValue.isDeserialized()) { // clear cached value in case it is not deserialized and user requests deserialized value cachedValue = null; } } if (cachedValue == null && errorMessage == null) { try { cachedValue = getSerializer().readValue(valueFields, deserializeValue); if (notifyOnImplicitUpdates && isMutableValue(cachedValue)) { Context.getCommandContext().registerCommandContextListener(this); } } catch (RuntimeException e) { // intercept the error message this.errorMessage = e.getMessage(); throw e; } } return cachedValue; }
public TypedValue getTypedValue(boolean deserializeValue) { if (cachedValue != null && cachedValue instanceof SerializableValue && Context.getCommandContext() != null) { SerializableValue serializableValue = (SerializableValue) cachedValue; if(deserializeValue && !serializableValue.isDeserialized()) { // clear cached value in case it is not deserialized and user requests deserialized value cachedValue = null; } } if (cachedValue == null && errorMessage == null) { try { cachedValue = getSerializer().readValue(valueFields, deserializeValue); if (notifyOnImplicitUpdates && isMutableValue(cachedValue)) { Context.getCommandContext().registerCommandContextListener(this); } } catch (RuntimeException e) { // intercept the error message this.errorMessage = e.getMessage(); throw e; } } return cachedValue; }
public void writeValue(T value, ValueFields valueFields) { String serializedStringValue = value.getValueSerialized(); byte[] serializedByteValue = null; if(value.isDeserialized()) { Object objectToSerialize = value.getValue(); if(objectToSerialize != null) { // serialize to byte array try { serializedByteValue = serializeToByteArray(objectToSerialize); serializedStringValue = getSerializedStringValue(serializedByteValue); } catch(Exception e) { throw new ProcessEngineException("Cannot serialize object in variable '"+valueFields.getName()+"': "+e.getMessage(), e); } } } else { if (serializedStringValue != null) { serializedByteValue = getSerializedBytesValue(serializedStringValue); } } // write value and type to fields. writeToValueFields(value, valueFields, serializedByteValue); // update the ObjectValue to keep it consistent with value fields. updateTypedValue(value, serializedStringValue); }
protected boolean canWriteValue(TypedValue typedValue) { if (!(typedValue instanceof SerializableValue) && !(typedValue instanceof UntypedValueImpl)) { return false; } if (typedValue instanceof SerializableValue) { SerializableValue serializableValue = (SerializableValue) typedValue; String requestedDataFormat = serializableValue.getSerializationDataFormat(); if (!serializableValue.isDeserialized()) { // serialized object => dataformat must match return serializationDataFormat.equals(requestedDataFormat); } else { final boolean canSerialize = typedValue.getValue() == null || canSerializeValue(typedValue.getValue()); return canSerialize && (requestedDataFormat == null || serializationDataFormat.equals(requestedDataFormat)); } } else { return typedValue.getValue() == null || canSerializeValue(typedValue.getValue()); } }
public TypedValue getTypedValue(boolean deserializeValue) { if (cachedValue != null && cachedValue instanceof SerializableValue && Context.getCommandContext() != null) { SerializableValue serializableValue = (SerializableValue) cachedValue; if(deserializeValue && !serializableValue.isDeserialized()) { // clear cached value in case it is not deserialized and user requests deserialized value cachedValue = null; } } if (cachedValue == null && errorMessage == null) { try { cachedValue = getSerializer().readValue(valueFields, deserializeValue); if (notifyOnImplicitUpdates && isMutableValue(cachedValue)) { Context.getCommandContext().registerCommandContextListener(this); } } catch (RuntimeException e) { // intercept the error message this.errorMessage = e.getMessage(); throw e; } } return cachedValue; }
public static void fromTypedValue(VariableValueDto dto, TypedValue typedValue, boolean preferSerializedValue) { ValueType type = typedValue.getType(); if (type != null) { String typeName = type.getName(); dto.setType(toRestApiTypeName(typeName)); dto.setValueInfo(type.getValueInfo(typedValue)); } if(typedValue instanceof SerializableValue) { SerializableValue serializableValue = (SerializableValue) typedValue; if(serializableValue.isDeserialized() && !preferSerializedValue) { dto.setValue(serializableValue.getValue()); } else { dto.setValue(serializableValue.getValueSerialized()); } } else if(typedValue instanceof FileValue){ //do not set the value for FileValues since we don't want to send megabytes over the network without explicit request } else { dto.setValue(typedValue.getValue()); } }
/** * Checks, if Java serialization will be used and if it is allowed to be used. * @param variableName * @param value */ protected void checkJavaSerialization(String variableName, TypedValue value) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); if (value instanceof SerializableValue && !processEngineConfiguration.isJavaSerializationFormatEnabled()) { SerializableValue serializableValue = (SerializableValue) value; // if Java serialization is prohibited if (!serializableValue.isDeserialized()) { String javaSerializationDataFormat = Variables.SerializationDataFormats.JAVA.getName(); String requestedDataFormat = serializableValue.getSerializationDataFormat(); if (requestedDataFormat == null) { // check if Java serializer will be used final TypedValueSerializer serializerForValue = TypedValueField.getSerializers() .findSerializerForValue(serializableValue, processEngineConfiguration.getFallbackSerializerFactory()); if (serializerForValue != null) { requestedDataFormat = serializerForValue.getSerializationDataformat(); } } if (javaSerializationDataFormat.equals(requestedDataFormat)) { throw ProcessEngineLogger.CORE_LOGGER.javaSerializationProhibitedException(variableName); } } } }
public static void fromTypedValue(VariableValueDto dto, TypedValue typedValue, boolean preferSerializedValue) { ValueType type = typedValue.getType(); if (type != null) { String typeName = type.getName(); dto.setType(toRestApiTypeName(typeName)); dto.setValueInfo(type.getValueInfo(typedValue)); } if(typedValue instanceof SerializableValue) { SerializableValue serializableValue = (SerializableValue) typedValue; if(serializableValue.isDeserialized() && !preferSerializedValue) { dto.setValue(serializableValue.getValue()); } else { dto.setValue(serializableValue.getValueSerialized()); } } else if(typedValue instanceof FileValue){ //do not set the value for FileValues since we don't want to send megabytes over the network without explicit request } else { dto.setValue(typedValue.getValue()); } }
/** * Checks, if Java serialization will be used and if it is allowed to be used. * @param variableName * @param value */ protected void checkJavaSerialization(String variableName, TypedValue value) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); if (value instanceof SerializableValue && !processEngineConfiguration.isJavaSerializationFormatEnabled()) { SerializableValue serializableValue = (SerializableValue) value; // if Java serialization is prohibited if (!serializableValue.isDeserialized()) { String javaSerializationDataFormat = Variables.SerializationDataFormats.JAVA.getName(); String requestedDataFormat = serializableValue.getSerializationDataFormat(); if (requestedDataFormat == null) { // check if Java serializer will be used final TypedValueSerializer serializerForValue = TypedValueField.getSerializers() .findSerializerForValue(serializableValue, processEngineConfiguration.getFallbackSerializerFactory()); if (serializerForValue != null) { requestedDataFormat = serializerForValue.getSerializationDataformat(); } } if (javaSerializationDataFormat.equals(requestedDataFormat)) { throw ProcessEngineLogger.CORE_LOGGER.javaSerializationProhibitedException(variableName); } } } }
public void writeValue(T value, ValueFields valueFields) { String serializedStringValue = value.getValueSerialized(); byte[] serializedByteValue = null; if(value.isDeserialized()) { Object objectToSerialize = value.getValue(); if(objectToSerialize != null) { // serialize to byte array try { serializedByteValue = serializeToByteArray(objectToSerialize); serializedStringValue = getSerializedStringValue(serializedByteValue); } catch(Exception e) { throw new ProcessEngineException("Cannot serialize object in variable '"+valueFields.getName()+"': "+e.getMessage(), e); } } } else { if (serializedStringValue != null) { serializedByteValue = getSerializedBytesValue(serializedStringValue); } } // write value and type to fields. writeToValueFields(value, valueFields, serializedByteValue); // update the ObjectValue to keep it consistent with value fields. updateTypedValue(value, serializedStringValue); }
protected boolean canWriteValue(TypedValue typedValue) { if (!(typedValue instanceof SerializableValue) && !(typedValue instanceof UntypedValueImpl)) { return false; } if (typedValue instanceof SerializableValue) { SerializableValue serializableValue = (SerializableValue) typedValue; String requestedDataFormat = serializableValue.getSerializationDataFormat(); if (!serializableValue.isDeserialized()) { // serialized object => dataformat must match return serializationDataFormat.equals(requestedDataFormat); } else { final boolean canSerialize = typedValue.getValue() == null || canSerializeValue(typedValue.getValue()); return canSerialize && (requestedDataFormat == null || serializationDataFormat.equals(requestedDataFormat)); } } else { return typedValue.getValue() == null || canSerializeValue(typedValue.getValue()); } }
public static void fromTypedValue(VariableValueDto dto, TypedValue typedValue, boolean preferSerializedValue) { ValueType type = typedValue.getType(); if (type != null) { String typeName = type.getName(); dto.setType(toRestApiTypeName(typeName)); dto.setValueInfo(type.getValueInfo(typedValue)); } if(typedValue instanceof SerializableValue) { SerializableValue serializableValue = (SerializableValue) typedValue; if(serializableValue.isDeserialized() && !preferSerializedValue) { dto.setValue(serializableValue.getValue()); } else { dto.setValue(serializableValue.getValueSerialized()); } } else if(typedValue instanceof FileValue){ //do not set the value for FileValues since we don't want to send megabytes over the network without explicit request } else { dto.setValue(typedValue.getValue()); } }
/** * Checks, if Java serialization will be used and if it is allowed to be used. * @param variableName * @param value */ protected void checkJavaSerialization(String variableName, TypedValue value) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); if (value instanceof SerializableValue && !processEngineConfiguration.isJavaSerializationFormatEnabled()) { SerializableValue serializableValue = (SerializableValue) value; // if Java serialization is prohibited if (!serializableValue.isDeserialized()) { String javaSerializationDataFormat = Variables.SerializationDataFormats.JAVA.getName(); String requestedDataFormat = serializableValue.getSerializationDataFormat(); if (requestedDataFormat == null) { // check if Java serializer will be used final TypedValueSerializer serializerForValue = TypedValueField.getSerializers() .findSerializerForValue(serializableValue, processEngineConfiguration.getFallbackSerializerFactory()); if (serializerForValue != null) { requestedDataFormat = serializerForValue.getSerializationDataformat(); } } if (javaSerializationDataFormat.equals(requestedDataFormat)) { throw ProcessEngineLogger.CORE_LOGGER.javaSerializationProhibitedException(variableName); } } } }