private String[] extractParams(final HttpServletRequest request) { final String[] pathParams = StringUtils.split(request.getPathInfo(), '/'); if (pathParams.length < 2) { throw new AbstractApplinksServlet.BadRequestException(messageFactory.newLocalizedMessage( "Servlet URL should be of form /listEntityLinks/{entity-type}/{entity-key}")); } return pathParams; } }
private void parsePathParams(final String typeId) { if (!internalHostApplication.doesEntityExist(key, typeAccessor.loadEntityType(typeId).getClass())) { throw new AbstractApplinksServlet.BadRequestException(messageFactory.newLocalizedMessage( String.format("No entity exists with key %s of type %s", key, typeId))); } final EntityType entityType = typeAccessor.loadEntityType(typeId); assertPermission(entityType.getClass(), key); final EntityReference entityReference = internalHostApplication.toEntityReference(key, entityType.getClass()); type = typeId; typeLabel = messageFactory.newI18nMessage(entityType.getShortenedI18nKey()).toString(); name = entityReference.getName(); }
/** * Examines the request for a "method" parameter and invokes either {@link #doDelete(HttpServletRequest, HttpServletResponse)} or {@link * #doPut(HttpServletRequest, HttpServletResponse)} appropriately. * * @param req the HTTP request * @param resp the HTTP response * @throws BadRequestException Thrown if the "method" parameter is not provided. * @throws IllegalArgumentException Thrown if the method requested is not "DELETE or "PUT". * @throws IOException Thrown if rendering fails for the invoked method. */ @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { String method = getRequiredParameter(req, "method"); if ("PUT".equals(method)) { doPut(req, resp); } else if ("DELETE".equals(method)) { doDelete(req, resp); } else { throw new BadRequestException(messageFactory.newLocalizedMessage("Invalid method: " + method)); } }