예제 #1
0
  protected void applyDefaultsToWsdlRequest(
      SubmitContext context, AbstractHttpRequestInterface<?> wsdlRequest, EndpointDefaults def) {
    String requestUsername = PropertyExpander.expandProperties(context, wsdlRequest.getUsername());
    String requestPassword = PropertyExpander.expandProperties(context, wsdlRequest.getPassword());
    String requestDomain = PropertyExpander.expandProperties(context, wsdlRequest.getDomain());

    String defUsername = PropertyExpander.expandProperties(context, def.getUsername());
    String defPassword = PropertyExpander.expandProperties(context, def.getPassword());
    String defDomain = PropertyExpander.expandProperties(context, def.getDomain());

    Enum authType = AuthType.Enum.forString(wsdlRequest.getAuthType());

    if (def.getMode() == EndpointConfig.Mode.OVERRIDE) {
      overrideRequest(
          context,
          wsdlRequest,
          def,
          requestUsername,
          requestPassword,
          requestDomain,
          defUsername,
          defPassword,
          defDomain,
          authType);
    } else if (def.getMode() == EndpointConfig.Mode.COPY) {
      copyToRequest(
          context,
          wsdlRequest,
          def,
          requestUsername,
          requestPassword,
          requestDomain,
          defUsername,
          defPassword,
          defDomain,
          authType);
    } else if (def.getMode() == EndpointConfig.Mode.COMPLEMENT) {
      complementRequest(
          context,
          wsdlRequest,
          def,
          requestUsername,
          requestPassword,
          requestDomain,
          defUsername,
          defPassword,
          defDomain,
          authType);
    }
  }
예제 #2
0
  private ExtendedHttpMethod createHttpMethod(AbstractHttpRequestInterface<?> httpRequest) {
    if (httpRequest instanceof HttpRequestInterface<?>) {
      HttpRequestInterface<?> restRequest = (HttpRequestInterface<?>) httpRequest;
      switch (restRequest.getMethod()) {
        case GET:
          return new ExtendedGetMethod();
        case HEAD:
          return new ExtendedHeadMethod();
        case DELETE:
          return new ExtendedDeleteMethod();
        case PUT:
          return new ExtendedPutMethod();
        case OPTIONS:
          return new ExtendedOptionsMethod();
        case TRACE:
          return new ExtendedTraceMethod();
      }
    }

    ExtendedPostMethod extendedPostMethod = new ExtendedPostMethod();

    extendedPostMethod.setAfterRequestInjection(httpRequest.getAfterRequestInjection());
    return extendedPostMethod;
  }
예제 #3
0
  public Response sendRequest(SubmitContext submitContext, Request request) throws Exception {
    AbstractHttpRequestInterface<?> httpRequest = (AbstractHttpRequestInterface<?>) request;

    HttpClient httpClient = HttpClientSupport.getHttpClient();
    ExtendedHttpMethod httpMethod = createHttpMethod(httpRequest);
    boolean createdState = false;

    HttpState httpState = (HttpState) submitContext.getProperty(SubmitContext.HTTP_STATE_PROPERTY);
    if (httpState == null) {
      httpState = new HttpState();
      submitContext.setProperty(SubmitContext.HTTP_STATE_PROPERTY, httpState);
      createdState = true;
    }

    HostConfiguration hostConfiguration = new HostConfiguration();

    String localAddress = System.getProperty("soapui.bind.address", httpRequest.getBindAddress());
    if (localAddress == null || localAddress.trim().length() == 0)
      localAddress = SoapUI.getSettings().getString(HttpSettings.BIND_ADDRESS, null);

    if (localAddress != null && localAddress.trim().length() > 0) {
      try {
        hostConfiguration.setLocalAddress(InetAddress.getByName(localAddress));
      } catch (Exception e) {
        SoapUI.logError(e);
      }
    }

    submitContext.removeProperty(RESPONSE);
    submitContext.setProperty(HTTP_METHOD, httpMethod);
    submitContext.setProperty(POST_METHOD, httpMethod);
    submitContext.setProperty(HTTP_CLIENT, httpClient);
    submitContext.setProperty(REQUEST_CONTENT, httpRequest.getRequestContent());
    submitContext.setProperty(HOST_CONFIGURATION, hostConfiguration);
    submitContext.setProperty(WSDL_REQUEST, httpRequest);
    submitContext.setProperty(RESPONSE_PROPERTIES, new StringToStringMap());

    for (RequestFilter filter : filters) {
      filter.filterRequest(submitContext, httpRequest);
    }

    try {
      Settings settings = httpRequest.getSettings();

      // custom http headers last so they can be overridden
      StringToStringMap headers = httpRequest.getRequestHeaders();
      for (String header : headers.keySet()) {
        String headerValue = headers.get(header);
        headerValue = PropertyExpander.expandProperties(submitContext, headerValue);
        httpMethod.setRequestHeader(header, headerValue);
      }

      // do request
      WsdlProject project = (WsdlProject) ModelSupport.getModelItemProject(httpRequest);
      WssCrypto crypto = null;
      if (project != null) {
        crypto =
            project
                .getWssContainer()
                .getCryptoByName(
                    PropertyExpander.expandProperties(submitContext, httpRequest.getSslKeystore()));
      }

      if (crypto != null && WssCrypto.STATUS_OK.equals(crypto.getStatus())) {
        hostConfiguration
            .getParams()
            .setParameter(
                SoapUIHostConfiguration.SOAPUI_SSL_CONFIG,
                crypto.getSource() + " " + crypto.getPassword());
      }

      // dump file?
      httpMethod.setDumpFile(
          PathUtils.expandPath(
              httpRequest.getDumpFile(), (AbstractWsdlModelItem<?>) httpRequest, submitContext));

      // include request time?
      if (settings.getBoolean(HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN))
        httpMethod.initStartTime();

      // submit!
      httpClient.executeMethod(hostConfiguration, httpMethod, httpState);
      httpMethod.getTimeTaken();
    } catch (Throwable t) {
      httpMethod.setFailed(t);

      if (t instanceof Exception) throw (Exception) t;

      SoapUI.logError(t);
      throw new Exception(t);
    } finally {
      for (int c = filters.size() - 1; c >= 0; c--) {
        filters.get(c).afterRequest(submitContext, httpRequest);
      }

      if (!submitContext.hasProperty(RESPONSE)) {
        createDefaultResponse(submitContext, httpRequest, httpMethod);
      }

      Response response = (Response) submitContext.getProperty(BaseHttpRequestTransport.RESPONSE);
      StringToStringMap responseProperties =
          (StringToStringMap)
              submitContext.getProperty(BaseHttpRequestTransport.RESPONSE_PROPERTIES);

      for (String key : responseProperties.keySet()) {
        response.setProperty(key, responseProperties.get(key));
      }

      if (httpMethod != null) {
        httpMethod.releaseConnection();
      } else log.error("PostMethod is null");

      if (createdState) {
        submitContext.setProperty(SubmitContext.HTTP_STATE_PROPERTY, null);
      }
    }

    return (Response) submitContext.getProperty(BaseHttpRequestTransport.RESPONSE);
  }