throw new WebApplicationException(e.getCause(), Response.Status.BAD_REQUEST);
} catch (ConversionException e) { logger.error(Messages.getMessage("conversionError", this, value), e); throw new WebApplicationException(e.getCause(), Response.Status.BAD_REQUEST);
@Override public Object getValue(RuntimeContext runtimeContext) throws IOException { if (runtimeContext == null) { return null; } List<String> allValues = new ArrayList<String>(); List<PathSegment> segments = runtimeContext.getAttribute(SearchResult.class).getData().getMatchedURIs().get(0); // get the matrix parameter only from the last segment PathSegment segment = segments.get(segments.size() - 1); MultivaluedMap<String, String> matrixParameters = segment.getMatrixParameters(); List<String> values = matrixParameters.get(getName()); if (values != null) { allValues.addAll(values); } if (allValues.size() == 0 && hasDefaultValue()) { allValues.add(getDefaultValue()); } decodeValues(allValues); // we found matrix parameters with the specified name try { return getConvertor().convert(allValues); } catch (ConversionException e) { throw new WebApplicationException(e.getCause(), Response.Status.NOT_FOUND); } } }
@Override public Object getValue(RuntimeContext runtimeContext) throws IOException { if (runtimeContext == null) { return null; } // for all headers HttpHeaders httpHeaders = runtimeContext.getHttpHeaders(); List<String> values = httpHeaders.getRequestHeader(getName()); if (values == null) { values = new LinkedList<String>(); } if (values.size() == 0 && hasDefaultValue()) { values.add(getDefaultValue()); } try { return getConvertor().convert(values); } catch (ConversionException e) { logger.error(Messages.getMessage("conversionError", this, values), e); throw new WebApplicationException(e.getCause(), Response.Status.BAD_REQUEST); } } }
@Override public Object getValue(RuntimeContext runtimeContext) throws IOException { if (runtimeContext == null) { return null; } UriInfo uriInfo = runtimeContext.getUriInfo(); MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(false); List<String> values = queryParameters.get(getName()); if (values == null) { values = new LinkedList<String>(); } if (values.size() == 0 && hasDefaultValue()) { values.add(getDefaultValue()); } decodeValues(values); // we found query parameter values with the specified name try { return getConvertor().convert(values); } catch (ConversionException e) { throw new WebApplicationException(e.getCause(), Response.Status.NOT_FOUND); } }
RuntimeException createConversionException(String value, Class<?> targetClass, Throwable e) { if (e instanceof WebApplicationException) { return (RuntimeException)e; } return new ConversionException(Messages.getMessage("cannotConvertValueFromTo", value, targetClass), e); //$NON-NLS-1$ }