import javax.ws.rs.client.ClientBuilder;
/**
- * An utility that represents an HTTP client that allows to make
- * HTTP requests.
+ * An utility that represents an HTTP client that allows to make HTTP requests.
*/
-//Suppressed so UT's can mock it using Mockito.
-@SuppressWarnings("checkstyle:FinalClass")
+// Non-final for mocking
public class SimpleHttpClient {
-
private final Client client;
- private SimpleHttpClient(final Client client) {
+ SimpleHttpClient(final Client client) {
this.client = client;
}
* @param <T> the return type of the request.
* @return the request builder.
*/
- public <T> SimpleHttpRequest.Builder<T> requestBuilder(Class<T> outputType) {
+ public <T> SimpleHttpRequest.Builder<T> requestBuilder(final Class<T> outputType) {
return new SimpleHttpRequest.Builder<>(client, outputType);
}
+ // Non-final for mocking
public static class Builder {
-
+ private final Set<Class<?>> providers = new HashSet<>();
private SSLContext sslContext;
private HostnameVerifier hostnameVerifier;
- private final Set<Class<?>> providers = new HashSet<>();
- private Builder() {
+ Builder() {
}
* @return self, the client builder.
*/
public Builder sslContext(final SSLContext context) {
- this.sslContext = context;
+ sslContext = context;
return this;
}
* @return self, the client builder.
*/
public Builder hostnameVerifier(final HostnameVerifier verifier) {
- this.hostnameVerifier = verifier;
+ hostnameVerifier = verifier;
return this;
}
return new SimpleHttpClient(clientBuilder.build());
}
-
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.aaa.shiro.realm.util.http;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
/**
* Basic utility to do an HTTP request. See {@link
* SimpleHttpClient#requestBuilder(Class)} on how to obtain a request builder.
*
* @param <T> the return type of the request.
*/
-// Suppressed so UT's can mock it using Mockito.
-@SuppressWarnings("checkstyle:FinalClass")
+// Non-final for mocking
public class SimpleHttpRequest<T> {
+ private final Map<String, String> queryParams = new HashMap<>();
private final Client client;
private final Class<T> outputType;
private URI uri;
private String method;
private MediaType mediaType;
private Object entity;
- private final Map<String, String> queryParams = new HashMap<>();
- private SimpleHttpRequest(final Client client, final Class<T> outputType) {
+ SimpleHttpRequest(final Client client, final Class<T> outputType) {
this.client = client;
this.outputType = outputType;
}
*
* @return the builder.
*/
- static <T> Builder<T> builder(Client client, Class<T> outputType) {
+ static <T> Builder<T> builder(final Client client, final Class<T> outputType) {
return new Builder<>(client, outputType);
}
+ // Non-final for mocking
public static class Builder<T> {
private final SimpleHttpRequest<T> request;
- Builder(Client client, Class<T> outputType) {
+ Builder(final Client client, final Class<T> outputType) {
request = new SimpleHttpRequest<>(client, outputType);
}
* @param uri the URI.
* @return self, the request builder.
*/
- public Builder<T> uri(URI uri) {
+ public Builder<T> uri(final URI uri) {
request.uri = uri;
return this;
}
* @param path the path.
* @return self, the request builder.
*/
- public Builder<T> path(String path) {
+ public Builder<T> path(final String path) {
request.path = path;
return this;
}
* @param method the method.
* @return self, the request builder.
*/
- public Builder<T> method(String method) {
+ public Builder<T> method(final String method) {
request.method = method;
return this;
}
* @param mediaType the media type.
* @return self, the request builder.
*/
- public Builder<T> mediaType(MediaType mediaType) {
+ public Builder<T> mediaType(final MediaType mediaType) {
request.mediaType = mediaType;
return this;
}
* @param input the input payload.
* @return self, the request builder.
*/
- public Builder<T> entity(Object input) {
+ public Builder<T> entity(final Object input) {
request.entity = input;
return this;
}
* @param theParamValue the parameter value
* @return self, the request builder
*/
- public Builder<T> queryParam(String theQueryParam, String theParamValue) {
+ public Builder<T> queryParam(final String theQueryParam, final String theParamValue) {
request.queryParams.put(theQueryParam, theParamValue);
return this;
}