@Override
  public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
    IIdType idDt = (IIdType) theArgs[getIdParameterIndex()];
    if (idDt == null) {
      throw new NullPointerException("ID can not be null");
    }

    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(getContext(), idDt);

    for (int idx = 0; idx < theArgs.length; idx++) {
      IParameter nextParam = getParameters().get(idx);
      nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null);
    }

    return retVal;
  }
Example #2
0
 public Parameter(IParameter source) {
   this.name = source.getName();
   this.dataType = source.getDataType();
   this.inputPath = source.getInputPath();
   this.defaultValue =
       source.getDefaultValue() == null ? null : source.getDefaultValue().toString();
 }
 @Override
 public void add(final Collection<? extends IParameter> params, final IAgent agent) {
   for (final IParameter var : params) {
     IParameterEditor gp = GuiUtils.getEditorFactory().create((IAgent) null, var, null);
     String cat = var.getCategory();
     cat = cat == null ? "General" : cat;
     addItem(cat);
     categories.get(cat).put(gp.getParam().getName(), gp);
   }
 }
  @Override
  public double[] getParameterValues() {
    double[] result = new double[getNoOfParameters()];
    int n = 0;
    for (IParameter p : parameterList) {
      result[n++] = p.getValue();
    }

    return result;
  }
  @Override
  public HttpGetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
    HttpGetClientInvocation retVal = MethodUtil.createConformanceInvocation(getContext());

    if (theArgs != null) {
      for (int idx = 0; idx < theArgs.length; idx++) {
        IParameter nextParam = getParameters().get(idx);
        nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null);
      }
    }

    return retVal;
  }
  @Override
  public IByteQueue getByteQueueForWritingParameter(IParameter parameter) {
    IByteQueue byteQueueForWritingParameter = new ByteQueue();

    addCommandRequestTo(
        byteQueueForWritingParameter, WRITE_COMMAND, parameter.getByteQueueForWriting());

    return byteQueueForWritingParameter;
  }
  @Override
  public IByteQueue getByteQueueForReadingParameter(IParameter parameter) {
    IByteQueue byteQueueForReadingParameter = new ByteQueue();

    addCommandRequestTo(
        byteQueueForReadingParameter, READ_COMMAND, parameter.getByteQueueForRequest());

    return byteQueueForReadingParameter;
  }
  public void parseXML(String XML) {
    logger = Logger.getLogger(RegisterResponseMessage.class);
    try {
      Response req = getResponse(XML);

      CommandResponseType command = req.getCommand();
      RegisterResponseType regType = command.getRegisterResponse();
      RegisterResponseParamsType regparams = regType.getParams();
      IParameter param = new Parameter();
      param.add(EnumParamsType.STATUSCODE, regparams.getStatuscode());
      param.add(EnumParamsType.MESSAGE, regparams.getMessage());

      this.setOperationType(EnumOperationType.REGISTERRESPONSE);
      this.setParameter(param);
    } catch (Exception e) {
      logger.error("Unable to parse request from string", e);
    }
  }
 @Override
 public int expectedWritingParameterResponseSize(IParameter parameter) {
   return STATIC_PARAMETER_RESPONSE_SIZE + parameter.getAddressSize() + parameter.getDataSize();
 }
  @Override
  public void invokeServer(RestfulServer theServer, Request theRequest)
      throws BaseServerResponseException, IOException {

    // Pretty print
    boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theServer, theRequest);

    // Narrative mode
    NarrativeModeEnum narrativeMode = RestfulServerUtils.determineNarrativeMode(theRequest);

    // Determine response encoding
    EncodingEnum responseEncoding =
        RestfulServerUtils.determineResponseEncodingNoDefault(theRequest.getServletRequest());

    // Is this request coming from a browser
    String uaHeader = theRequest.getServletRequest().getHeader("user-agent");
    boolean requestIsBrowser = false;
    if (uaHeader != null && uaHeader.contains("Mozilla")) {
      requestIsBrowser = true;
    }

    Object requestObject = parseRequestObject(theRequest);

    // Method params
    Object[] params = new Object[getParameters().size()];
    for (int i = 0; i < getParameters().size(); i++) {
      IParameter param = getParameters().get(i);
      if (param != null) {
        params[i] = param.translateQueryParametersIntoServerArgument(theRequest, requestObject);
      }
    }

    Object resultObj = invokeServer(theRequest, params);

    Integer count = RestfulServerUtils.extractCountParameter(theRequest.getServletRequest());
    boolean respondGzip = theRequest.isRespondGzip();
    HttpServletResponse response = theRequest.getServletResponse();
    switch (getReturnType()) {
      case BUNDLE:
        {
          if (getMethodReturnType() == MethodReturnTypeEnum.BUNDLE_RESOURCE) {
            IResource resource;
            if (resultObj instanceof IBundleProvider) {
              IBundleProvider result = (IBundleProvider) resultObj;
              resource = result.getResources(0, 1).get(0);
            } else {
              resource = (IResource) resultObj;
            }

            /*
             * We assume that the bundle we got back from the handling method may not have everything populated
             * (e.g. self links, bundle type, etc) so we do that here.
             */
            IVersionSpecificBundleFactory bundleFactory =
                theServer.getFhirContext().newBundleFactory();
            bundleFactory.initializeWithBundleResource(resource);
            bundleFactory.addRootPropertiesToBundle(
                null,
                theRequest.getFhirServerBase(),
                theRequest.getCompleteUrl(),
                count,
                getResponseBundleType());

            for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
              IServerInterceptor next = theServer.getInterceptors().get(i);
              boolean continueProcessing =
                  next.outgoingResponse(
                      theRequest,
                      resource,
                      theRequest.getServletRequest(),
                      theRequest.getServletResponse());
              if (!continueProcessing) {
                ourLog.debug("Interceptor {} returned false, not continuing processing");
                return;
              }
            }
            RestfulServerUtils.streamResponseAsResource(
                theServer,
                response,
                resource,
                responseEncoding,
                prettyPrint,
                requestIsBrowser,
                narrativeMode,
                Constants.STATUS_HTTP_200_OK,
                respondGzip,
                theRequest.getFhirServerBase(),
                isAddContentLocationHeader());
            break;
          } else {
            Set<Include> includes = getRequestIncludesFromParams(params);

            IBundleProvider result = (IBundleProvider) resultObj;
            if (count == null) {
              count = result.preferredPageSize();
            }

            IVersionSpecificBundleFactory bundleFactory =
                theServer.getFhirContext().newBundleFactory();
            bundleFactory.initializeBundleFromBundleProvider(
                theServer,
                result,
                responseEncoding,
                theRequest.getFhirServerBase(),
                theRequest.getCompleteUrl(),
                prettyPrint,
                0,
                count,
                null,
                getResponseBundleType(),
                includes);
            Bundle bundle = bundleFactory.getDstu1Bundle();
            if (bundle != null) {
              for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
                IServerInterceptor next = theServer.getInterceptors().get(i);
                boolean continueProcessing =
                    next.outgoingResponse(
                        theRequest,
                        bundle,
                        theRequest.getServletRequest(),
                        theRequest.getServletResponse());
                if (!continueProcessing) {
                  ourLog.debug("Interceptor {} returned false, not continuing processing");
                  return;
                }
              }
              RestfulServerUtils.streamResponseAsBundle(
                  theServer,
                  response,
                  bundle,
                  responseEncoding,
                  theRequest.getFhirServerBase(),
                  prettyPrint,
                  narrativeMode,
                  respondGzip,
                  requestIsBrowser);
            } else {
              IBaseResource resBundle = bundleFactory.getResourceBundle();
              for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
                IServerInterceptor next = theServer.getInterceptors().get(i);
                boolean continueProcessing =
                    next.outgoingResponse(
                        theRequest,
                        resBundle,
                        theRequest.getServletRequest(),
                        theRequest.getServletResponse());
                if (!continueProcessing) {
                  ourLog.debug("Interceptor {} returned false, not continuing processing");
                  return;
                }
              }
              RestfulServerUtils.streamResponseAsResource(
                  theServer,
                  response,
                  (IResource) resBundle,
                  responseEncoding,
                  prettyPrint,
                  requestIsBrowser,
                  narrativeMode,
                  Constants.STATUS_HTTP_200_OK,
                  theRequest.isRespondGzip(),
                  theRequest.getFhirServerBase(),
                  isAddContentLocationHeader());
            }

            break;
          }
        }
      case RESOURCE:
        {
          IBundleProvider result = (IBundleProvider) resultObj;
          if (result.size() == 0) {
            throw new ResourceNotFoundException(theRequest.getId());
          } else if (result.size() > 1) {
            throw new InternalErrorException("Method returned multiple resources");
          }

          IResource resource = result.getResources(0, 1).get(0);

          for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
            IServerInterceptor next = theServer.getInterceptors().get(i);
            boolean continueProcessing =
                next.outgoingResponse(
                    theRequest,
                    resource,
                    theRequest.getServletRequest(),
                    theRequest.getServletResponse());
            if (!continueProcessing) {
              return;
            }
          }

          RestfulServerUtils.streamResponseAsResource(
              theServer,
              response,
              resource,
              responseEncoding,
              prettyPrint,
              requestIsBrowser,
              narrativeMode,
              Constants.STATUS_HTTP_200_OK,
              respondGzip,
              theRequest.getFhirServerBase(),
              isAddContentLocationHeader());
          break;
        }
    }
  }
  /**
   * Analyze and categorize each of the parameters in scope.
   *
   * @param helpers The standard burp ExtensionHelpers object.
   * @param messages The set of request messages to be processed.
   */
  private void firstPass(IExtensionHelpers helpers, IHttpRequestResponse[] messages) {
    publish("Examining parameters...");
    for (int i = 0; i < messages.length; i++) {
      publish(100 * i / messages.length);
      messages[i].getHttpService();
      //  Analyze response for cookies
      if (messages[i].getResponse() != null) {
        IResponseInfo responseInfo = helpers.analyzeResponse(messages[i].getResponse());
        List<String> headers = responseInfo.getHeaders();
        for (String header : headers) {
          if (startsWithIgnoreCase(header, "set-cookie:")) {
            processCookieHeader(header);
          }
        }
      }
      IRequestInfo requestInfo = helpers.analyzeRequest(messages[i]);
      if (callbacks.isInScope(requestInfo.getUrl())) {
        byte[] responseBytes = messages[i].getResponse();
        String responseString = "";
        if (responseBytes != null) {
          responseString = helpers.bytesToString(responseBytes);
          inScopeMessagesWithResponses.add(messages[i]);
        }

        List<IParameter> params = requestInfo.getParameters();
        for (IParameter param : params) {
          if ((!ignoreEmpty || param.getValue().length() > 0)
              && !ignoreList.contains(param.getName())) {
            int type = param.getType();
            Map<String, CorrelatedParam> paramMap;
            switch (type) {
              case IParameter.PARAM_URL:
                paramMap = urlParameters;
                break;
              case IParameter.PARAM_BODY:
                paramMap = bodyParameters;
                break;
              case IParameter.PARAM_COOKIE:
                paramMap = cookieParameters;
                break;
              case IParameter.PARAM_JSON:
                paramMap = jsonParameters;
                break;
              default:
                paramMap = null;
                // nothing
            }

            if (paramMap != null) {
              if (messages[i] == null) {
                callbacks.printOutput("Warning... adding null message!");
              }

              if (paramMap.containsKey(param.getName())) {
                paramMap
                    .get(param.getName())
                    .put(param, messages[i], requestInfo, responseString, helpers);
              } else {
                paramMap.put(
                    param.getName(),
                    new CorrelatedParam(param, messages[i], requestInfo, responseString, helpers));
              }
            }
          }
        }
      }
    }
  }