• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/main/java/com/meterware/servletunit/ServletUnitWebResponse.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.servletunit;
9

10
import com.meterware.httpunit.FrameSelector;
11
import com.meterware.httpunit.WebResponse;
12

13
import jakarta.servlet.http.HttpServletResponse;
14

15
import java.io.ByteArrayInputStream;
16
import java.io.IOException;
17
import java.net.HttpURLConnection;
18
import java.net.URL;
19

20
/**
21
 * A response from to a request from the simulated servlet environment.
22
 **/
23
class ServletUnitWebResponse extends WebResponse {
24

25
    /**
26
     * Constructs a response object from a servlet response.
27
     *
28
     * @param client
29
     *            the client
30
     * @param frame
31
     *            the target frame on which the response will be displayed
32
     * @param url
33
     *            the url from which the response was received
34
     * @param response
35
     *            the response populated by the servlet
36
     * @param throwExceptionOnError
37
     *            the throw exception on error
38
     *
39
     * @throws IOException
40
     *             Signals that an I/O exception has occurred.
41
     */
42
    ServletUnitWebResponse(ServletUnitClient client, FrameSelector frame, URL url, HttpServletResponse response,
43
            boolean throwExceptionOnError) throws IOException {
44
        super(client, frame, url);
1✔
45
        _response = (ServletUnitHttpResponse) response;
1✔
46
        /** make sure that any IO exception for HTML received page happens here, not later. **/
47
        if (getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST || !throwExceptionOnError) {
1!
48
            defineRawInputStream(new ByteArrayInputStream(_response.getContents()));
1✔
49
            if (getContentType().startsWith("text")) {
1!
50
                loadResponseText();
1✔
51
            }
52
        }
53
    }
1✔
54

55
    /**
56
     * Constructs a response object from a servlet response.
57
     *
58
     * @param client
59
     *            the client
60
     * @param frame
61
     *            the target frame on which the response will be displayed
62
     * @param url
63
     *            the url from which the response was received
64
     * @param response
65
     *            the response populated by the servlet
66
     *
67
     * @throws IOException
68
     *             Signals that an I/O exception has occurred.
69
     */
70
    ServletUnitWebResponse(ServletUnitClient client, FrameSelector frame, URL url, HttpServletResponse response)
71
            throws IOException {
72
        this(client, frame, url, response, true);
1✔
73
    }
1✔
74

75
    /**
76
     * Returns the response code associated with this response.
77
     **/
78
    @Override
79
    public int getResponseCode() {
80
        return _response.getStatus();
1✔
81
    }
82

83
    /**
84
     * Returns the response message associated with this response.
85
     **/
86
    @Override
87
    public String getResponseMessage() {
88
        return _response.getMessage();
×
89
    }
90

91
    @Override
92
    public String[] getHeaderFieldNames() {
93
        return _response.getHeaderFieldNames();
×
94
    }
95

96
    /**
97
     * Returns the value for the specified header field. If no such field is defined, will return null.
98
     **/
99
    @Override
100
    public String getHeaderField(String fieldName) {
101
        return _response.getHeaderField(fieldName);
1✔
102
    }
103

104
    @Override
105
    public String[] getHeaderFields(String fieldName) {
106
        return _response.getHeaderFields(fieldName);
1✔
107
    }
108

109
    @Override
110
    public String toString() {
111
        return "[ _response = " + _response + "]";
×
112
    }
113

114
    // -------------------------------------------- private members ------------------------------------------------
115

116
    /** The response. */
117
    private ServletUnitHttpResponse _response;
118

119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc