Calling a REST service using business central and JBPM - java

We're trying to do a POC showing we can call an external REST service using JBPM in business-central.
We've created a new BPM, then added a REST service task. We notice at this point that a WID file is created that has REST definition. Inside the WID file, it defines things like URL, Method, and authentication.
We've sifted through all the 7.2 docs, but for the life of us, we cannot figure out how to actually set those parameters and do something useful. Does anyone have a simple "Hello World" using business central 7.2 calling out to an external process?
We see there's a predefinied REST handler: https://github.com/kiegroup/jbpm/blob/master/jbpm-workitems/jbpm-workitems-rest/src/main/java/org/jbpm/process/workitem/rest/RESTWorkItemHandler.java
We're lacking how to assemble all of this; we can't find documentation or examples on something that seems so simple.
Thank you!

If you're using Busines Central, you can edit the process model and check the data assignments for the specific REST node. In there you can set the values of the variables or use some process variable to map dynamic values. Hope it helps.

Related

Is it possible to create a custom form in Camunda BPM changing "on-the-fly" without re-deploy?

I'm new to Camunda and still trying to figure out what things are possible.
Camunda BPM provides at least three ways to create custom forms:
Web-based form using AngularJS https://github.com/camunda/camunda-bpm-examples/tree/master/sdk-js/browser-forms-angular
Web-based form using JSF https://github.com/camunda/camunda-bpm-examples/tree/master/bpmn-model-api/generate-jsf-form
Embedded task form using several mechanisms https://github.com/camunda/camunda-bpm-examples/tree/master/usertask
I suppose I can customize a form any of those ways, but I wonder if I can create "on-the-fly" customization based on a pre-defined template stored in a database.
For example, I have a process of handling customer requests. They usually want something from three categories: A, B, and C.
FormA, FormB, and FormC are different but having typical fields for those kinds of requests.
Is there any way to add FormD in Camunda without re-deploy and changing source code of the task/process?
I mean just add a template of FormD in the database and see changes on the next process start.
Best regards, Ivan
You can bundle process models and custom html template in a deployment and hot deploy it together. No server restart required.
You can do this via Cockpit (if EE) or REST API:
https://docs.camunda.org/manual/develop/reference/rest/deployment/
One possible way to do that is through custom form builder using external service form.io - https://forum.camunda.org/t/form-builder-drag-and-drop-form-server-validations/1092/14
Based on the answer from Camunda BPM forum: https://forum.camunda.org/t/is-it-possible-to-create-on-the-fly-changing-form/20683
So, theoretically it's achievable I assume.

How to handle classes that need web resources?

I'm making a project in Java where I have a class that on its initialization connects to an API to retrieve some info. Based on that info it then provides several methods to use and analyse it.
But what if the web request fails ? Or if I have some other issue. Every method will now fail because they don't have the info required
What I did is having a boolean named loadInfo, and also a public method didLoadInfo, so that the client knows the state of the object. I also add a reloadInfo method to try to reload all info, and every method throws an exception if they are called when the loadInfo variable is false. That exception is a checked exception.
Is there another better way to handle this situation ? The exception thrown by all the methods should be checked or unchecked ?
EDIT:
Is a good idea to maintain default values, but how would you let the client know that the info returned may not be up to date ? Maybe another boolean indicating the info state ?
I think in this kind of scenarios you should use REST, so that your java components will be running on web server independently.
If you UI is up and running(it could be on angular or react js or html) and have REST calls in place to call java REST API, also you can configure other API in same web project independent of REST classes and will be initialized as soon at web context is loaded( for example if you are using spring, as soon as application context is loaded).
Since you are calling other services to retrieve info, use Netflix Hysytix to handle failure gracefully with a fallback method. Obviously, you have many more options to fallback logic.
Check out the official Hystrix Library here.
If you have time, check out my article on LinkedIn.

How to set session key in cookie for every request in jersey

I am using jersey for REST service. I am deploying the REST service using apache tomcat. How do i set the session key in every response.
I have tried the below piece of code
return Response.ok(response.toString(), MediaType.APPLICATION_JSON).cookie(new NewCookie("JSESSIONID", request.getSession().getId())).build();
where request is instance of HttpServletRequest. I want to is there any configuration in web.xml so that the JSESSIONID is set for every response
Generally speaking (this holds true for many frameworks!) anything you want to be used in multiple places is best done with a filter. I'm not going to show you exactly how you do it, as it is very simple and it is better for you to read the docs, but have a look here:
https://jersey.java.net/documentation/latest/filters-and-interceptors.html
You can apply these to both methods and classes, so you only need to place annotations in a couple of places.
A very useful thing for writing clean code!

Create REST Services using Java in Eclipse

I have been looking for a few days at tutorials on this subject but either they aren't exactly what i'm looking for or I cant get them to work. I cant imagine that more people aren't confused on the subject so I will ask here.
What I would like to create is a REST service in Eclipse that I can run on my web server and "connect to" using ajax from a separate dynamic web project. All i'm looking for here at the moment is a simple hello world example of a service returning ajax working alongside a separate web project that consumes the JSON it returns.
Im hoping to get a usable user guide (or at least links to one) that will help me out and future people looking for this same thing.
I have gotten as far as this simple class (i have included Jersey Jars but I dont understand what to do from here):
public class UserRestService {
private static final Logger log = Logger.getLogger(UserRestService.class.getName());
private CreateUserService createUser;
#POST
#Path("/CreateUser/{name}/{age}")
#Consumes("text/html")
public User createUser(#PathParam("name") String name, #PathParam("age") Integer age) {
return createUser.createUser(name, age);
}
}
How do i get this class to be an accessible api service on my tomcat server? How do I setup another web project to consume it (I understand how to make an ajax call this is more a question of how do i setup the projects)? Where do servlets come in ?
Rather than copying jars, it would be better to use maven or gradle for package management. A simple pom.xml (maven) with the dependencies can help you abstract determining the compile and runtime dependencies.
Okay so the Java standard is jaxrs (https://jax-rs-spec.java.net/). You can use Jersey which is the rest implementation of jaxrs (https://jersey.java.net/).
A sample of implementing a service using eclipse, jersey and tomcat can be found here: http://www.vogella.com/articles/REST/article.html
If you are feeling like an adventure you can look at vertx.io (http://vertx.io) and my beta release of jaxrs 2.0 framework for vertx called 'vest' (https://github.com/kevinbayes/vest)
Addition:
Jersey provides examples on github of how to implement services at https://github.com/jersey/jersey/tree/master/examples

Axis2 Options: setAction()

I've successfully managed to create a HTTP Basic Authentication Client.
There is a particular operation that I'm having some doubts as to it's purpose.
I tried a tutorial for a simple helloworld script and some other tutorials are the internet and I saw this:
options.setAction("urn:echo");
If I comment this line of code, the client works anyway.
So what does it do? I can't find specific information about this.
I know that my service has an "echo" operation.
So if I had both an "echo" and "echo2" operations, I would have to call setAction for each one?
Regards,
Nuno.
This is the soapAction attribute in wsdl binding for operation element. If nothing is specified in the WSDL then its value should be blank string or the exact value mentioned in the WSDL should be used here.
Its purpose is not very well defined but it can be used for filtering the traffic.

Categories