Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix(#1114): switch to camunda rest client feign #1117

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions digiwf-connector/digiwf-camunda-connector-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>

<!-- DigiWF -->
<dependency>
<groupId>de.muenchen.oss.digiwf</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package de.muenchen.oss.digiwf.connector;

import de.muenchen.oss.digiwf.spring.security.client.OAuth2AccessTokenSupplier;
import feign.RequestInterceptor;
import lombok.AllArgsConstructor;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
import org.camunda.community.rest.client.invoker.ApiClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import java.io.IOException;
import org.springframework.http.HttpHeaders;

@Configuration
@Profile("!no-security")
Expand All @@ -25,31 +16,17 @@

private final OAuth2AccessTokenSupplier tokenSupplier;

// Camunda External Task
@Bean
public ClientRequestInterceptor interceptor() {
return context -> {
context.addHeader("Authorization", this.getAccessToken());
};
}

@Autowired
public void addOAuthInterceptor(final ApiClient apiClient) {
apiClient.setHttpClient(HttpClientBuilder.create().addRequestInterceptorFirst(this::intercept).build());
}

private void intercept(HttpRequest httpRequest, EntityDetails entityDetails, HttpContext httpContext) {
httpRequest.addHeader("Authorization", this.getAccessToken());
}

public Response intercept(final Interceptor.Chain chain) throws IOException {
final Request originalRequest = chain.request();
final Request requestWithToken = originalRequest.newBuilder()
.header("Authorization", this.getAccessToken())
.build();
return chain.proceed(requestWithToken);
return context ->
context.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + this.tokenSupplier.get().getTokenValue());

Check warning on line 23 in digiwf-connector/digiwf-camunda-connector-service/src/main/java/de/muenchen/oss/digiwf/connector/CamundaSecurityConfig.java

View check run for this annotation

Codecov / codecov/patch

digiwf-connector/digiwf-camunda-connector-service/src/main/java/de/muenchen/oss/digiwf/connector/CamundaSecurityConfig.java#L22-L23

Added lines #L22 - L23 were not covered by tests
}

