Package ca.uhn.fhir.rest.server.exceptions

Examples of ca.uhn.fhir.rest.server.exceptions.InvalidRequestException


      if (tok.hasMoreTokens()) {
        String nextString = tok.nextToken();
        if (nextString.startsWith("_")) {
          if (operation != null) {
            throw new InvalidRequestException("URL Path contains two operations (part beginning with _): " + requestPath);
          }
          operation = nextString;
        }
      }
View Full Code Here


      String[] countValues = theParameterValues.remove(Constants.PARAM_COUNT);
      if (countValues.length > 0 && StringUtils.isNotBlank(countValues[0])) {
        try {
          args[myCountParamIndex] = new IntegerDt(countValues[0]);
        } catch (DataFormatException e) {
          throw new InvalidRequestException("Invalid _count parameter value: " + countValues[0]);
        }
      }
    }
    if (mySinceParamIndex != null) {
      String[] sinceValues = theParameterValues.remove(Constants.PARAM_SINCE);
      if (sinceValues.length > 0 && StringUtils.isNotBlank(sinceValues[0])) {
        try {
          args[mySinceParamIndex] = new InstantDt(sinceValues[0]);
        } catch (DataFormatException e) {
          throw new InvalidRequestException("Invalid _since parameter value: " + sinceValues[0]);
        }
      }
    }

    if (myIdParamIndex!=null) {
View Full Code Here

          ourLog.debug("Ignoring response content of type: {}", theResponseMimeType);
        }
      }
      return retVal;
    case Constants.STATUS_HTTP_400_BAD_REQUEST:
      throw new InvalidRequestException("Server responded with: " + IOUtils.toString(theResponseReader));
    case Constants.STATUS_HTTP_404_NOT_FOUND:
      throw new ResourceNotFoundException("Server responded with: " + IOUtils.toString(theResponseReader));
    case Constants.STATUS_HTTP_405_METHOD_NOT_ALLOWED:
      throw new MethodNotAllowedException("Server responded with: " + IOUtils.toString(theResponseReader));
    case Constants.STATUS_HTTP_409_CONFLICT:
View Full Code Here

    String locationHeader = theRequest.getServletRequest().getHeader(Constants.HEADER_CONTENT_LOCATION);
    if (isNotBlank(locationHeader)) {
      MethodOutcome mo = new MethodOutcome();
      parseContentLocation(mo, locationHeader);
      if (mo.getId() == null || mo.getId().isEmpty()) {
        throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName()+ ": " + locationHeader);
      }
      if (mo.getVersionId() != null && mo.getVersionId().isEmpty() == false) {
        theRequest.setVersion(mo.getVersionId());
      }
    }
View Full Code Here

  protected void addParametersForServerRequest(Request theRequest, Object[] theParams) {
    String url = theRequest.getCompleteUrl();
    int resNameIdx = url.indexOf(getResourceName());
    String id = url.substring(resNameIdx+getResourceName().length() + 1);
    if (id.contains("/")) {
      throw new InvalidRequestException("Invalid request path for a DELETE operation: "+theRequest.getCompleteUrl());
    }
   
    theParams[myIdParameterIndex] = new IdDt(id);
  }
View Full Code Here

  public Object parse(List<QualifiedParamList> theParams) throws InternalErrorException, InvalidRequestException {
    if (theParams.size() == 0 || theParams.get(0).size() == 0) {
      return "";
    }
    if (theParams.size() > 1 || theParams.get(0).size() > 1) {
      throw new InvalidRequestException("Multiple values detected");
    }

    return theParams.get(0).get(0);
  }
View Full Code Here

        if (StringUtils.isNotBlank(sinceParams[0])) {
          try {
            InstantDt since = new InstantDt(sinceParams[0]);
            return ParameterUtil.fromInstant(myType, since);
          } catch (DataFormatException e) {
            throw new InvalidRequestException("Invalid " + Constants.PARAM_SINCE + " value: " + sinceParams[0]);
          }
        }
      }
    }
    return ParameterUtil.fromInstant(myType, null);
