Java Code Examples for javax.servlet.http.HttpServletResponse#SC_UNSUPPORTED_MEDIA_TYPE

The following examples show how to use javax.servlet.http.HttpServletResponse#SC_UNSUPPORTED_MEDIA_TYPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MkcolMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Parse the request body
 * 
 * @exception WebDAVServerException
 */
protected void parseRequestBody() throws WebDAVServerException
{
    // There should not be a body with the MKCOL request

    if (m_request.getContentLength() > 0)
    {
        throw new WebDAVServerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
    }
}
 
Example 2
Source File: JaxRsWebApplicationExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider
public static Object[][] dataProviderForShouldHandleException() {
    return new Object[][] {
        { new NotFoundException(), testProjectApiErrors.getNotFoundApiError() },
        { new WebApplicationException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), testProjectApiErrors.getUnsupportedMediaTypeApiError() },
        { new WebApplicationException(HttpServletResponse.SC_METHOD_NOT_ALLOWED), testProjectApiErrors.getMethodNotAllowedApiError() },
        { new WebApplicationException(HttpServletResponse.SC_UNAUTHORIZED), testProjectApiErrors.getUnauthorizedApiError() },
        { new WebApplicationException(HttpServletResponse.SC_NOT_ACCEPTABLE), testProjectApiErrors.getNoAcceptableRepresentationApiError() },
        { mock(JsonProcessingException.class), testProjectApiErrors.getMalformedRequestApiError() }
    };
}
 
Example 3
Source File: Jersey1WebApplicationExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider
public static Object[][] dataProviderForShouldHandleException() {
    return new Object[][] {
        { new NotFoundException(), testProjectApiErrors.getNotFoundApiError() },
        { mock(ParamException.URIParamException.class), testProjectApiErrors.getNotFoundApiError() },
        { mock(ParamException.class), testProjectApiErrors.getMalformedRequestApiError() },
        { new WebApplicationException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), testProjectApiErrors.getUnsupportedMediaTypeApiError() },
        { new WebApplicationException(HttpServletResponse.SC_METHOD_NOT_ALLOWED), testProjectApiErrors.getMethodNotAllowedApiError() },
        { new WebApplicationException(HttpServletResponse.SC_UNAUTHORIZED), testProjectApiErrors.getUnauthorizedApiError() },
        { new WebApplicationException(HttpServletResponse.SC_NOT_ACCEPTABLE), testProjectApiErrors.getNoAcceptableRepresentationApiError() },
        { mock(JsonProcessingException.class), testProjectApiErrors.getMalformedRequestApiError() }
    };
}
 
Example 4
Source File: KatharsisInvokerV2.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
public void invoke(KatharsisInvokerContext invokerContext) throws KatharsisInvokerException {
	if (isAcceptableMediaType(invokerContext)) {
		try {
			dispatchRequest(invokerContext);
		} catch (Exception e) {
			throw new KatharsisInvokerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
		}
	} else {
		throw new KatharsisInvokerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
	}
}
 
Example 5
Source File: KatharsisInvoker.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
public void invoke(KatharsisInvokerContext invokerContext) throws KatharsisInvokerException {
    if (isAcceptableMediaType(invokerContext)) {
        try {
            dispatchRequest(invokerContext);
        } catch (Exception e) {
            throw new KatharsisInvokerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
        }
    } else {
        throw new KatharsisInvokerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
    }
}
 
