use of javax.activation.MimeTypeParseException in project rest.li by linkedin.
the class MultiplexedCallback method notifyIndividualCallbacks.
private void notifyIndividualCallbacks(Response<MultiplexedResponseContent> muxResponse) {
IndividualResponseMap individualResponses = muxResponse.getEntity().getResponses();
for (IndividualResponseMap.Entry<String, IndividualResponse> individualResponseMapEntry : individualResponses.entrySet()) {
Integer id = Integer.valueOf(individualResponseMapEntry.getKey());
IndividualResponse individualResponse = individualResponseMapEntry.getValue();
Callback<RestResponse> callback = _callbacks.get(id);
RestResponse individualRestResponse;
try {
individualRestResponse = buildIndividualRestResponse(muxResponse, individualResponse);
} catch (MimeTypeParseException e) {
callback.onError(new RestLiDecodingException("Could not convert IndividualResponse to individual RestRestponse due to an invalid content type, id=" + id, e));
return;
} catch (IOException e) {
callback.onError(new RestLiDecodingException("Could not convert IndividualResponse to individual RestRestponse, id=" + id, e));
return;
}
if (RestStatus.isOK(individualResponse.getStatus())) {
callback.onSuccess(individualRestResponse);
} else {
RestException exception = new RestException(individualRestResponse, "Received error " + individualRestResponse.getStatus());
callback.onError(exception);
}
}
}
use of javax.activation.MimeTypeParseException in project rest.li by linkedin.
the class IndividualResponseConversionTask method run.
@Override
protected Promise<? extends IndividualResponseWithCookies> run(Context context) throws Throwable {
if (_restResponse.isFailed()) {
return Promises.value(toErrorIndividualResponse(_restResponse.getError()));
}
try {
RestResponse restResponse = _restResponse.get();
IndividualResponse response = toIndividualResponse(_restResponseId, restResponse);
return Promises.value(new IndividualResponseWithCookies(response, restResponse.getCookies()));
} catch (MimeTypeParseException e) {
return Promises.value(createInternalServerErrorResponse("Invalid content type for individual response: " + _restResponseId));
} catch (IOException e) {
return Promises.value(createInternalServerErrorResponse("Unable to set body for individual response: " + _restResponseId));
} catch (Exception e) {
return Promises.value(toErrorIndividualResponse(e));
}
}
use of javax.activation.MimeTypeParseException in project rest.li by linkedin.
the class RestResponseDecoder method createResponse.
private ResponseImpl<T> createResponse(Map<String, String> headers, int status, ByteString entity, List<String> cookies) throws RestLiDecodingException {
ResponseImpl<T> response = new ResponseImpl<T>(status, headers, CookieUtil.decodeSetCookies(cookies));
try {
DataMap dataMap = (entity.isEmpty()) ? null : DataMapConverter.bytesToDataMap(headers, entity);
response.setEntity(wrapResponse(dataMap, headers, ProtocolVersionUtil.extractProtocolVersion(response.getHeaders())));
return response;
} catch (MimeTypeParseException e) {
throw new RestLiDecodingException("Could not decode REST response", e);
} catch (IOException e) {
throw new RestLiDecodingException("Could not decode REST response", e);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
use of javax.activation.MimeTypeParseException in project ddf by codice.
the class BinaryContentImplTest method setUp.
@Before
public void setUp() {
content = new File("src/test/resources/data/i4ce.png");
MimetypesFileTypeMap mimeMapper = new MimetypesFileTypeMap();
try {
mimeType = new MimeType(mimeMapper.getContentType(content));
} catch (MimeTypeParseException e) {
LOGGER.error("Mime parser Failure", e);
new Failure(null, e);
}
}
use of javax.activation.MimeTypeParseException in project ddf by codice.
the class BinaryContentImplTest method setUp.
@Before
public void setUp() {
content = new File("src/test/resources/data/i4ce.png");
MimetypesFileTypeMap mimeMapper = new MimetypesFileTypeMap();
try {
mimeType = new MimeType(mimeMapper.getContentType(content));
} catch (MimeTypeParseException e) {
LOGGER.error("Mime parser Failure", e);
new Failure(null, e);
}
}
Aggregations