private T convert(String value) { try { return paramConverter.fromString(value); } catch (WebApplicationException wae) { throw wae; } catch (IllegalArgumentException iae) { throw iae; } catch (Exception ex) { throw new ExtractorException(ex); } }
@Override public Object apply(ContainerRequest containerRequest) { // TODO: cache? MultivaluedMap<String, String> cookies = new MultivaluedStringMap(); for (Map.Entry<String, Cookie> e : containerRequest.getCookies().entrySet()) { cookies.putSingle(e.getKey(), e.getValue().getValue()); } try { return extractor.extract(cookies); } catch (ExtractorException ex) { throw new ParamException.CookieParamException(ex.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
@Override public T fromString(String value) { if (value == null || value.isEmpty()) { return null; // throw new IllegalStateException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } if (value.length() == 1) { return rawType.cast(value.charAt(0)); } throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(value)); }
@Override public Object apply(ContainerRequest containerRequest) { // TODO: cache? MultivaluedMap<String, String> cookies = new MultivaluedStringMap(); for (Map.Entry<String, Cookie> e : containerRequest.getCookies().entrySet()) { cookies.putSingle(e.getKey(), e.getValue().getValue()); } try { return extractor.extract(cookies); } catch (ExtractorException ex) { throw new ParamException.CookieParamException(ex.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
@Override public T fromString(String value) { if (value == null || value.isEmpty()) { return null; // throw new IllegalStateException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } if (value.length() == 1) { return rawType.cast(value.charAt(0)); } throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(value)); }
@Override public Object apply(ContainerRequest containerRequest) { List<PathSegment> l = containerRequest.getUriInfo().getPathSegments(decode); PathSegment p = l.get(l.size() - 1); try { return extractor.extract(p.getMatrixParameters()); } catch (ExtractorException e) { throw new ParamException.MatrixParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
private T convert(String value) { try { return paramConverter.fromString(value); } catch (WebApplicationException wae) { throw wae; } catch (IllegalArgumentException iae) { throw iae; } catch (Exception ex) { throw new ExtractorException(ex); } }
@Override public Object apply(ContainerRequest containerRequest) { List<PathSegment> l = containerRequest.getUriInfo().getPathSegments(decode); PathSegment p = l.get(l.size() - 1); try { return extractor.extract(p.getMatrixParameters()); } catch (ExtractorException e) { throw new ParamException.MatrixParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
private Object getValue(String v) { try { return valueOf.invoke(null, v); } catch (InvocationTargetException ex) { Throwable target = ex.getTargetException(); if (target instanceof WebApplicationException) { throw (WebApplicationException) target; } else { throw new ExtractorException(target); } } catch (Exception ex) { throw new ProcessingException(ex); } }
@Override public Object apply(ContainerRequest containerRequest) { try { return extractor.extract(containerRequest.getHeaders()); } catch (ExtractorException e) { throw new ParamException.HeaderParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
private Object getValue(String v) { try { return valueOf.invoke(null, v); } catch (InvocationTargetException ex) { Throwable target = ex.getTargetException(); if (target instanceof WebApplicationException) { throw (WebApplicationException) target; } else { throw new ExtractorException(target); } } catch (Exception ex) { throw new ProcessingException(ex); } }
@Override public Object apply(ContainerRequest containerRequest) { try { return extractor.extract(containerRequest.getHeaders()); } catch (ExtractorException e) { throw new ParamException.HeaderParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
@Override public Object extract(MultivaluedMap<String, String> parameters) { String v = parameters.getFirst(parameter); if (v != null && !v.trim().isEmpty()) { if (v.length() == 1) { return v.charAt(0); } else { throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(v)); } } else if (defaultStringValue != null && !defaultStringValue.trim().isEmpty()) { if (defaultStringValue.length() == 1) { return defaultStringValue.charAt(0); } else { throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(defaultStringValue)); } } return defaultPrimitiveTypeValue; } }
@Override public Object apply(ContainerRequest containerRequest) { try { return extractor.extract(containerRequest.getUriInfo().getQueryParameters(decode)); } catch (ExtractorException e) { throw new ParamException.QueryParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
@Override public T fromString(final String value) { if (value == null) { throw new IllegalArgumentException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } try { return rawType.cast(HttpDateFormat.readDate(value)); } catch (final ParseException ex) { throw new ExtractorException(ex); } }
@Override public Object apply(ContainerRequest containerRequest) { try { return extractor.extract(containerRequest.getUriInfo().getQueryParameters(decode)); } catch (ExtractorException e) { throw new ParamException.QueryParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
@Override public Object extract(MultivaluedMap<String, String> parameters) { String v = parameters.getFirst(parameter); if (v != null && !v.trim().isEmpty()) { if (v.length() == 1) { return v.charAt(0); } else { throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(v)); } } else if (defaultStringValue != null && !defaultStringValue.trim().isEmpty()) { if (defaultStringValue.length() == 1) { return defaultStringValue.charAt(0); } else { throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(defaultStringValue)); } } return defaultPrimitiveTypeValue; } }
@Override public Object apply(ContainerRequest request) { try { return extractor.extract(request.getUriInfo().getPathParameters(decode)); } catch (ExtractorException e) { throw new PathParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }
@Override public T fromString(final String value) { if (value == null) { throw new IllegalArgumentException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } try { return rawType.cast(HttpDateFormat.readDate(value)); } catch (final ParseException ex) { throw new ExtractorException(ex); } }
@Override public Object apply(ContainerRequest request) { try { return extractor.extract(request.getUriInfo().getPathParameters(decode)); } catch (ExtractorException e) { throw new PathParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } } }