当前位置: 首页>>代码示例>>Java>>正文


Java ParamException类代码示例

本文整理汇总了Java中com.sun.jersey.api.ParamException的典型用法代码示例。如果您正苦于以下问题:Java ParamException类的具体用法?Java ParamException怎么用?Java ParamException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ParamException类属于com.sun.jersey.api包,在下文中一共展示了ParamException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dataProviderForShouldHandleException

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
@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() }
    };
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:14,代码来源:Jersey1WebApplicationExceptionHandlerListenerTest.java

示例2: toResponse

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(ParamException exception) {
	ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
	builder.header(ERROR_HEADER, exception.getMessage());
	return builder.build();

}
 
开发者ID:netxilia,项目名称:netxilia,代码行数:8,代码来源:ParamConversionExceptionMapper.java

示例3: toResponse

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(Exception e) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GOT EXCEPITION", e);
  }

  //clear content type
  response.setContentType(null);

  //Convert exception
  if (e instanceof ParamException) {
    final ParamException paramexception = (ParamException)e;
    e = new IllegalArgumentException("Invalid value for webhdfs parameter \""
        + paramexception.getParameterName() + "\": "
        + e.getCause().getMessage(), e);
  }
  if (e instanceof ContainerException) {
    e = toCause(e);
  }
  if (e instanceof RemoteException) {
    e = ((RemoteException)e).unwrapRemoteException();
  }

  if (e instanceof SecurityException) {
    e = toCause(e);
  }
  
  //Map response status
  final Response.Status s;
  if (e instanceof SecurityException) {
    s = Response.Status.FORBIDDEN;
  } else if (e instanceof AuthorizationException) {
    s = Response.Status.FORBIDDEN;
  } else if (e instanceof FileNotFoundException) {
    s = Response.Status.NOT_FOUND;
  } else if (e instanceof IOException) {
    s = Response.Status.FORBIDDEN;
  } else if (e instanceof UnsupportedOperationException) {
    s = Response.Status.BAD_REQUEST;
  } else if (e instanceof IllegalArgumentException) {
    s = Response.Status.BAD_REQUEST;
  } else {
    LOG.warn("INTERNAL_SERVER_ERROR", e);
    s = Response.Status.INTERNAL_SERVER_ERROR;
  }
 
  final String js = JsonUtil.toJsonString(e);
  return Response.status(s).type(MediaType.APPLICATION_JSON).entity(js).build();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:50,代码来源:ExceptionHandler.java

示例4: exceptionCaught

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
static DefaultFullHttpResponse exceptionCaught(Throwable cause) {
  Exception e = cause instanceof Exception ? (Exception) cause : new Exception(cause);

  if (LOG.isTraceEnabled()) {
    LOG.trace("GOT EXCEPITION", e);
  }

  //Convert exception
  if (e instanceof ParamException) {
    final ParamException paramexception = (ParamException)e;
    e = new IllegalArgumentException("Invalid value for webhdfs parameter \""
                                       + paramexception.getParameterName() + "\": "
                                       + e.getCause().getMessage(), e);
  } else if (e instanceof ContainerException || e instanceof SecurityException) {
    e = toCause(e);
  } else if (e instanceof RemoteException) {
    e = ((RemoteException)e).unwrapRemoteException();
  }

  //Map response status
  final HttpResponseStatus s;
  if (e instanceof SecurityException) {
    s = FORBIDDEN;
  } else if (e instanceof AuthorizationException) {
    s = FORBIDDEN;
  } else if (e instanceof FileNotFoundException) {
    s = NOT_FOUND;
  } else if (e instanceof IOException) {
    s = FORBIDDEN;
  } else if (e instanceof UnsupportedOperationException) {
    s = BAD_REQUEST;
  } else if (e instanceof IllegalArgumentException) {
    s = BAD_REQUEST;
  } else {
    LOG.warn("INTERNAL_SERVER_ERROR", e);
    s = INTERNAL_SERVER_ERROR;
  }

  final byte[] js = JsonUtil.toJsonString(e).getBytes(Charsets.UTF_8);
  DefaultFullHttpResponse resp =
    new DefaultFullHttpResponse(HTTP_1_1, s, Unpooled.wrappedBuffer(js));

  resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8);
  resp.headers().set(CONTENT_LENGTH, js.length);
  return resp;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:47,代码来源:ExceptionHandler.java

示例5: exceptionCaught

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
static DefaultFullHttpResponse exceptionCaught(Throwable cause) {
  Exception e = cause instanceof Exception ? (Exception) cause : new Exception(cause);

  if (LOG.isTraceEnabled()) {
    LOG.trace("GOT EXCEPTION", e);
  }

  //Convert exception
  if (e instanceof ParamException) {
    final ParamException paramexception = (ParamException)e;
    e = new IllegalArgumentException("Invalid value for webhdfs parameter \""
                                       + paramexception.getParameterName() + "\": "
                                       + e.getCause().getMessage(), e);
  } else if (e instanceof ContainerException || e instanceof SecurityException) {
    e = toCause(e);
  } else if (e instanceof RemoteException) {
    e = ((RemoteException)e).unwrapRemoteException();
  }

  //Map response status
  final HttpResponseStatus s;
  if (e instanceof SecurityException) {
    s = FORBIDDEN;
  } else if (e instanceof AuthorizationException) {
    s = FORBIDDEN;
  } else if (e instanceof FileNotFoundException) {
    s = NOT_FOUND;
  } else if (e instanceof IOException) {
    s = FORBIDDEN;
  } else if (e instanceof UnsupportedOperationException) {
    s = BAD_REQUEST;
  } else if (e instanceof IllegalArgumentException) {
    s = BAD_REQUEST;
  } else {
    LOG.warn("INTERNAL_SERVER_ERROR", e);
    s = INTERNAL_SERVER_ERROR;
  }

  final byte[] js = JsonUtil.toJsonString(e).getBytes(Charsets.UTF_8);
  DefaultFullHttpResponse resp =
    new DefaultFullHttpResponse(HTTP_1_1, s, Unpooled.wrappedBuffer(js));

  resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8);
  resp.headers().set(CONTENT_LENGTH, js.length);
  return resp;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:47,代码来源:ExceptionHandler.java

