Skip to content

Package: SpringMvcResponseBuilder

SpringMvcResponseBuilder

nameinstructionbranchcomplexitylinemethod
SpringMvcResponseBuilder()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
doBuild()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getHeader(String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
withContentLength(long)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
withContentType(String)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
withHeader(String, String)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

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