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);
//Invoke
Metrix.event("doRestCommand() - about to invoke");
Response response;
try {
response = invoc.invoke();
} catch (ClientException ex) {
//Rethrow original execaption (not Throwable) for future processing
if (ex.getCause() != null && ex.getCause() instanceof Exception) {
throw (Exception) ex.getCause();
} else {