public static String getExceptionStacktrace(ByteArrayEntity byteArray) { String result = null; if(byteArray != null) { result = StringUtil.fromBytes(byteArray.getBytes()); } return result; }
public static String getExceptionStacktrace(ByteArrayEntity byteArray) { String result = null; if(byteArray != null) { result = StringUtil.fromBytes(byteArray.getBytes()); } return result; }
protected String getSerializedStringValue(byte[] serializedByteValue) { if(serializedByteValue != null) { if(!isSerializationTextBased()) { serializedByteValue = Base64.encodeBase64(serializedByteValue); } return StringUtil.fromBytes(serializedByteValue); } else { return null; } }
protected String getSerializedStringValue(byte[] serializedByteValue) { if(serializedByteValue != null) { if(!isSerializationTextBased()) { serializedByteValue = Base64.encodeBase64(serializedByteValue); } return StringUtil.fromBytes(serializedByteValue); } else { return null; } }
/** * converts a byte array into a string using the current process engines default charset as * returned by {@link ProcessEngineConfigurationImpl#getDefaultCharset()} * * @param bytes the byte array * @return a string representing the bytes */ public static String fromBytes(byte[] bytes) { EnsureUtil.ensureActiveCommandContext("StringUtil.fromBytes"); ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); return fromBytes(bytes, processEngineConfiguration.getProcessEngine()); }
/** * converts a byte array into a string using the current process engines default charset as * returned by {@link ProcessEngineConfigurationImpl#getDefaultCharset()} * * @param bytes the byte array * @return a string representing the bytes */ public static String fromBytes(byte[] bytes) { EnsureUtil.ensureActiveCommandContext("StringUtil.fromBytes"); ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); return fromBytes(bytes, processEngineConfiguration.getProcessEngine()); }
public static JsonObject asObject(byte[] byteArray) { String stringValue = null; if (byteArray != null) { stringValue = StringUtil.fromBytes(byteArray); } if (stringValue == null) { return createObject(); } JsonObject jsonObject = null; try { jsonObject = getGsonMapper().fromJson(stringValue, JsonObject.class); } catch (JsonParseException e) { LOG.logJsonException(e); } if (jsonObject != null) { return jsonObject; } else { return createObject(); } }
public static JsonObject asObject(byte[] byteArray) { String stringValue = null; if (byteArray != null) { stringValue = StringUtil.fromBytes(byteArray); } if (stringValue == null) { return createObject(); } JsonObject jsonObject = null; try { jsonObject = getGsonMapper().fromJson(stringValue, JsonObject.class); } catch (JsonParseException e) { LOG.logJsonException(e); } if (jsonObject != null) { return jsonObject; } else { return createObject(); } }
@Test @Deployment public void testJavaObjectNotDeserializedIfNotRequested() throws Exception { // this test makes sure that if a serialized value is set, it is not automatically deserialized if deserialization is not requested // given // a serialized Java Object FailingJavaSerializable javaSerializable = new FailingJavaSerializable("foo"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(javaSerializable); byte[] serializedObjectBytes = baos.toByteArray(); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(serializedObjectBytes), engineRule.getProcessEngine()); thrown.expect(RuntimeException.class); thrown.expectMessage("Exception while deserializing object"); // which cannot be deserialized ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(serializedObjectBytes)); objectInputStream.readObject(); // if // I start a process instance in which a Java Delegate reads the value in its serialized form runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables() .putValue("varName", serializedObjectValue(serializedObject) .serializationDataFormat(JAVA_DATA_FORMAT) .objectTypeName(JavaSerializable.class.getName()) .create())); // then // it does not fail }
@Test @Deployment(resources = ONE_TASK_PROCESS) public void testSetJavaObjectSerializedEmptySerializationDataFormat() throws Exception { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JavaSerializable javaSerializable = new JavaSerializable("foo"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(javaSerializable); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine()); thrown.expect(ProcessEngineException.class); thrown.expectMessage("Cannot set variable with name simpleBean. Java serialization format is prohibited"); runtimeService.setVariable(instance.getId(), "simpleBean", serializedObjectValue(serializedObject) .objectTypeName(JavaSerializable.class.getName()) .create()); }
@Test @Deployment public void testJavaObjectDeserializedInFirstCommand() throws Exception { // this test makes sure that if a serialized value is set, it can be deserialized in the same command in which it is set. // given // a serialized Java Object JavaSerializable javaSerializable = new JavaSerializable("foo"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(javaSerializable); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine()); // if // I start a process instance in which a Java Delegate reads the value in its deserialized form runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables() .putValue("varName", serializedObjectValue(serializedObject) .serializationDataFormat(JAVA_DATA_FORMAT) .objectTypeName(JavaSerializable.class.getName()) .create())); // then // it does not fail }
@Deployment(resources = ONE_TASK_PROCESS) public void testFailSerializationForUnknownSerializedValueType() throws IOException { // given JavaSerializable pojo = new JavaSerializable("foo"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(pojo); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), processEngine); ObjectValue serializedObjectValue = Variables .serializedObjectValue(serializedObject) .serializationDataFormat(SerializationDataFormats.JAVA) .objectTypeName(pojo.getClass().getName()) .create(); VariableMap variables = Variables.createVariables().putValueTyped("var", serializedObjectValue); // when ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables); // then JavaSerializable returnedPojo = (JavaSerializable) runtimeService.getVariable(processInstance.getId(), "var"); assertEquals(pojo, returnedPojo); }
@Test @Deployment(resources = ONE_TASK_PROCESS) public void testSetJavaObjectSerialized() throws Exception { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JavaSerializable javaSerializable = new JavaSerializable("foo"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(javaSerializable); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine()); thrown.expect(ProcessEngineException.class); thrown.expectMessage("Cannot set variable with name simpleBean. Java serialization format is prohibited"); runtimeService.setVariable(instance.getId(), "simpleBean", serializedObjectValue(serializedObject) .serializationDataFormat(JAVA_DATA_FORMAT) .objectTypeName(JavaSerializable.class.getName()) .create()); }
@Test public void testStandaloneTaskTransientVariable() throws IOException { Task task = taskService.newTask(); task.setName("gonzoTask"); taskService.saveTask(task); String taskId = task.getId(); try{ ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(new String("trumpet")); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine()); taskService.setVariable(taskId, "instrument", Variables.serializedObjectValue(serializedObject) .objectTypeName(String.class.getName()) .serializationDataFormat(Variables.SerializationDataFormats.JAVA) .setTransient(true) ); assertEquals("trumpet", taskService.getVariable(taskId, "instrument")); } finally { taskService.deleteTask(taskId, true); } }
private void testVariablesWithoutDeserialization(String processDefinitionKey) throws Exception { //given serializable variable JavaSerializable javaSerializable = new JavaSerializable("foo"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(javaSerializable); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine()); //when execute process with serialized variable and wait state ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService() .createProcessInstanceByKey(processDefinitionKey) .setVariable("serializedVar", serializedObjectValue(serializedObject) .serializationDataFormat(Variables.SerializationDataFormats.JAVA) .objectTypeName(JavaSerializable.class.getName()) .create()) .executeWithVariablesInReturn(false, false); //then returned instance contains serialized variable VariableMap map = procInstance.getVariables(); assertNotNull(map); ObjectValue serializedVar = (ObjectValue) map.getValueTyped("serializedVar"); assertFalse(serializedVar.isDeserialized()); assertObjectValueSerializedJava(serializedVar, javaSerializable); //access on value should fail because variable is not deserialized try { serializedVar.getValue(); Assert.fail("Deserialization should fail!"); } catch (IllegalStateException ise) { assertTrue(ise.getMessage().equals("Object is not deserialized.")); } }
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
@Test @Deployment(resources = ONE_TASK_PROCESS) public void testSetJavaObjectSerialized() throws Exception { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); JavaSerializable javaSerializable = new JavaSerializable("foo"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(javaSerializable); String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine()); runtimeService.setVariable(instance.getId(), "simpleBean", serializedObjectValue(serializedObject) .serializationDataFormat(JAVA_DATA_FORMAT) .objectTypeName(JavaSerializable.class.getName()) .create()); // validate untyped value JavaSerializable value = (JavaSerializable) runtimeService.getVariable(instance.getId(), "simpleBean"); assertEquals(javaSerializable, value); // validate typed value ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean"); assertObjectValueDeserialized(typedValue, javaSerializable); assertObjectValueSerializedJava(typedValue, javaSerializable); }
@Test @OperateOnDeployment("dummy-client") public void testGracefulDegradationOnMissingClassJava() { // given byte[] serializedPriorityBean = readByteArrayFromClasspath(PRIORITY_BEAN_INSTANCE_FILE); String encodedPriorityBean = StringUtil.fromBytes(Base64.encodeBase64(serializedPriorityBean), processEngine); Map<String, Object> variables = Variables.createVariables().putValue( "priorityBean", Variables.serializedObjectValue(encodedPriorityBean) .serializationDataFormat(SerializationDataFormats.JAVA) .objectTypeName(VARIABLE_CLASS_NAME) .create()); // when processInstance = engine1.getRuntimeService().startProcessInstanceByKey("priorityProcess", variables); // then the job was created successfully and has the default priority although // the bean could not be resolved due to a missing class Job job = engine1.getManagementService().createJobQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult(); Assert.assertEquals(DefaultJobPriorityProvider.DEFAULT_PRIORITY_ON_RESOLUTION_FAILURE, job.getPriority()); }