if (authInfo != null) {
HttpBasicAuthFilter besicAuth = new HttpBasicAuthFilter(authInfo.getUser(), authInfo.getPassword() == null ? "" : authInfo.getPassword());
target.configuration().register(besicAuth);
}
Metrix.event("doRestCommand() - about to prepare request builder");
Builder request = target.request(acceptedResponseTypes);
Metrix.event("doRestCommand() - about to add headers");
if (authToken != null) {
/*
* If this request is for metadata then we expect to reuse
* the auth token.
*/
request = request.header(
SecureAdmin.Util.ADMIN_ONE_TIME_AUTH_TOKEN_HEADER_NAME,
(isForMetadata ? AuthTokenManager.markTokenForReuse(authToken) : authToken));
}
if (commandModel != null && isCommandModelFromCache() && commandModel instanceof CachedCommandModel) {
request = request.header(COMMAND_MODEL_MATCH_HEADER,
((CachedCommandModel) commandModel).getETag());
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "CommandModel ETag: {0}", ((CachedCommandModel) commandModel).getETag());
}
}
//Headers
for (Header h : requestHeaders) {
request = request.header(h.getName(), h.getValue());
}
request = addAdditionalHeaders(request);
if (logger.isLoggable(Level.FINER)) {
request = request.header("X-Indent", "true");
}
//Make invocation
Invocation invoc = null;
Metrix.event("doRestCommand() - about to prepare invocation");
if ("POST".equals(method)) {
if (outboundPayload != null && outboundPayload.size() > 0) {
FormDataMultiPart mp = new FormDataMultiPart();
//Copy params there
for (Map.Entry<String, List<String>> entry : options.entrySet()) {
String key = entry.getKey();
for (String val : entry.getValue()) {
mp.field(key, val);
}
}
//Copy outbound there
outboundPayload.addToMultipart(mp, logger);
Entity<FormDataMultiPart> entity = Entity.<FormDataMultiPart>entity(mp, mp.getMediaType());
invoc = request.build(method, entity);
} else {
Entity<ParameterMap> entity = Entity.<ParameterMap>entity(options, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
invoc = request.build(method, entity);
}
} else {
invoc = request.build(method);
}
//todo: set timeout
// urlConnection.setReadTimeout(readTimeout);
// if (connectTimeout >= 0)
// urlConnection.setConnectTimeout(connectTimeout);