Autoretry incidents by code

Hi, in Camunda 7 I used this code for auto retry incidents. Is any similar way how to do that in platform 8? I need to get ALL incidents from database try to run them again. Thanks

try (
                Stream<Incident> incidentStream = runtimeService.createIncidentQuery()
                        .list()
                        .stream()
        ) {

            incidentStream.forEach(

                    incidentRecord -> {
                        log.info("Retry of process instance {} task {}",
                                incidentRecord.getProcessInstanceId(), incidentRecord.getFailedActivityId());
                        String activityId = incidentRecord.getFailedActivityId();incidentRecord.getFailedActivityId(), incidentRecord.getProcessDefinitionId());
                        if (!activityId.isEmpty())
                            autoRetryJobsId.add(incidentRecord.getConfiguration());
                    }
            );
    private void autoRetry(List<String> ids) {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        processEngine.getManagementService().setJobRetries(ids, 1);
    }

Hi @milousel - I believe this API call is the one you’re looking for:

Thank you a lot. Can you also tell me how to generate bearer token in self managed mode? I run in my local docker environment docker-compose-core.yaml.

@milousel - if you’re using the docker-compose-core configuration, it uses basic authentication only. To use OAuth/OIDC flows, you need to use Identity. For that particular configuration, it defaults to a username of demo/demo.

So can you please tell me what I doing wrong? I add basic authorization as you said, but I still receive code 401. I let default username and password.

public void getAllIncidents() throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "{}");
        Request request = new Request.Builder()
                .url("http://localhost:8081/v1/incidents/search")
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .addHeader("Accept", "application/json")
                .addHeader(HttpHeaders.AUTHORIZATION, Credentials.basic("demo", "demo"))
                //.addHeader("Authorization", "Bearer <TOKEN>")
                .build();
        log.info("http request: {}", request);
        Response response = client.newCall(request).execute();
        log.info("response: {}", response);
    }
    }

response:

Response{protocol=http/1.1, code=401, message=, url=http://localhost:8081/v1/incidents/search}

Hi @milousel - I don’t have an example for Operate off-hand, but this library shows the same basic authentication against Tasklist: GitHub - camunda-community-hub/camunda-tasklist-client-java: Java client for the Tasklist API of Camunda Platform 8 - and you can view an implementation example using that library here: camunda-deep-dives/tasklist-client-examples at main · upgradingdave/camunda-deep-dives · GitHub

Hi,
tried to rewrite it by your example, but it is not still working. Can please try to find what I doing wrong? Thank you a lot of.

SimpleConfig simpleConf = new SimpleConfig();
        simpleConf.addProduct(Product.OPERATE, new SimpleCredential("demo", "demo"));
        Authentication auth = SimpleAuthentication.builder().simpleConfig(simpleConf).build();
        CamundaOperateClient client = CamundaOperateClient.builder().operateUrl("http://localhost:8081").authentication(auth).build();
        List<Incident> incidentList = client.searchIncidents(new SearchQuery());
        log.info("incidents: {}", incidentList);

response:

java.lang.NullPointerException: Cannot invoke “io.camunda.common.http.HttpClient.post(java.lang.Class, java.lang.Class, com.google.common.reflect.TypeToken, Object)” because “this.httpClient” is null
at io.camunda.operate.CamundaOperateClient.searchIncidentResults(CamundaOperateClient.java:102) ~[java-client-operate-8.4.0.jar:8.4.0]
at io.camunda.operate.CamundaOperateClient.searchIncidents(CamundaOperateClient.java:98) ~[java-client-operate-8.4.0.jar:8.4.0]
at com.camunda.eight.demo.service.impl.CamundaServiceImpl.getAllIncidents(CamundaServiceImpl.java:69) ~[classes/:na]

Hi @milousel - I have only done API work using Identity and OAuth, so I don’t have any practical experience to help with here. Perhaps these docs help?

I finally find a solution how to connect to self-manage Operate with simpleCredential:

SimpleConfig simpleConf = new SimpleConfig();
        simpleConf.addProduct(Product.OPERATE, new SimpleCredential("demo", "demo"));
        Authentication auth = SimpleAuthentication.builder().simpleUrl("http://localhost:8081").simpleConfig(simpleConf).build();
        CamundaOperateClient client = CamundaOperateClient.builder().operateUrl("http://localhost:8081").authentication(auth).setup().build();

But I still have a question if is it possibe to invoke autoretry of incident by CamundaOperateClient?