Search in sources :

Example 1 with MimeTypeParseException

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);
        }
    }
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) RestResponse(com.linkedin.r2.message.rest.RestResponse) RestException(com.linkedin.r2.message.rest.RestException) RestLiDecodingException(com.linkedin.restli.client.RestLiDecodingException) ByteString(com.linkedin.data.ByteString) IOException(java.io.IOException) IndividualResponseMap(com.linkedin.restli.common.multiplexer.IndividualResponseMap) IndividualResponse(com.linkedin.restli.common.multiplexer.IndividualResponse)

Example 2 with MimeTypeParseException

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));
    }
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) RestResponse(com.linkedin.r2.message.rest.RestResponse) IOException(java.io.IOException) IndividualResponse(com.linkedin.restli.common.multiplexer.IndividualResponse) MimeTypeParseException(javax.activation.MimeTypeParseException) IOException(java.io.IOException)

Example 3 with MimeTypeParseException

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);
    }
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) RestLiDecodingException(com.linkedin.restli.client.RestLiDecodingException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataMap(com.linkedin.data.DataMap)

Example 4 with MimeTypeParseException

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);
    }
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) MimeTypeParseException(javax.activation.MimeTypeParseException) File(java.io.File) MimeType(javax.activation.MimeType) Failure(org.junit.runner.notification.Failure) Before(org.junit.Before)

Example 5 with MimeTypeParseException

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);
    }
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) MimeTypeParseException(javax.activation.MimeTypeParseException) File(java.io.File) MimeType(javax.activation.MimeType) Failure(org.junit.runner.notification.Failure) Before(org.junit.Before)

Aggregations

MimeTypeParseException (javax.activation.MimeTypeParseException)17 MimeType (javax.activation.MimeType)14 IOException (java.io.IOException)8 File (java.io.File)4 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)3 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)3 Before (org.junit.Before)3 Failure (org.junit.runner.notification.Failure)3 RestResponse (com.linkedin.r2.message.rest.RestResponse)2 RestLiDecodingException (com.linkedin.restli.client.RestLiDecodingException)2 IndividualResponse (com.linkedin.restli.common.multiplexer.IndividualResponse)2 BinaryContent (ddf.catalog.data.BinaryContent)2 MetacardCreationException (ddf.catalog.data.MetacardCreationException)2 ResourceResponse (ddf.catalog.operation.ResourceResponse)2 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)2 Resource (ddf.catalog.resource.Resource)2 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)2 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)2 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 InputStream (java.io.InputStream)2