Search in sources :

Example 56 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerTest method shouldResumeAsyncResponseDueToTimeoutExceeded.

@Test
public void shouldResumeAsyncResponseDueToTimeoutExceeded() {
    // given - no pending requests
    // assume
    assertThat(handler.getPendingRequests().size(), is(0));
    // when
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    handler.addPendingRequest(createDto(FetchAndLockHandlerImpl.MAX_TIMEOUT + 1), asyncResponse, processEngine);
    // then
    verify(handler, never()).suspend(anyLong());
    assertThat(handler.getPendingRequests().size(), is(0));
    ArgumentCaptor<InvalidRequestException> argumentCaptor = ArgumentCaptor.forClass(InvalidRequestException.class);
    verify(asyncResponse).resume(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getMessage(), is("The asynchronous response timeout cannot " + "be set to a value greater than " + FetchAndLockHandlerImpl.MAX_TIMEOUT + " milliseconds"));
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.junit.Test)

Example 57 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerImpl method invalidRequest.

protected void invalidRequest(AsyncResponse asyncResponse, String message) {
    InvalidRequestException invalidRequestException = new InvalidRequestException(Status.BAD_REQUEST, message);
    asyncResponse.resume(invalidRequestException);
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 58 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class AbstractReportDto method executeReport.

public List<? extends ReportResult> executeReport(ProcessEngine engine) {
    T reportQuery = createNewReportQuery(engine);
    applyFilters(reportQuery);
    try {
        return executeReportQuery(reportQuery);
    } catch (NotValidException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, e.getMessage());
    }
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 59 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class VariableValueDto method toTypedValue.

public TypedValue toTypedValue(ProcessEngine processEngine, ObjectMapper objectMapper) {
    ValueTypeResolver valueTypeResolver = processEngine.getProcessEngineConfiguration().getValueTypeResolver();
    if (type == null) {
        if (valueInfo != null && valueInfo.get(ValueType.VALUE_INFO_TRANSIENT) instanceof Boolean) {
            return Variables.untypedValue(value, (Boolean) valueInfo.get(ValueType.VALUE_INFO_TRANSIENT));
        }
        return Variables.untypedValue(value);
    }
    ValueType valueType = valueTypeResolver.typeForName(fromRestApiTypeName(type));
    if (valueType == null) {
        throw new RestException(Status.BAD_REQUEST, String.format("Unsupported value type '%s'", type));
    } else {
        if (valueType instanceof PrimitiveValueType) {
            PrimitiveValueType primitiveValueType = (PrimitiveValueType) valueType;
            Class<?> javaType = primitiveValueType.getJavaType();
            Object mappedValue = null;
            try {
                if (value != null) {
                    if (javaType.isAssignableFrom(value.getClass())) {
                        mappedValue = value;
                    } else {
                        // use jackson to map the value to the requested java type
                        mappedValue = objectMapper.readValue("\"" + value + "\"", javaType);
                    }
                }
                return valueType.createValue(mappedValue, valueInfo);
            } catch (Exception e) {
                throw new InvalidRequestException(Status.BAD_REQUEST, e, String.format("Cannot convert value '%s' of type '%s' to java type %s", value, type, javaType.getName()));
            }
        } else if (valueType instanceof SerializableValueType) {
            if (value != null && !(value instanceof String)) {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Must provide 'null' or String value for value of SerializableValue type '" + type + "'.");
            }
            return ((SerializableValueType) valueType).createValueFromSerialized((String) value, valueInfo);
        } else if (valueType instanceof FileValueType) {
            if (value instanceof String) {
                value = Base64.decodeBase64((String) value);
            }
            return valueType.createValue(value, valueInfo);
        } else {
            return valueType.createValue(value, valueInfo);
        }
    }
}
Also used : SerializableValueType(org.camunda.bpm.engine.variable.type.SerializableValueType) SerializableValueType(org.camunda.bpm.engine.variable.type.SerializableValueType) FileValueType(org.camunda.bpm.engine.variable.type.FileValueType) ValueType(org.camunda.bpm.engine.variable.type.ValueType) PrimitiveValueType(org.camunda.bpm.engine.variable.type.PrimitiveValueType) PrimitiveValueType(org.camunda.bpm.engine.variable.type.PrimitiveValueType) RestException(org.camunda.bpm.engine.rest.exception.RestException) ValueTypeResolver(org.camunda.bpm.engine.variable.type.ValueTypeResolver) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) FileValueType(org.camunda.bpm.engine.variable.type.FileValueType) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) MimeTypeParseException(javax.activation.MimeTypeParseException) RestException(org.camunda.bpm.engine.rest.exception.RestException)

Example 60 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class AbstractVariablesResource method putVariable.

@Override
public void putVariable(String variableName, VariableValueDto variable) {
    try {
        TypedValue typedValue = variable.toTypedValue(engine, objectMapper);
        setVariableEntity(variableName, typedValue);
    } catch (RestException e) {
        throw new InvalidRequestException(e.getStatus(), e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
    } catch (BadUserRequestException e) {
        throw new RestException(Status.BAD_REQUEST, e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Aggregations

InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)116 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)30 RestException (org.camunda.bpm.engine.rest.exception.RestException)25 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)20 NotValidException (org.camunda.bpm.engine.exception.NotValidException)12 ArrayList (java.util.ArrayList)11 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)11 ManagementService (org.camunda.bpm.engine.ManagementService)11 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)11 VariableQueryParameterDto (org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)10 HistoryService (org.camunda.bpm.engine.HistoryService)9 RuntimeService (org.camunda.bpm.engine.RuntimeService)9 InputStream (java.io.InputStream)8 RepositoryService (org.camunda.bpm.engine.RepositoryService)8 Batch (org.camunda.bpm.engine.batch.Batch)8 URI (java.net.URI)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FormService (org.camunda.bpm.engine.FormService)5 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)5