Skip to content

Commit

Permalink
fix: web jersey
Browse files Browse the repository at this point in the history
  • Loading branch information
gbzarelli committed Jan 18, 2023
1 parent cf133b5 commit f876043
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .docker-compose/spring-app.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'
version: '3.3'

services:

Expand All @@ -7,7 +7,7 @@ services:
ports:
- 8080:8080
environment:
MYSQL_URL: jdbc:mysql://db:3306/sample
MYSQL_URL: jdbc:mysql://sampledb:3306/sample
MYSQL_USER: user
MYSQL_PASSWORD: pass
MYSQL_PASSWORD: pass123

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ mvn clean install
```

#### Spring boot

Nota: O projeto com Spring Boot não está finalizado. No caso o profile do Spring está sem o módulo
de output: `restclient-http-service`, pois o Spring Boot não tem uma implementação para o microprofile-restclient
no caso, o ideal seria a criação de um modulo com o Feign para implementar a porta do use-case: `ProtocolGeneratorClient`
Porém, atualmente para o projeto rodar, essa porta foi implementada como um fake no modulo da app `spring-app` no seguinte package: ` br.com.helpdev.protocolgenerator`.
Mas o módulo de `acceptance-test` irá falhar, pois o mesmo faz um mock desse serviço;

```bash
mvn clean install -Pspring
```
Expand All @@ -105,6 +112,11 @@ mvn clean install -Pspring
docker build -t helpdev/app-quarkus-jvm .
```

## Gerando imagem docker com o Spring
```bash
docker build -t helpdev/app-spring-jvm .
```

## Iniciando serviço

*O comando sobe toda infraestrutura necessária para a aplicação*
Expand All @@ -113,10 +125,17 @@ docker-compose -f .docker-compose/stack.yml up
```

*Agora podemos iniciar nossa aplicação*

Quarkus:
```bash
docker-compose -f .docker-compose/quarkus-app.yml up
```

Spring:
```bash
docker-compose -f .docker-compose/spring-app.yml up
```

## Consumindo API

<p align="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.ZonedDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ChatResponseDto {

private StatusResponseDto status;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package br.com.helpdev.controller.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@Builder
@EqualsAndHashCode
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class ErrorDto {

private String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@Builder
@ToString
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
public class MessageCreateDto {

@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.ZonedDateTime;
import java.util.Collection;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MessageResponseDto {

private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import br.com.helpdev.domain.Recipient;
import javax.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@EqualsAndHashCode
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RecipientDto {

@NotBlank(message = "Recipient name can't be null!")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package br.com.helpdev;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(
scanBasePackages = {"br.com.helpdev"}
)
@EnableAutoConfiguration
public class SpringSampleApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package br.com.helpdev.config;

import br.com.helpdev.controller.config.CustomObjectMapperConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

@Configuration
public class ObjectMapperConfig {

@Bean
public ObjectMapper objectMapper(final Jackson2ObjectMapperBuilder builder) {
final var objectMapper = builder.build();
CustomObjectMapperConfig.customize(objectMapper);
return objectMapper;
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package br.com.helpdev.config;

import java.util.Objects;
import java.util.stream.Collectors;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.util.ClassUtils;

@Configuration
@Slf4j
public class WebJerseyConfiguration extends ResourceConfig {

public WebJerseyConfiguration() {
var scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(Provider.class));
scanner.addIncludeFilter(new AnnotationTypeFilter(Path.class));
scanner.findCandidateComponents("br.com.helpdev.controller").forEach(beanDefinition -> {
try {
register(Class.forName(beanDefinition.getBeanClassName()));
} catch (ClassNotFoundException e) {
log.warn("Failed to register: {}", beanDefinition.getBeanClassName());
}
});
registerClasses(
scanner.findCandidateComponents("br.com.helpdev.controller").stream()
.map(
beanDefinition ->
ClassUtils.resolveClassName(
Objects.requireNonNull(beanDefinition.getBeanClassName()),
getClassLoader()))
.collect(Collectors.toSet()));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package br.com.helpdev.protocolgenerator;

import br.com.helpdev.usecase.port.ProtocolGeneratorClient;
import java.util.Random;
import org.springframework.stereotype.Component;

@Component
public class FakeProtocolGenerator implements ProtocolGeneratorClient {

public static final Random RANDOM = new Random();

@Override
public String generateNewProtocol() {
return "PROT-" + RANDOM.nextInt(Integer.MAX_VALUE);
}
}
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<module>core/use-case</module>
<module>adapter/input/jaxrs-controller-v1</module>
<module>adapter/output/jpa-mysql-repository</module>
<module>adapter/output/restclient-http-services</module>
<!--TODO: The restclient don't work in Spring; In this sample, the implementation about ProtocolGeneratorClient is in the spring-app module ( br.com.helpdev.protocolgenerator )-->
<!--<module>adapter/output/restclient-http-services</module>-->
<module>app/spring-app</module>
<module>acceptance-test</module>
</modules>
Expand Down Expand Up @@ -88,7 +89,7 @@
<assertj.version>3.22.0</assertj.version>
<testcontainers.version>1.17.1</testcontainers.version>
<java-faker.version>1.0.2</java-faker.version>
<glassfish.test.version>2.32</glassfish.test.version>
<glassfish.test.version>2.35</glassfish.test.version>

<!-- Specs / apis -->
<jakarta.enterprise.cdi-api.version>2.0.2</jakarta.enterprise.cdi-api.version>
Expand All @@ -100,7 +101,7 @@
<jaxb-api.version>2.3.1</jaxb-api.version>

<!-- Others -->
<jersey.version>2.32</jersey.version>
<jersey.version>2.35</jersey.version>
<lombok.version>1.18.24</lombok.version>

<slf4j.version>1.7.36</slf4j.version>
Expand Down

0 comments on commit f876043

Please sign in to comment.