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

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

0.81 hits per line

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

81.82
/src/main/java/com/meterware/httpunit/PostMethodWebRequest.java
1
/*
2
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit;
21

22
import com.meterware.httpunit.protocol.MessageBody;
23
import com.meterware.httpunit.protocol.URLEncodedString;
24

25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.net.URL;
28

29
/**
30
 * An HTTP request using the POST method.
31
 **/
32
public class PostMethodWebRequest extends MessageBodyWebRequest {
33

34
    /**
35
     * Constructs a web request using a specific absolute url string.
36
     *
37
     * @param urlString
38
     *            the url string
39
     */
40
    public PostMethodWebRequest(String urlString) {
41
        this(urlString, false);
1✔
42
    }
1✔
43

44
    /**
45
     * Constructs a web request using a specific absolute url string, with optional mime encoding.
46
     *
47
     * @param urlString
48
     *            the url string
49
     * @param mimeEncoded
50
     *            the mime encoded
51
     */
52
    public PostMethodWebRequest(String urlString, boolean mimeEncoded) {
53
        super(urlString, mimeEncoded);
1✔
54
    }
1✔
55

56
    /**
57
     * Constructs a web request with a specific target.
58
     *
59
     * @param urlBase
60
     *            the url base
61
     * @param urlString
62
     *            the url string
63
     * @param target
64
     *            the target
65
     */
66
    public PostMethodWebRequest(URL urlBase, String urlString, String target) {
67
        this(urlBase, urlString, target, false);
×
68
    }
×
69

70
    /**
71
     * Constructs a web request with a specific target, with optional mime encoding.
72
     *
73
     * @param urlBase
74
     *            the url base
75
     * @param urlString
76
     *            the url string
77
     * @param target
78
     *            the target
79
     * @param mimeEncoded
80
     *            the mime encoded
81
     */
82
    public PostMethodWebRequest(URL urlBase, String urlString, String target, boolean mimeEncoded) {
83
        super(urlBase, urlString, target, mimeEncoded);
×
84
    }
×
85

86
    /**
87
     * Constructs a web request using a specific absolute url string and input stream.
88
     *
89
     * @param urlString
90
     *            the URL to which the request should be issued
91
     * @param source
92
     *            an input stream which will provide the body of this request
93
     * @param contentType
94
     *            the MIME content type of the body, including any character set
95
     **/
96
    public PostMethodWebRequest(String urlString, InputStream source, String contentType) {
97
        super(urlString, false);
1✔
98
        _body = new InputStreamMessageBody(source, contentType);
1✔
99
    }
1✔
100

101
    /**
102
     * Returns the HTTP method defined for this request.
103
     **/
104
    @Override
105
    public String getMethod() {
106
        return "POST";
1✔
107
    }
108

109
    /**
110
     * Returns the query string defined for this request.
111
     **/
112
    @Override
113
    public String getQueryString() {
114
        try {
115
            URLEncodedString encoder = new URLEncodedString();
1✔
116
            getParameterHolder().recordPredefinedParameters(encoder);
1✔
117
            return encoder.getString();
1✔
118
        } catch (IOException e) {
×
119
            throw new RuntimeException("Programming error: " + e); // should never happen
×
120
        }
121
    }
122

123
    /**
124
     * Returns true if selectFile may be called with this parameter.
125
     */
126
    @Override
127
    protected boolean maySelectFile(String parameterName) {
128
        return isMimeEncoded() && isFileParameter(parameterName);
1✔
129
    }
130

131
    // ----------------------------- MessageBodyWebRequest methods ---------------------------
132

133
    @Override
134
    protected MessageBody getMessageBody() {
135
        if (_body == null) {
1✔
136
            _body = MessageBody.createPostMethodMessageBody(isMimeEncoded(), getCharacterSet());
1✔
137
        }
138
        return _body;
1✔
139
    }
140

141
    // ----------------------------------- package members -----------------------------------
142

143
    /**
144
     * Constructs a web request for a form submitted by clicking a button.
145
     *
146
     * @param sourceForm
147
     *            the source form
148
     * @param button
149
     *            the button
150
     * @param x
151
     *            the x
152
     * @param y
153
     *            the y
154
     */
155
    PostMethodWebRequest(WebForm sourceForm, SubmitButton button, int x, int y) {
156
        this(sourceForm, sourceForm, button, x, y);
1✔
157
    }
1✔
158

159
    /**
160
     * Instantiates a new post method web request.
161
     *
162
     * @param sourceForm
163
     *            the source form
164
     * @param parameterHolder
165
     *            the parameter holder
166
     * @param button
167
     *            the button
168
     * @param x
169
     *            the x
170
     * @param y
171
     *            the y
172
     */
173
    PostMethodWebRequest(WebForm sourceForm, ParameterHolder parameterHolder, SubmitButton button, int x, int y) {
174
        super(sourceForm, parameterHolder, button, x, y);
1✔
175
    }
1✔
176

177
    /**
178
     * Constructs a web request for a form submitted via a script.
179
     *
180
     * @param sourceForm
181
     *            the source form
182
     */
183
    PostMethodWebRequest(WebForm sourceForm) {
184
        super(sourceForm);
1✔
185
    }
1✔
186

187
}
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