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

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


  protected BaseServerResponseException processNon2xxResponseAndReturnExceptionToThrow(int theStatusCode, String theResponseMimeType, Reader theResponseReader) {
    BaseServerResponseException ex;
    switch (theStatusCode) {
    case Constants.STATUS_HTTP_400_BAD_REQUEST:
      ex = new InvalidRequestException("Server responded with HTTP 400");
      break;
    case Constants.STATUS_HTTP_404_NOT_FOUND:
      ex = new ResourceNotFoundException("Server responded with HTTP 404");
      break;
    case Constants.STATUS_HTTP_405_METHOD_NOT_ALLOWED:
View Full Code Here


    if (theParams.size() == 0 || theParams.get(0).size() == 0) {
      return dt;
    }
    if (theParams.size() > 1 || theParams.get(0).size() > 1) {
      throw new InvalidRequestException("Multiple values detected for non-repeatable parameter '" + theName + "'. This server is not configured to allow multiple (AND/OR) values for this param.");
    }

    dt.setValueAsQueryToken(theParams.get(0).getQualifier(), value);
    return dt;
  }
View Full Code Here

  public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
    HttpPostClientInvocation retVal;

    IdDt id = (IdDt) theArgs[myIdParamIndex];
    if (id == null || id.isEmpty()) {
      throw new InvalidRequestException("ID must not be null or empty for this operation");
    }

    IdDt versionId = null;
    if (myVersionIdParamIndex != null) {
      versionId = (IdDt) theArgs[myVersionIdParamIndex];
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);
      }
    }

    theParams[myIdParameterIndex] = theRequest.getId();
    if (myVersionIdParameterIndex != null) {
View Full Code Here

    boolean compartmentSearch = false;
    if (theCompartmentName != null) {
      if (theId == null || !theId.hasIdPart()) {
        String msg = theContext.getLocalizer().getMessage(SearchMethodBinding.class.getName() + ".idNullForCompartmentSearch");
        throw new InvalidRequestException(msg);
      } else {
        compartmentSearch = true;
      }
    }
View Full Code Here

    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

      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

          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

      }
      if (myId == null) {
        myId = myResource.getId();
      }
      if (myId == null || myId.hasIdPart() == false) {
        throw new InvalidRequestException("No ID supplied for resource to update, can not invoke server");
      }

      BaseHttpClientInvocation invocation = MethodUtil.createUpdateInvocation(myResource, myResourceBody, myId, myContext);

      RuntimeResourceDefinition def = myContext.getResourceDefinition(myResource);
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);
          } 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;
        } else {
          compartment = 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) {
        String contentLocation = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION);
        if (contentLocation != null) {
          id = 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.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);
      r.setCompartmentName(compartment);

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

      if (resourceMethod == null && resourceBinding != null) {
        resourceMethod = resourceBinding.getMethod(r);
      }
      if (resourceMethod == null) {
        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());
      }

      RequestDetails requestDetails = r;
      requestDetails.setResourceOperationType(resourceMethod.getResourceOperationType());
      requestDetails.setSystemOperationType(resourceMethod.getSystemOperationType());
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.