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

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


    for (List<String> nextParamList : theString) {
      if (nextParamList.isEmpty()) {
        continue;
      }
      if (nextParamList.size() > 1) {
        throw new InvalidRequestException("'OR' query parameters (values containing ',') are not supported in _include parameters");
      }

      String value = nextParamList.get(0);
      if (myAllow != null) {
        if (!myAllow.contains(value)) {
          if (!myAllow.contains("*")) {
            throw new InvalidRequestException("Invalid _include parameter value: '" + value + "'. Valid values are: " + new TreeSet<String>(myAllow));
          }
        }
      }
      if (retValCollection == null) {
        if (mySpecType == String.class) {
View Full Code Here


    }
   
    if (idDt.hasResourceType()==false) {
      idDt = idDt.withResourceType(getResourceName());
    }else if (getResourceName().equals(idDt.getResourceType())==false) {
      throw new InvalidRequestException("ID parameter has the wrong resource type, expected '" + getResourceName() + "', found: " + idDt.getResourceType());
    }
   
    HttpDeleteClientInvocation retVal = createDeleteInvocation(idDt);

    for (int idx = 0; idx < theArgs.length; idx++) {
View Full Code Here

     */
    String locationHeader = theRequest.getServletRequest().getHeader(Constants.HEADER_CONTENT_LOCATION);
    IdDt id = new IdDt(locationHeader);
    if (isNotBlank(id.getResourceType())) {
      if (!getResourceName().equals(id.getResourceType())) {
        throw new InvalidRequestException("Attempting to update '" + getResourceName() + "' but content-location header specifies different resource type '" + id.getResourceType() + "' - header value: " + locationHeader);
      }
    }

    if (theRequest.getId() != null && theRequest.getId().hasVersionIdPart() == false) {
      if (id != null && id.hasVersionIdPart()) {
        theRequest.setId(id);
      }
    }
   
    if (isNotBlank(locationHeader)) {
      MethodOutcome mo = new MethodOutcome();
      parseContentLocation(mo, getResourceName(), 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

    myComparator = null;
    setValueAsString(null);
    if (theParameters.size() == 1) {
      setValueAsString(theParameters.get(0));
    } else if (theParameters.size() > 1) {
      throw new InvalidRequestException("This server does not support multi-valued dates for this paramater: " + theParameters);
    }
  }
View Full Code Here

        if (StringUtils.isNotBlank(sinceParams[0])) {
          try {
            IntegerDt since = new IntegerDt(sinceParams[0]);
            return ParameterUtil.fromInteger(myType, since);
          } catch (DataFormatException e) {
            throw new InvalidRequestException("Invalid " + Constants.PARAM_COUNT + " value: " + sinceParams[0]);
          }
        }
      }
    }
    return ParameterUtil.fromInteger(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(Constants.HEADER_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

      myLeftType.setValueAsQueryToken(theQualifier, "");
      myRightType.setValueAsQueryToken(theQualifier, "");
    } else {
      List<String> parts = ParameterUtil.splitParameterString(theValue, '$', false);
      if (parts.size() > 2) {
        throw new InvalidRequestException("Invalid value for composite parameter (only one '$' is valid for this parameter, others must be escaped). Value was: " + theValue);
      }
      myLeftType.setValueAsQueryToken(theQualifier, parts.get(0));
      if (parts.size() > 1) {
        myRightType.setValueAsQueryToken(theQualifier, parts.get(1));
      }
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);
      DateParam parsed = new DateParam();
      parsed.setValueAsQueryToken(null, param);
      addParam(parsed);
View Full Code Here

  }

  private void addParam(DateParam 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

          encoding = EncodingEnum.JSON;
          break;
        }
      }
      if (encoding == null) {
        throw new InvalidRequestException("FHIR client can't determine resource encoding");
      }
      return encoding.newParser(myContext).parseResource(theResourceBody);
    }
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.