use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.
the class FetchAndLockHandlerImpl method addPendingRequest.
@Override
public void addPendingRequest(FetchExternalTasksExtendedDto dto, AsyncResponse asyncResponse, ProcessEngine processEngine) {
Long asyncResponseTimeout = dto.getAsyncResponseTimeout();
if (asyncResponseTimeout != null && asyncResponseTimeout > MAX_TIMEOUT) {
invalidRequest(asyncResponse, "The asynchronous response timeout cannot be set to a value greater than " + MAX_TIMEOUT + " milliseconds");
return;
}
IdentityService identityService = processEngine.getIdentityService();
Authentication authentication = identityService.getCurrentAuthentication();
FetchAndLockRequest incomingRequest = new FetchAndLockRequest().setProcessEngine(processEngine).setAsyncResponse(asyncResponse).setAuthentication(authentication).setDto(dto);
FetchAndLockResult result = tryFetchAndLock(incomingRequest);
if (result.wasSuccessful()) {
List<LockedExternalTaskDto> lockedTasks = result.getTasks();
if (!lockedTasks.isEmpty() || dto.getAsyncResponseTimeout() == null) {
// response immediately if tasks available
asyncResponse.resume(lockedTasks);
} else {
addRequest(incomingRequest);
}
} else {
ProcessEngineException processEngineException = result.getProcessEngineException();
asyncResponse.resume(processEngineException);
}
}
use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.
the class FetchAndLockHandlerImpl method acquire.
protected void acquire() {
queue.drainTo(pendingRequests);
// timestamp
long backoffTime = MAX_BACK_OFF_TIME;
Iterator<FetchAndLockRequest> iterator = pendingRequests.iterator();
while (iterator.hasNext()) {
FetchAndLockRequest pendingRequest = iterator.next();
long currentTime = ClockUtil.getCurrentTime().getTime();
FetchAndLockResult result = tryFetchAndLock(pendingRequest);
if (result.wasSuccessful()) {
List<LockedExternalTaskDto> lockedTasks = result.getTasks();
long timeout = pendingRequest.getTimeoutTimestamp();
if (!lockedTasks.isEmpty() || timeout <= currentTime) {
AsyncResponse asyncResponse = pendingRequest.getAsyncResponse();
iterator.remove();
asyncResponse.resume(lockedTasks);
} else {
if (timeout < backoffTime) {
backoffTime = timeout;
}
}
} else {
AsyncResponse asyncResponse = pendingRequest.getAsyncResponse();
iterator.remove();
ProcessEngineException processEngineException = result.getProcessEngineException();
asyncResponse.resume(processEngineException);
}
}
suspend(Math.max(0, backoffTime - ClockUtil.getCurrentTime().getTime()));
}
use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.
the class FetchAndLockHandlerTest method shouldResumeAsyncResponseAfterBackoffDueToProcessEngineException.
@Test
public void shouldResumeAsyncResponseAfterBackoffDueToProcessEngineException() {
// given
doReturn(Collections.emptyList()).when(fetchTopicBuilder).execute();
AsyncResponse asyncResponse = mock(AsyncResponse.class);
handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);
handler.acquire();
// assume
assertThat(handler.getPendingRequests().size(), is(1));
verify(handler).suspend(5000L);
// when
doThrow(new ProcessEngineException()).when(fetchTopicBuilder).execute();
handler.acquire();
// then
assertThat(handler.getPendingRequests().size(), is(0));
verify(handler).suspend(Long.MAX_VALUE - ClockUtil.getCurrentTime().getTime());
verify(asyncResponse).resume(any(ProcessEngineException.class));
}
use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.
the class FetchAndLockRestServiceInteractionTest method shouldThrowProcessEngineExceptionNotDuringTimeout.
@Test
public void shouldThrowProcessEngineExceptionNotDuringTimeout() {
FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L);
when(fetchTopicBuilder.execute()).thenThrow(new ProcessEngineException("anExceptionMessage"));
given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().body("type", equalTo(ProcessEngineException.class.getSimpleName())).body("message", equalTo("anExceptionMessage")).statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE);
verify(fetchTopicBuilder, times(1)).execute();
}
use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.
the class FallbackSerializationTest method testSerializationOfUnknownFormat.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationOfUnknownFormat() {
// given
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// when
ObjectValue objectValue = Variables.serializedObjectValue("foo").serializationDataFormat("application/foo").objectTypeName("org.camunda.Foo").create();
runtimeService.setVariable(instance.getId(), "var", objectValue);
// then
try {
runtimeService.getVariable(instance.getId(), "var");
fail();
} catch (ProcessEngineException e) {
assertTextPresent("Fallback serializer cannot handle deserialized objects", e.getMessage());
}
ObjectValue returnedValue = runtimeService.getVariableTyped(instance.getId(), "var", false);
assertFalse(returnedValue.isDeserialized());
assertEquals("application/foo", returnedValue.getSerializationDataFormat());
assertEquals("foo", returnedValue.getValueSerialized());
assertEquals("org.camunda.Foo", returnedValue.getObjectTypeName());
}
Aggregations