Example 6
Source File: JaxRsWebApplicationExceptionHandlerListener.java    From backstopper with Apache License 2.0 4 votes vote down vote up
@Override
public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) {

    ApiExceptionHandlerListenerResult result;
    SortedApiErrorSet handledErrors = null;
    List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>();

    if (ex instanceof NotFoundException) {
        handledErrors = singletonSortedSetOf(projectApiErrors.getNotFoundApiError());
    }
    else if (ex instanceof WebApplicationException) {
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        WebApplicationException webex = (WebApplicationException) ex;
        Response webExResponse = webex.getResponse();
        if (webExResponse != null) {
            int webExStatusCode = webExResponse.getStatus();
            if (webExStatusCode == HttpServletResponse.SC_NOT_ACCEPTABLE) {
                handledErrors = singletonSortedSetOf(projectApiErrors.getNoAcceptableRepresentationApiError());
            }
            else if (webExStatusCode == HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE) {
                handledErrors = singletonSortedSetOf(projectApiErrors.getUnsupportedMediaTypeApiError());
            }
            else if (webExStatusCode == HttpServletResponse.SC_METHOD_NOT_ALLOWED) {
                handledErrors = singletonSortedSetOf(projectApiErrors.getMethodNotAllowedApiError());
            }
            else if (webExStatusCode == HttpServletResponse.SC_UNAUTHORIZED) {
                handledErrors = singletonSortedSetOf(projectApiErrors.getUnauthorizedApiError());
            }
        }
    }
    else if (ex instanceof JsonProcessingException) {
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError());
    }

    // Return an indication that we will handle this exception if handledErrors got set
    if (handledErrors != null) {
        result = ApiExceptionHandlerListenerResult.handleResponse(handledErrors, extraDetailsForLogging);
    }
    else {
        result = ApiExceptionHandlerListenerResult.ignoreResponse();
    }

    return result;
}
 
Example 7
Source File: Jersey1WebApplicationExceptionHandlerListener.java    From backstopper with Apache License 2.0 4 votes vote down vote up
@Override
public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) {

    ApiExceptionHandlerListenerResult result;
    SortedApiErrorSet handledErrors = null;
    List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>();

    if (ex instanceof NotFoundException) {
        handledErrors = singletonSortedSetOf(projectApiErrors.getNotFoundApiError());
    }
    else if (ex instanceof ParamException.URIParamException) {
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        // Returning a 404 is intentional here.
        //      The Jersey contract for URIParamException states it should map to a 404.
        handledErrors = singletonSortedSetOf(projectApiErrors.getNotFoundApiError());
    }
    else if (ex instanceof ParamException) {
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError());
    }
    else if (ex instanceof WebApplicationException) {
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        WebApplicationException webex = (WebApplicationException) ex;
        Response webExResponse = webex.getResponse();
        if (webExResponse != null) {
            int webExStatusCode = webExResponse.getStatus();
            if (webExStatusCode == HttpServletResponse.SC_NOT_ACCEPTABLE) {
                handledErrors = singletonSortedSetOf(projectApiErrors.getNoAcceptableRepresentationApiError());
            }
            else if (webExStatusCode == HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE) {
                handledErrors = singletonSortedSetOf(projectApiErrors.getUnsupportedMediaTypeApiError());
            }
            else if (webExStatusCode == HttpServletResponse.SC_METHOD_NOT_ALLOWED) {
                handledErrors = singletonSortedSetOf(projectApiErrors.getMethodNotAllowedApiError());
            }
            else if (webExStatusCode == HttpServletResponse.SC_UNAUTHORIZED) {
                handledErrors = singletonSortedSetOf(projectApiErrors.getUnauthorizedApiError());
            }
        }
    }
    else if (ex instanceof JsonProcessingException) {
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError());
    }

    // Return an indication that we will handle this exception if handledErrors got set
    if (handledErrors != null) {
        result = ApiExceptionHandlerListenerResult.handleResponse(handledErrors, extraDetailsForLogging);
    }
    else {
        result = ApiExceptionHandlerListenerResult.ignoreResponse();
    }

    return result;
}
 
Example 8
Source File: HttpException.java    From nomulus with Apache License 2.0 4 votes vote down vote up
public UnsupportedMediaTypeException(String message) {
  super(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, null);
}
 
Example 9
Source File: HttpException.java    From nomulus with Apache License 2.0 4 votes vote down vote up
public UnsupportedMediaTypeException(String message, Throwable cause) {
  super(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, cause);
}