MCPcopy Create free account
hub / github.com/BaseXdb/basex / response

Method response

basex-core/src/main/java/org/basex/io/IOUrl.java:134–166  ·  view source on GitHub ↗

Returns an HTTP response. @return response @throws IOException I/O exception

()

Source from the content-addressed store, hash-verified

132 * @throws IOException I/O exception
133 */
134 public HttpResponse<InputStream> response() throws IOException {
135 final HttpClient client = client(true);
136
137 final HttpResponse<InputStream> response;
138 try {
139 final URI uri = new URI(pth);
140 final HttpRequest.Builder rb = HttpRequest.newBuilder(uri).timeout(Duration.ofMinutes(1));
141 rb.header(HTTPText.ACCEPT, MediaType.ALL_ALL.toString());
142 rb.header(HTTPText.USER_AGENT, Prop.NAME + '/' + Prop.VERSION.replace(' ', '-') +
143 " (Java " + Prop.JAVA_VERSION + "; " + Prop.OS + " " + Prop.OS_ARCH + ')');
144 new UserInfo(uri).basic(rb);
145 response = client.send(rb.build(), HttpResponse.BodyHandlers.ofInputStream());
146 } catch(final IOException ex) {
147 throw ex;
148 } catch(final Exception ex) {
149 /* possible exceptions, among others:
150 * - construct URI: invalid argument
151 * - build request: invalid URI scheme
152 * - send request: interrupted requests */
153 Util.debug(ex);
154 throw new IOException(ex.getMessage());
155 }
156
157 // create exception if response was not successful
158 final int status = response.statusCode();
159 if(status >= 400) {
160 final StringBuilder sb = new StringBuilder().append(status);
161 final String reason = reason(status);
162 if(!reason.isEmpty()) sb.append(": ").append(reason);
163 throw new IOException(sb.toString());
164 }
165 return response;
166 }
167
168 /**
169 * Returns a singleton HTTP client instance.

Callers 2

inputStreamMethod · 0.95
itemMethod · 0.45

Calls 14

clientMethod · 0.95
debugMethod · 0.95
reasonMethod · 0.95
timeoutMethod · 0.80
statusCodeMethod · 0.80
toStringMethod · 0.65
appendMethod · 0.65
headerMethod · 0.45
replaceMethod · 0.45
basicMethod · 0.45
sendMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected