Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yhao3 committed Aug 30, 2024
1 parent 3a30169 commit b862ee9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _%>
return ResponseEntity.ok().body(entityList);
<%_ } else { _%>
Page<<%= instanceType %>> page = <%= entityInstance %>QueryService.findByCriteria(criteria, pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (!reactive) { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } else { %>ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders())<% } %>, page);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (!reactive) { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } else { %>UriComponentsBuilder.fromUri(request.getURI())<% } %>, page);
return ResponseEntity.ok().headers(headers).body(page.getContent());
<%_ } _%>
<%_ } else { _%>
Expand All @@ -47,7 +47,7 @@ _%>
ResponseEntity.ok()
.headers(
PaginationUtil.generatePaginationHttpHeaders(
ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders()),
UriComponentsBuilder.fromUri(request.getURI()),
new PageImpl<>(countWithEntities.getT2(), pageable, countWithEntities.getT1())
)
).body(countWithEntities.getT2())
Expand Down Expand Up @@ -104,7 +104,7 @@ _%>
ResponseEntity.ok()
.headers(
PaginationUtil.generatePaginationHttpHeaders(
ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders()),
UriComponentsBuilder.fromUri(request.getURI()),
new PageImpl<>(countWithEntities.getT2(), pageable, countWithEntities.getT1())
)
).body(countWithEntities.getT2())
Expand All @@ -117,10 +117,10 @@ _%>
} else {
page = <%= entityInstance %><%= viaService ? 'Service' : 'Repository' %>.findAll(pageable)<%= reactiveEntityToDto %>;
}
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders())<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>UriComponentsBuilder.fromUri(request.getURI())<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
<%_ } else { _%>
Page<<%= instanceType %>> page = <%= entityInstance %><%= viaService ? 'Service' : 'Repository' %>.findAll(pageable)<%= reactiveEntityToDto %>;
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders())<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>UriComponentsBuilder.fromUri(request.getURI())<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
<%_ } _%>
return ResponseEntity.ok().headers(headers).body(page.getContent());
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (paginationNo) { %>
'Service.' + (searchEngineElasticsearch ? 'searchCount' : 'countAll') :
(searchEngineElasticsearch ? 'Search' : '') + 'Repository.count' %>()
.map(total -> new PageImpl<>(new ArrayList<>(), pageable, total))
.map(page -> PaginationUtil.generatePaginationHttpHeaders(ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders()), page))
.map(page -> PaginationUtil.generatePaginationHttpHeaders(UriComponentsBuilder.fromUri(request.getURI()), page))
.map(headers -> ResponseEntity.ok().headers(headers).body(<%= entityInstance %><%= viaService ? 'Service' : (searchEngineElasticsearch ? 'Search' : '') + 'Repository' %>.search(query, pageable)<% if (!viaService && dtoMapstruct) { %>.map(<%= entityToDtoReference %>)<% } %>));
<%_ } else { _%>
try {
Expand All @@ -43,7 +43,7 @@ if (paginationNo) { %>
<%_ } else { _%>
Page<<%= persistClass %>> page = <%= entityInstance %><% if (searchEngineElasticsearch) { %>Search<% } %>Repository.search(query, pageable);
<%_ } _%>
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders())<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>UriComponentsBuilder.fromUri(request.getURI())<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
return ResponseEntity.ok().headers(headers).body(<% if (!viaService && dtoMapstruct) { %><%= entityListToDtoListReference %>(<% } %>page.getContent()<% if (!viaService && dtoMapstruct) { %>)<% } %>);
} catch (RuntimeException e) {
<% if (searchEngineElasticsearch) { %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.*;
<%_ if (reactive) { _%>
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.util.ForwardedHeaderUtils;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
<%_ } else {_%>
Expand Down Expand Up @@ -133,7 +133,7 @@ public class PublicUserResource {
return userService.countManagedUsers()
.map(total -> new PageImpl<>(new ArrayList<>(), pageable, total))
.map(page -> PaginationUtil.generatePaginationHttpHeaders(ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders()), page))
.map(page -> PaginationUtil.generatePaginationHttpHeaders(UriComponentsBuilder.fromUri(request.getURI()), page))
.map(headers -> ResponseEntity.ok().headers(headers).body(userService.getAllPublicUsers(pageable)));
}
<%_ } else { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
<%_ if (reactive) { _%>
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.util.ForwardedHeaderUtils;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
<%_ } else { _%>
Expand Down Expand Up @@ -288,7 +288,7 @@ public class UserResource {
.map(total -> new PageImpl<>(new ArrayList<>(), pageable, total))
.map(page ->
PaginationUtil.generatePaginationHttpHeaders(
ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders()),
UriComponentsBuilder.fromUri(request.getURI()),
page
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
<%_ } _%>
<%_ if (reactive) { _%>
import org.springframework.web.util.ForwardedHeaderUtils;
import org.springframework.web.util.UriComponentsBuilder;
<%_ } else { _%>
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ import org.springframework.web.cors.CorsConfiguration;
<%_ if (!reactive) { _%>
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.filter.ForwardedHeaderFilter;
<%_ } _%>
<%_ if (reactive) { _%>
import org.springframework.web.cors.reactive.CorsConfigurationSource;;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver;
import org.springframework.web.server.WebExceptionHandler;
import org.springframework.web.server.adapter.ForwardedHeaderTransformer;
import <%= packageName %>.web.rest.errors.ExceptionTranslator;
import tech.jhipster.web.rest.errors.ReactiveWebExceptionHandler;
<%_ } _%>
Expand Down Expand Up @@ -122,6 +124,11 @@ public class WebConfigurer implements <% if (!reactive) { %>ServletContextInitia
<%_ if (!reactive) { _%>
@Bean
public ForwardedHeaderFilter forwardedHeaderFilter() {
return new ForwardedHeaderFilter();
}
@Override
public void onStartup(ServletContext servletContext) {
if (env.getActiveProfiles().length != 0) {
Expand Down Expand Up @@ -214,6 +221,11 @@ public class WebConfigurer implements <% if (!reactive) { %>ServletContextInitia
return new ReactiveWebExceptionHandler(problemHandling, mapper);
}

@Bean
public ForwardedHeaderTransformer forwardedHeaderTransformer() {
return new ForwardedHeaderTransformer();
}

<%_ if (!skipClient) { _%>

@Bean
Expand Down

0 comments on commit b862ee9

Please sign in to comment.