示例6: shouldHandleException

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
@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;
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:56,代码来源:Jersey1WebApplicationExceptionHandlerListener.java

示例7: toResponse

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(Exception e) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GOT EXCEPITION", e);
  }

  //clear content type
  response.setContentType(null);

  //Convert exception
  if (e instanceof ParamException) {
    final ParamException paramexception = (ParamException)e;
    e = new IllegalArgumentException("Invalid value for webhdfs parameter \""
        + paramexception.getParameterName() + "\": "
        + e.getCause().getMessage(), e);
  }
  if (e instanceof ContainerException) {
    e = toCause(e);
  }
  if (e instanceof RemoteException) {
    e = ((RemoteException)e).unwrapRemoteException();
  }

  //Map response status
  final Response.Status s;
  if (e instanceof SecurityException) {
    s = Response.Status.UNAUTHORIZED;
  } else if (e instanceof AuthorizationException) {
    s = Response.Status.UNAUTHORIZED;
  } else if (e instanceof FileNotFoundException) {
    s = Response.Status.NOT_FOUND;
  } else if (e instanceof IOException) {
    s = Response.Status.FORBIDDEN;
  } else if (e instanceof UnsupportedOperationException) {
    s = Response.Status.BAD_REQUEST;
  } else if (e instanceof IllegalArgumentException) {
    s = Response.Status.BAD_REQUEST;
  } else {
    LOG.warn("INTERNAL_SERVER_ERROR", e);
    s = Response.Status.INTERNAL_SERVER_ERROR;
  }
 
  final String js = JsonUtil.toJsonString(e);
  return Response.status(s).type(MediaType.APPLICATION_JSON).entity(js).build();
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:46,代码来源:ExceptionHandler.java

示例8: toResponse

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(Exception e) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GOT EXCEPITION", e);
  }

  //clear content type
  response.setContentType(null);

  //Convert exception
  if (e instanceof ParamException) {
    final ParamException paramexception = (ParamException) e;
    e = new IllegalArgumentException(
        "Invalid value for webhdfs parameter \"" +
            paramexception.getParameterName() + "\": " +
            e.getCause().getMessage(), e);
  }
  if (e instanceof ContainerException) {
    e = toCause(e);
  }
  if (e instanceof RemoteException) {
    e = ((RemoteException) e).unwrapRemoteException();
  }

  //Map response status
  final Response.Status s;
  if (e instanceof SecurityException) {
    s = Response.Status.UNAUTHORIZED;
  } else if (e instanceof AuthorizationException) {
    s = Response.Status.UNAUTHORIZED;
  } else if (e instanceof FileNotFoundException) {
    s = Response.Status.NOT_FOUND;
  } else if (e instanceof IOException) {
    s = Response.Status.FORBIDDEN;
  } else if (e instanceof UnsupportedOperationException) {
    s = Response.Status.BAD_REQUEST;
  } else if (e instanceof IllegalArgumentException) {
    s = Response.Status.BAD_REQUEST;
  } else {
    LOG.warn("INTERNAL_SERVER_ERROR", e);
    s = Response.Status.INTERNAL_SERVER_ERROR;
  }

  final String js = JsonUtil.toJsonString(e);
  return Response.status(s).type(MediaType.APPLICATION_JSON).entity(js)
      .build();
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:48,代码来源:ExceptionHandler.java

示例9: toResponse

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(Exception e) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GOT EXCEPITION", e);
  }

  //clear content type
  response.setContentType(null);

  //Convert exception
  if (e instanceof ParamException) {
    final ParamException paramexception = (ParamException)e;
    e = new IllegalArgumentException("Invalid value for webhdfs parameter \""
        + paramexception.getParameterName() + "\": "
        + e.getCause().getMessage(), e);
  }
  if (e instanceof ContainerException) {
    e = toCause(e);
  }
  if (e instanceof RemoteException) {
    e = ((RemoteException)e).unwrapRemoteException();
  }

  //Map response status
  final Response.Status s;
  if (e instanceof SecurityException) {
    s = Response.Status.FORBIDDEN;
  } else if (e instanceof AuthorizationException) {
    s = Response.Status.FORBIDDEN;
  } else if (e instanceof FileNotFoundException) {
    s = Response.Status.NOT_FOUND;
  } else if (e instanceof IOException) {
    s = Response.Status.FORBIDDEN;
  } else if (e instanceof UnsupportedOperationException) {
    s = Response.Status.BAD_REQUEST;
  } else if (e instanceof IllegalArgumentException) {
    s = Response.Status.BAD_REQUEST;
  } else {
    LOG.warn("INTERNAL_SERVER_ERROR", e);
    s = Response.Status.INTERNAL_SERVER_ERROR;
  }
 
  final String js = JsonUtil.toJsonString(e);
  return Response.status(s).type(MediaType.APPLICATION_JSON).entity(js).build();
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:46,代码来源:ExceptionHandler.java

示例10: toResponse

import com.sun.jersey.api.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(ParamException exception) {
	return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN)
			.entity(exception.getParameterName() + " has an invalid format").build();
}
 
开发者ID:52North,项目名称:GEO-label-java,代码行数:6,代码来源:ExceptionMappers.java


注:本文中的com.sun.jersey.api.ParamException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。