How can I throw exception in subprocess in Drools jbpm? - drools

I have several custom WorkItemHandlers, and handle the exception by using handleException(e);
public abstract class AbstractItemHandler extends AbstractLogOrThrowWorkItemHandler implements WorkItemHandler
But I found a very strange thing, if the custom WorkItemHandler is in subprocess, there will be no exception when calling kieSession.startProcess(MAIN_PROCESS_ID, processMap).
It works when there is only one process(bpmn). But when there are more bpmn files, I found the ProcessInstance is return abnormal state.
Assert.assertEquals(ProcessInstance.STATE_ABORTED, processInstance.getState());

Related

Why JpaRepository doesn't commit to database when called from #SpringBootTest?

When repository.save(t) is called from my service, which is in turn called from my controller, all works just fine, and the object is inserted into the database table; But, when the service is called from my test class, Hibernate returns the created object but does not really flush the transaction into the database. I have tried using #Transactinal and #Commit in my test class and also on my #Test methods, but no difference in the result. I have also tried other solutions which involve using org.springframework.test.context.transaction.TestTransaction class, but any method call on this class throws an exception.
this is my super class for test:
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
#TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class QaApplicationTest {
protected abstract void initializeTest() throws Exception;
protected abstract void cleanupTestEffects() throws Exception;
}
And this is my concrete test class:
public class RequestControllerTest extends QaApplicationTest {
#Autowired
private SiteService siteService;
#Autowired
private RequestService requestService;
#Test
#Transactional
public void givenObject_whenInsertToDB_thenCreated() throws Exception{
Site siteObject = siteService.save(siteObject); //Here I need a commit.
Request request = new Request(site.getId());
Request savedRequest = requestService.save(request); //Here database returns "Parent Key Not Found" error.
Assertions.assertTrue(savedRequest.getId()>0);
}
}
I know the #Transactional on test methods are used to roll back all the changes made inside the method, however, In my case, the changes are not even committed in the first place. And I have used #org.springframework.transaction.annotation.Transactional which is the correct annotation. I don't know which part I am doing wrong! Any idea?
My colleague found the issue; we had used a third-party library (Camunda) that had enabled batch-insert on Hibernate. So by disabling the batch operation the issue was resolved and the insert is actually taking place now. Not sure, why we faced this only in Spring Test and not in the main application though. if anyone has a comment, we appreciate it.

Does Crud Repository has saveAll method that works?

I am trying to use CRUDRepository for my development project. I have seen in many posts that CRUD Repository do support saveAll method which allows to save a list of object in the database. But when I am using it, It is giving me an error that saveAll property is not found
Here is the detailed error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'BinaryPartCRUDRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query method public abstract java.util.List xxx.xxx.xx.xxxx.repository.BinaryPartCRUDRepository.saveAll(java.util.List)! No property saveAll found for type BinaryPart!
Here is my code.
public interface BinaryPartCRUDRepository extends CrudRepository<BinaryPart, Long> {
BinaryPart save(BinaryPart binaryPart);
List<BinaryPart> saveAll(List<BinaryPart> binaryParts);
}
The save Function is working. But saveAll is not.
I have also tried to use the Persistence manager to do the batch save. But having null object while doing JUnit Testing. So I am preferring to stay with CRUD Repository. Appreciate any kind of suggestion.
saveAll already there in CrudRepository, so no need to specify your own method for save all in repository interface.
remove this part:
List<BinaryPart> saveAll(List<BinaryPart> binaryParts);
and in your service class , directly call `saveAll method. Remember this method using iterable as param and return value.
The saveAll method has the following signature:
<S extends T> Iterable<S> saveAll(Iterable<S> entities);
You define an additional method with the same name, but a different signature. Spring Data does not know how to create an implementation for that and throws the exception.
Just change your interface to:
public interface BinaryPartCRUDRepository extends CrudRepository<BinaryPart, Long> {}
And you are good to go.

JAX-RS exception handling

I'm relatively new to REST services in Java. I've created one and everything works fine except error handling. If I make a request with incorrectly formed JSON in it, Jackson JSON processor throws an exception which I unable to catch and I get error 500 in client. Exception follows:
javax.ws.rs.InternalServerErrorException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.HashSet out of VALUE_STRING token
I have no idea how to handle exceptions raised outside my code.
Google suggests using Exception Mappers or Phase Inteceptors. Though I could miss something in search results.
What is the proper way to handle such situations?
Please, advise something. I'm stuck with this problem...
A JAX-RS ExceptionMapper should do the job. Just add a class like below to your code and if you have the exception type right, then you should get the hook to customize the handling.
#Provider
public class MyExceptionMapper implements ExceptionMapper<MyException> {
#Override
public Response toResponse(MyException ex) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
}

GWT development mode is quiet

I'm developing a project with GWT for quite some months but since two weeks or so i get no more feedback in the jetty development mode window when an error occures...
How could that come?? Could it be caused by some missconfiguration of the logging module? Some errors appear on the console of the started jetty application as [INFO].
Try CCleaner Software and clean all Recent files, browser Cache, Temporary files etc. Then just restart eclipse or better restart the entire System. Also, check if you have GWT.log("MESSAGE") method called for Errors/Exceptions.
The strange behaviour with GWT can happen if:
You have "server" (not included source code) class
You have only import to server class
One of your bean used to communication by service is not serializable (or not extends IsSerializable) or any of it attributes is not serializable
Your bean used to communication by service do not have not parameters constructor (or any of parent class)
Your bean used to communication by service has final field
I had almost all from this when I searched why my code is broken. I did not included all cases of course :)
Update
In our project we extends AsyncCallback
public abstract class MyAsyncCallback<T> implements AsyncCallback<T> {
#Override
public final void onFailure(Throwable caught) {
yourLogger.log(caught);
onFailureDefault(caught);
}
protected abstract void onFailureImpl(Throwable caught);
}
You has to replace all your AsyncCallback with this. Now you have control on errors. Sometimes there are suppressed by wrong error handling.
See also GWT.setUncaughtExceptionHandler(GWT.UncaughtExceptionHandler handler)

GWT RequestContext ENum in the request

If we use enum as one of the attribute in the Request invocation , it throws an UnsupportedOpeationException and does not even invoke the service method on the server.
#Service(value = DesignService.class, locator = DesignServiceLocator.class)
public interface DesignRequest extends RequestContext {
Request<List<DesignProxy>> findDesign(SortEnum sortorder);
}
when we invoke the designRequest.findDesign(sortorderEnum).fire() the UnsupportOperationException is thrown on the javascript console on chrome dev tools/Firebug console.
Looks like it is related to Issue 6504, which will throw an UnsupportedOperationException if it fails to find the type you are using - consider trying to change to class methods in your enum, or wait until 2.4 is released.
If you are not using anonymous enum instances, can you post more info about this error, such as where the exception is thrown from?