Package: SpringMvcResponseBuilder
SpringMvcResponseBuilder
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SpringMvcResponseBuilder() |
|
|
|
|
|
||||||||||||||||||||
doBuild() |
|
|
|
|
|
||||||||||||||||||||
getHeader(String) |
|
|
|
|
|
||||||||||||||||||||
withContentLength(long) |
|
|
|
|
|
||||||||||||||||||||
withContentType(String) |
|
|
|
|
|
||||||||||||||||||||
withHeader(String, String) |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.springmvc;
27:
28: import javax.annotation.Nonnegative;
29: import javax.annotation.Nonnull;
30: import javax.annotation.concurrent.NotThreadSafe;
31: import java.util.Optional;
32: import org.springframework.http.HttpHeaders;
33: import org.springframework.http.HttpStatus;
34: import org.springframework.http.MediaType;
35: import org.springframework.http.ResponseEntity;
36: import it.tidalwave.northernwind.core.model.spi.ResponseBuilder;
37: import it.tidalwave.northernwind.core.model.spi.ResponseBuilderSupport;
38: import static java.util.Collections.emptyList;
39:
40: /***************************************************************************************************************************************************************
41: *
42: * @author Fabrizio Giudici
43: *
44: **************************************************************************************************************************************************************/
45: @NotThreadSafe
46: public class SpringMvcResponseBuilder extends ResponseBuilderSupport<ResponseEntity<?>>
47: {
48: private final HttpHeaders headers = new HttpHeaders();
49:
50: @Override @Nonnull
51: public ResponseBuilder withHeader (@Nonnull final String header, @Nonnull final String value)
52: {
53: headers.add(header, value);
54: return this;
55: }
56:
57: @Override @Nonnull
58: protected Optional<String> getHeader (@Nonnull final String header)
59: {
60: return headers.getOrDefault(header, emptyList()).stream().findFirst();
61: }
62:
63: @Override @Nonnull
64: public ResponseBuilder withContentType (@Nonnull final String contentType)
65: {
66: headers.setContentType(MediaType.parseMediaType(contentType));
67: return this;
68: }
69:
70: @Override @Nonnull
71: public ResponseBuilder withContentLength (@Nonnegative final long contentLength)
72: {
73: headers.setContentLength(contentLength);
74: return this;
75: }
76:
77: @Override @Nonnull
78: protected ResponseEntity<?> doBuild()
79: {
80: return new ResponseEntity<>(body, headers, HttpStatus.valueOf(httpStatus));
81: }
82: }
83: