View controllerLayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected final Function<UserNotPresentError, ResponseEntity<?>> userFacadeErrorHandler = | |
userNotPresentError -> ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); | |
protected final Function<Either<ItemsError, ?>, ResponseEntity> resultHandler = serviceResult -> serviceResult.fold( | |
itemsError -> handleItemsError(itemsError), | |
successValue -> Match(successValue).of( | |
Case($(), () -> ResponseEntity.ok(successValue).build()) | |
) | |
); |
View userOrFail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected Either<UserNotPresentError, UserId> userOrFail(RequestContext requestContext) { | |
return requestContext.userId().toEither(UserNotPresentError::new); | |
} |
View dbCallWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected <T> Either<ItemsDbError, T> tryDbCall(Supplier<T> dbCall) { | |
return Try.of(dbCall::get) | |
.fold( | |
dbError -> { | |
logger.warn("Problem executing db operation", dbError); | |
return Left(new ItemsDbError(dbError.getMessage())); | |
}, | |
Either::right | |
); | |
} |
View TokenString2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
@Scope(scopeName = ScopeConfig.THREAD_INHERITED, | |
proxyMode = ScopedProxyMode.TARGET_CLASS) | |
public TokenString tokenString() { | |
HttpServletRequest request = ((ServletRequestAttributes) | |
RequestContextHolder | |
.currentRequestAttributes()) | |
.getRequest(); | |
String value = request.getHeader("Authorization").split(" ")[1]; | |
return new TokenString(value); |
View CustomScopeConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public CustomScopeConfigurer customScopeConfigurer() { | |
CustomScopeConfigurer configurer = new CustomScopeConfigurer(); | |
Map<String, Object> scopes = new HashMap<>(); | |
scopes.put(THREAD_INHERITED, new InheritedThreadScope()); | |
configurer.setScopes(scopes); | |
return configurer; | |
} |
View InheritedThreadScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InheritedThreadScope implements Scope { | |
private static final Logger logger = LoggerFactory.getLogger(InheritedThreadScope.class); | |
private final ThreadLocal<Map<String, Object>> threadScope = | |
new InheritableThreadLocal() { | |
@Override | |
protected Map<String, Object> initialValue() { | |
return new HashMap<>(); | |
} |
View SvcBController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GetMapping | |
public CompletableFuture<ResponseEntity> get() { | |
logger.info("GET request"); | |
return myService.callBAsync().thenApply(status -> | |
status.equals("ok") ? | |
ResponseEntity.ok().build() : | |
ResponseEntity.badRequest().build()); | |
} |
View SvcABean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Autowired | |
TokenString tokenString; | |
public CompletableFuture<String> callBAsync() { | |
return supplyAsync(() -> { | |
logger.info("calling B"); | |
RestTemplate restTemplate = new RestTemplate(); | |
HttpHeaders headers = new HttpHeaders(); | |
headers.set("Authorization", "bearer "+tokenString.getValue()); | |
HttpEntity entity = new HttpEntity(headers); | |
ResponseEntity re = restTemplate.exchange( |
View StupidAsyncGet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GetMapping | |
public CompletableFuture<ResponseEntity> get() { | |
return supplyAsync(() -> ResponseEntity.ok().build()) | |
} |
View TokenString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TokenString { | |
private final String value; | |
public TokenString(String value) { | |
this.value = value; | |
} | |
public String getValue() { | |
return this.value; | |
} |
NewerOlder