public String getAccessToken() {
return "Bearer " + this.tokenSupplier.get().getTokenValue();
// Feign
@Bean
public RequestInterceptor oAuth2RequestInterceptor() {
return (requestTemplate ->
requestTemplate.header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenSupplier.get().getTokenValue()));

Check warning on line 30 in digiwf-connector/digiwf-camunda-connector-service/src/main/java/de/muenchen/oss/digiwf/connector/CamundaSecurityConfig.java

View check run for this annotation

Codecov / codecov/patch

digiwf-connector/digiwf-camunda-connector-service/src/main/java/de/muenchen/oss/digiwf/connector/CamundaSecurityConfig.java#L29-L30

Added lines #L29 - L30 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package de.muenchen.oss.digiwf.connector;

import org.camunda.community.rest.EnableCamundaRestClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
@EnableCamundaRestClient
public class DigiWFConnectorApplication {

public static void main(final String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
server.port=8080
[email protected]@
camunda.bpm.client.date-format=yyyy-MM-dd'T'HH:mm:ss.SSSX

feign.client.config.default.url=${ENGINE_CAMUNDA_REST_ENDPOINT_URL}
13 changes: 6 additions & 7 deletions digiwf-connector/digiwf-camunda-connector-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,17 @@
<version>${project.version}</version>
</dependency>

<!-- Camunda -->
<dependency>
<groupId>org.camunda.community</groupId>
<artifactId>camunda-engine-rest-client-openapi-springboot</artifactId>
<version>${camunda-engine-rest-client-openapi-java.version}</version>
</dependency>

<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-external-task-client</artifactId>
<version>${camunda.version}</version>
</dependency>
<!-- Old Dependency - We should use https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api but camunda-bpm-spring-boot-starter-external-task-client requires it -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.muenchen.oss.digiwf.camunda.connector.configuration;

import de.muenchen.oss.digiwf.camunda.connector.output.CamundaOutputClient;
import de.muenchen.oss.digiwf.camunda.connector.data.EngineDataSerializer;
import de.muenchen.oss.digiwf.camunda.connector.output.CamundaOutputClient;
import de.muenchen.oss.digiwf.camunda.connector.output.CamundaOutputConfiguration;
import de.muenchen.oss.digiwf.connector.api.output.OutputService;
import de.muenchen.oss.digiwf.connector.output.internal.OutputServiceImpl;
Expand Down
15 changes: 12 additions & 3 deletions digiwf-connector/digiwf-camunda-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@

<!-- Camunda -->
<dependency>
<groupId>org.camunda.community</groupId>
<artifactId>camunda-engine-rest-client-openapi-java</artifactId>
<version>${camunda-engine-rest-client-openapi-java.version}</version>
<groupId>org.camunda.community.rest</groupId>
<artifactId>camunda-platform-7-rest-client-spring-boot-starter</artifactId>
<version>7.20.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>

<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-external-task-client-spring</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.camunda.community.rest.client.api.MessageApi;
import org.camunda.community.rest.client.dto.CorrelationMessageDto;
import org.camunda.community.rest.client.invoker.ApiException;
import org.camunda.community.rest.client.model.CorrelationMessageDto;
import org.springframework.stereotype.Service;

@Slf4j
Expand Down Expand Up @@ -42,12 +41,7 @@ public void createBpmnError(final BpmnError bpmnError) {
correlationMessageDto.putProcessVariablesItem(VARIABLEKEY_ERROR_MESSAGE, this.serializer.toEngineData(bpmnError.getErrorMessage()));
}

try {
this.messageApi.deliverMessage(correlationMessageDto);
} catch (final ApiException apiException) {
log.error("Bpmn error could not be sent.", apiException);
throw new RuntimeException(apiException);
}
this.messageApi.deliverMessage(correlationMessageDto);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.value.TypedValue;
import org.camunda.community.rest.client.dto.VariableValueDto;
import org.camunda.community.rest.client.model.VariableValueDto;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -58,6 +58,4 @@ private Object fromEngineData(final Object value) {
}
return new JSONObject(value.toString()).toMap();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import lombok.extern.slf4j.Slf4j;
import org.camunda.community.rest.client.api.EventSubscriptionApi;
import org.camunda.community.rest.client.api.ExecutionApi;
import org.camunda.community.rest.client.dto.CreateIncidentDto;
import org.camunda.community.rest.client.dto.EventSubscriptionDto;
import org.camunda.community.rest.client.invoker.ApiException;
import org.camunda.community.rest.client.model.CreateIncidentDto;
import org.camunda.community.rest.client.model.EventSubscriptionDto;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.NoSuchElementException;

@Slf4j
Expand All @@ -34,21 +34,25 @@
Assert.notNull(messageName, "message name cannot be empty");

//load corresponding event subscription
final String executionId = this.eventSubscriptionApi.getEventSubscriptions(
null,
messageName,
EVENT_TYPE,
null,
processInstanceId,
null,
null,
null,
null,
null,
null,
null,
null)
.stream()
final List<EventSubscriptionDto> eventSubscriptions = this.eventSubscriptionApi.getEventSubscriptions(
null,
messageName,
EVENT_TYPE,
null,
processInstanceId,
null,
null,
null,
null,
null,
null,
null,
null)
.getBody();
if (eventSubscriptions.isEmpty()) {
throw new NoSuchElementException();

Check warning on line 53 in digiwf-connector/digiwf-camunda-connector/src/main/java/de/muenchen/oss/digiwf/camunda/connector/incident/IncidentServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

digiwf-connector/digiwf-camunda-connector/src/main/java/de/muenchen/oss/digiwf/camunda/connector/incident/IncidentServiceImpl.java#L53

Added line #L53 was not covered by tests
}
final String executionId = eventSubscriptions.stream()
.findFirst()
.map(EventSubscriptionDto::getExecutionId)
.orElseThrow();
Expand All @@ -64,10 +68,6 @@

// send create incident call
this.executionApi.createIncident(executionId, createIncidentDto);

} catch (final ApiException e) {
log.error("Cannot create incident for processinstance id {} and message name {}: {}", processInstanceId, messageName, e.getResponseBody());
throw new RuntimeException(e);
} catch (final NoSuchElementException | IllegalArgumentException e) {
log.error("Cannot create incident for processinstance id {} and message name {}", processInstanceId, messageName);
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.camunda.community.rest.client.api.MessageApi;
import org.camunda.community.rest.client.dto.CorrelationMessageDto;
import org.camunda.community.rest.client.dto.VariableValueDto;
import org.camunda.community.rest.client.invoker.ApiException;
import org.camunda.community.rest.client.model.CorrelationMessageDto;
import org.camunda.community.rest.client.model.VariableValueDto;
import org.springframework.stereotype.Service;

import java.util.Map;
Expand Down Expand Up @@ -48,12 +47,7 @@ public void correlateMessage(final CorrelateMessage correlateMessage) {
correlationMessageDto.setBusinessKey(correlateMessage.getBusinessKey());
}

try {
this.messageApi.deliverMessage(correlationMessageDto);
} catch (final ApiException apiException) {
log.error("Message could not be sent.", apiException);
throw new RuntimeException(apiException);
}
this.messageApi.deliverMessage(correlationMessageDto);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,34 @@

import de.muenchen.oss.digiwf.camunda.connector.bpmnerror.BpmnErrorServiceImpl;
import de.muenchen.oss.digiwf.camunda.connector.data.EngineDataSerializer;
import de.muenchen.oss.digiwf.connector.bpmnerror.internal.impl.model.BpmnErrorImpl;
import de.muenchen.oss.digiwf.connector.BaseSpringTest;
import de.muenchen.oss.digiwf.connector.api.bpmnerror.BpmnError;
import de.muenchen.oss.digiwf.connector.api.bpmnerror.BpmnErrorService;
import de.muenchen.oss.digiwf.connector.bpmnerror.internal.impl.model.BpmnErrorImpl;
import org.camunda.community.rest.client.api.MessageApi;
import org.camunda.community.rest.client.invoker.ApiException;
import org.junit.jupiter.api.*;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@DisplayName("Bpmn error Service Test")
@Import({EngineDataSerializer.class})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BpmnErrorServiceTest extends BaseSpringTest {
class BpmnErrorServiceTest {
private final MessageApi messageApi = mock(MessageApi.class);

@Mock
private MessageApi messageApi;

@Autowired
private EngineDataSerializer engineDataSerializer;
private final EngineDataSerializer engineDataSerializer = new EngineDataSerializer();

private BpmnErrorService bpmnErrorService;

@BeforeEach
private void initTests() {
void initTests() {
this.bpmnErrorService = new BpmnErrorServiceImpl(this.messageApi, this.engineDataSerializer);
}

@Order(1)
@Test
@DisplayName("should correlate bpmn error")
public void shouldCorrelateBpmnError() throws ApiException {
void shouldCorrelateBpmnError() {

final BpmnError bpmnError = BpmnErrorImpl.builder()
.messageName("myMessage")
Expand All @@ -51,5 +43,4 @@ public void shouldCorrelateBpmnError() throws ApiException {

verify(this.messageApi).deliverMessage(any());
}

}
Loading