View Full Code Here

      } else if (resourceName == null) {
        resourceBinding = myNullResourceBinding;
      } else {
        resourceBinding = myResourceNameToProvider.get(resourceName);
        if (resourceBinding == null) {
          throw new InvalidRequestException("Unknown resource type '" + resourceName + "' - Server knows how to handle: " + myResourceNameToProvider.keySet());
        }
      }

      if (tok.hasMoreTokens()) {
        String nextString = tok.nextToken();
        if (nextString.startsWith("_")) {
          operation = nextString;
        } else {
          id = new IdDt(resourceName, nextString);
        }
      }

      if (tok.hasMoreTokens()) {
        String nextString = tok.nextToken();
        if (nextString.equals(Constants.PARAM_HISTORY)) {
          if (tok.hasMoreTokens()) {
            String versionString = tok.nextToken();
            if (id == null) {
              throw new InvalidRequestException("Don't know how to handle request path: " + requestPath);
            }
            id = new IdDt(resourceName + "/" + id.getIdPart() + "/_history/" + versionString);
            versionId = id;
          } else {
            operation = Constants.PARAM_HISTORY;
          }
        } else if (nextString.startsWith("_")) {
          if (operation != null) {
            throw new InvalidRequestException("URL Path contains two operations (part beginning with _): " + requestPath);
          }
          operation = nextString;
        }
      }

      // Secondary is for things like ..../_tags/_delete
      String secondaryOperation = null;

      while (tok.hasMoreTokens()) {
        String nextString = tok.nextToken();
        if (operation == null) {
          operation = nextString;
        } else if (secondaryOperation == null) {
          secondaryOperation = nextString;
        } else {
          throw new InvalidRequestException("URL path has unexpected token '" + nextString + "' at the end: " + requestPath);
        }
      }

      if (theRequestType == RequestType.PUT && versionId == null) {
        String contentLocation = theRequest.getHeader("Content-Location");
        if (contentLocation != null) {
          versionId = new IdDt(contentLocation);
        }
      }

      // TODO: look for more tokens for version, compartments, etc...

      String acceptEncoding = theRequest.getHeader(Constants.HEADER_ACCEPT_ENCODING);
      boolean respondGzip = false;
      if (acceptEncoding != null) {
        String[] parts = acceptEncoding.trim().split("\\s*,\\s*");
        for (String string : parts) {
          if (string.equals("gzip")) {
            respondGzip = true;
          }
        }
      }

      Request r = new Request();
      r.setResourceName(resourceName);
      r.setId(id);
      r.setVersion(versionId);
      r.setOperation(operation);
      r.setSecondaryOperation(secondaryOperation);
      r.setParameters(params);
      r.setRequestType(theRequestType);
      r.setFhirServerBase(fhirServerBase);
      r.setCompleteUrl(completeUrl);
      r.setServletRequest(theRequest);
      r.setServletResponse(theResponse);
      r.setRespondGzip(respondGzip);

      String pagingAction = theRequest.getParameter(Constants.PARAM_PAGINGACTION);
      if (getPagingProvider() != null && isNotBlank(pagingAction)) {
        handlePagingRequest(r, theResponse, pagingAction);
        return;
      }

      if (resourceMethod == null && resourceBinding != null) {
        resourceMethod = resourceBinding.getMethod(r);
      }
      if (null == resourceMethod) {
        StringBuilder b = new StringBuilder();
        b.append("No resource method available for ");
        b.append(theRequestType.name());
        b.append(" operation[");
        b.append(requestPath);
        b.append("]");
        b.append(" with parameters ");
        b.append(params.keySet());
        throw new InvalidRequestException(b.toString());
      }

      resourceMethod.invokeServer(this, r, theResponse);

    } catch (AuthenticationException e) {
View Full Code Here

    for (List<String> paramList : theParameters) {
      if (paramList.size() == 0) {
        continue;
      }
      if (paramList.size() > 1) {
        throw new InvalidRequestException("DateRange parameter does not suppport OR queries");
      }
      String param = paramList.get(0);
      QualifiedDateParam parsed = new QualifiedDateParam();
      parsed.setValueAsQueryToken(null, param);
      addParam(parsed);
View Full Code Here

  }

  private void addParam(QualifiedDateParam theParsed) throws InvalidRequestException {
    if (theParsed.getComparator() == null) {
      if (myLowerBound != null || myUpperBound != null) {
        throw new InvalidRequestException("Can not have multiple date range parameters for the same param without a qualifier");
      }

      myLowerBound = theParsed;
      myUpperBound = theParsed;
      // TODO: in this case, should set lower and upper to exact moments
      // using specified precision
    } else {

      switch (theParsed.getComparator()) {
      case GREATERTHAN:
      case GREATERTHAN_OR_EQUALS:
        if (myLowerBound != null) {
          throw new InvalidRequestException("Can not have multiple date range parameters for the same param that specify a lower bound");
        }
        myLowerBound = theParsed;
        break;
      case LESSTHAN:
      case LESSTHAN_OR_EQUALS:
        if (myUpperBound != null) {
          throw new InvalidRequestException("Can not have multiple date range parameters for the same param that specify an upper bound");
        }
        myUpperBound = theParsed;
        break;
      default:
        throw new InvalidRequestException("Unknown comparator: " + theParsed.getComparator());
      }

    }
  }
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.rest.server.exceptions.InvalidRequestException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.