/** * Validate that an external content link header is appropriately formatted * @param link to be validated * @return Link object if the header is formatted correctly, else null * @throws ExternalMessageBodyException on error */ private Link parseLinkHeader(final String link) throws ExternalMessageBodyException { final Link realLink = Link.valueOf(link); try { final String handling = realLink.getParams().get(HANDLING); if (handling == null || !handling.matches("(?i)" + PROXY + "|" + COPY + "|" + REDIRECT)) { // error throw new ExternalMessageBodyException( "Link header formatted incorrectly: 'handling' parameter incorrect or missing"); } } catch (final Exception e) { throw new ExternalMessageBodyException("External content link header url is malformed"); } return realLink; }
@Override public Response toResponse(final ExternalMessageBodyException e) { debugException(this, e, LOGGER); final Link link = buildConstraintLink(e, context, uriInfo); final String msg = e.getMessage(); return status(BAD_REQUEST).entity(msg).links(link).type(TEXT_PLAIN_WITH_CHARSET).build(); } }
throw new ExternalMessageBodyException("External content is disallowed by the server"); throw new ExternalMessageBodyException("External content path was empty"); uri.toURL(); } catch (final Exception e) { throw new ExternalMessageBodyException("Path was not a valid URI: " + extPath); throw new ExternalMessageBodyException("Path was not absolute: " + extPath); throw new ExternalMessageBodyException("Path was not absolute: " + extPath); throw new ExternalMessageBodyException("Path did not provide an allowed scheme: " + extPath); throw new ExternalMessageBodyException("Path did not match any allowed external content paths: " + extPath); return; throw new ExternalMessageBodyException("Path did not match any allowed external content paths: " + extPath);
throw new ExternalMessageBodyException("More then one External Content Link header in request"); } else if (externalContentLinks.size() == 1) { final String link = externalContentLinks.get(0);