private Map<String, String> propertyExpansionSupport(
     Map<String, String> checkMap, SubmitContext context) {
   Map<String, String> expanded = new HashMap<String, String>();
   for (String key : checkMap.keySet()) {
     expanded.put(context.expand(key), context.expand(checkMap.get(key)));
   }
   return expanded;
 }
Esempio n. 2
0
  private SoapUIAMFConnection getConnection(AMFRequest amfRequest) throws Exception {
    SoapUIAMFConnection amfConnection = null;
    if (isAuthorisationEnabled(amfRequest) && (context.getModelItem() instanceof WsdlTestCase)) {
      if ((amfConnection = (SoapUIAMFConnection) context.getProperty(AMF_CONNECTION)) != null) {
        return amfConnection;
      } else {
        throw new Exception("amf session connection error! ");
      }
    } else if (isAuthorisationEnabled(amfRequest)
        && (context.getModelItem() instanceof AMFRequestTestStep)) {
      String endpoint = context.expand(getTestCaseConfig(amfRequest).getAmfEndpoint());
      String username = context.expand(getTestCaseConfig(amfRequest).getAmfLogin());
      String password = context.expand(getTestCaseConfig(amfRequest).getAmfPassword());

      if (StringUtils.hasContent(endpoint) && StringUtils.hasContent(username)) {
        credentials = new AMFCredentials(endpoint, username, password, context);
        amfConnection = credentials.login();
      } else {
        amfConnection = new SoapUIAMFConnection();
        amfConnection.connect(context.expand(amfRequest.getEndpoint()));
      }

      context.setProperty(AMF_CONNECTION, amfConnection);
      return amfConnection;
    } else {
      amfConnection = new SoapUIAMFConnection();
      amfConnection.connect(context.expand(amfRequest.getEndpoint()));
      return amfConnection;
    }
  }
  public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> wsdlRequest) {
    if (!wsdlRequest.isStripWhitespaces()) {
      return;
    }

    String content = (String) context.getProperty(BaseHttpRequestTransport.REQUEST_CONTENT);
    if (content == null) {
      log.warn("Missing request content in context, skipping stripWhitespaces");
    } else {
      content = XmlUtils.stripWhitespaces(content);
      context.setProperty(BaseHttpRequestTransport.REQUEST_CONTENT, content);
    }
  }
Esempio n. 4
0
  @Override
  protected String internalAssertResponse(MessageExchange messageExchange, SubmitContext context)
      throws AssertionException {

    if (context.getProperty(JdbcSubmit.JDBC_TIMEOUT) != null) {
      Long timeout = Long.valueOf(context.getProperty(JdbcSubmit.JDBC_TIMEOUT).toString());
      throw new AssertionException(
          new AssertionError(
              "JDBC Request timeout error! Query not executed in " + timeout + " ms."));
    }

    return "JDBC Timeout OK";
  }
Esempio n. 5
0
  private Object executeAmfCall(AMFRequest amfRequest)
      throws ClientStatusException, ServerStatusException {
    SoapUIAMFConnection amfConnection = null;
    try {
      amfConnection = getConnection(amfRequest);
      addAmfHeaders(amfRequest, amfConnection);
      addHttpHeaders(amfRequest, amfConnection);
      Object result =
          amfConnection.call(context, amfRequest.getAmfCall(), amfRequest.argumentsToArray());

      return result;
    } catch (Exception e) {
      SoapUI.logError(e);
      error = e;
      status = Status.ERROR;
    } finally {
      amfRequest.clearArguments();
      if (context.getModelItem() instanceof AMFRequestTestStep) {
        if (credentials != null && credentials.isLoggedIn()) {
          credentials.logout();
          credentials = null;
        } else {
          amfConnection.close();
        }
      }
    }
    return null;
  }
  public Response execute(SubmitContext submitContext, Request request, long timeStarted)
      throws Exception {
    Session queueSession = null;
    JMSConnectionHolder jmsConnectionHolder = null;
    try {
      init(submitContext, request);
      jmsConnectionHolder =
          new JMSConnectionHolder(jmsEndpoint, hermes, false, clientID, username, password);

      // session
      queueSession = jmsConnectionHolder.getSession();

      // destination
      Queue queue = jmsConnectionHolder.getQueue(jmsConnectionHolder.getJmsEndpoint().getReceive());

      // consumer
      MessageConsumer messageConsumer =
          queueSession.createConsumer(queue, submitContext.expand(messageSelector));

      return makeResponse(submitContext, request, timeStarted, null, messageConsumer);

    } catch (JMSException jmse) {
      return errorResponse(submitContext, request, timeStarted, jmse);
    } catch (Throwable t) {
      SoapUI.logError(t);
    } finally {
      if (jmsConnectionHolder != null) jmsConnectionHolder.closeAll();
      closeSessionAndConnection(
          jmsConnectionHolder != null ? jmsConnectionHolder.getConnection() : null, queueSession);
    }
    return null;
  }
  @Override
  public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> request) {
    HttpRequestBase httpMethod =
        (HttpRequestBase) context.getProperty(BaseHttpRequestTransport.HTTP_METHOD);

    String strURL = request.getEndpoint();
    strURL = PropertyExpander.expandProperties(context, strURL);
    try {
      if (StringUtils.hasContent(strURL)) {
        URI uri = new URI(strURL, request.getSettings().getBoolean(HttpSettings.ENCODED_URLS));
        context.setProperty(BaseHttpRequestTransport.REQUEST_URI, uri);
        httpMethod.setURI(HttpUtils.createUri(uri));
      }
    } catch (Exception e) {
      SoapUI.logError(e);
    }
  }
Esempio n. 8
0
 private void addHttpHeaders(AMFRequest amfRequest, SoapUIAMFConnection amfConnection) {
   StringToStringsMap httpHeaders = amfRequest.getHttpHeaders();
   if (httpHeaders != null) {
     for (String key : httpHeaders.getKeys()) {
       for (String value : httpHeaders.get(key))
         amfConnection.addHttpRequestHeader(key, context.expand(value));
     }
   }
 }
Esempio n. 9
0
  private void addAmfHeaders(AMFRequest amfRequest, SoapUIAMFConnection amfConnection) {
    if (amfRequest.getAmfHeaders() != null) {
      for (String key : amfRequest.getAmfHeaders().keySet()) {
        Object data = amfRequest.getAmfHeaders().get(key);
        if (data instanceof String) data = context.expand((String) data);

        amfConnection.addAmfHeader(key, data);
      }
    }
  }
Esempio n. 10
0
  private void createDefaultResponse(
      SubmitContext submitContext,
      AbstractHttpRequestInterface<?> httpRequest,
      ExtendedHttpMethod httpMethod) {
    String requestContent =
        (String) submitContext.getProperty(BaseHttpRequestTransport.REQUEST_CONTENT);

    // check content-type for multiplart
    Header responseContentTypeHeader = httpMethod.getResponseHeader("Content-Type");
    Response response = null;

    if (responseContentTypeHeader != null
        && responseContentTypeHeader.getValue().toUpperCase().startsWith("MULTIPART")) {
      response = new MimeMessageResponse(httpRequest, httpMethod, requestContent, submitContext);
    } else {
      response = new SinglePartHttpResponse(httpRequest, httpMethod, requestContent, submitContext);
    }

    submitContext.setProperty(BaseHttpRequestTransport.RESPONSE, response);
  }
Esempio n. 11
0
 public void logout() {
   SoapUIAMFConnection connection =
       (SoapUIAMFConnection) context.getProperty(AMFSubmit.AMF_CONNECTION);
   CommandMessage commandMessage = createLogoutCommandMessage();
   try {
     connection.call((SubmitContext) context, null, commandMessage);
   } catch (ClientStatusException e) {
     SoapUI.logError(e);
   } catch (ServerStatusException e) {
     SoapUI.logError(e);
   } finally {
     connection.close();
   }
 }
  public void filterRequest(SubmitContext context, WsdlRequest wsdlRequest) {
    TimeablePostMethod postMethod =
        (TimeablePostMethod) context.getProperty(BaseHttpRequestTransport.POST_METHOD);

    //	 set maxsize
    Settings settings = wsdlRequest.getSettings();

    // close connections?
    if (settings.getBoolean(HttpSettings.CLOSE_CONNECTIONS))
      postMethod.setRequestHeader("Connection", "close");

    // max size..
    postMethod.setMaxSize(settings.getLong(HttpSettings.MAX_RESPONSE_SIZE, 0));

    // apply global settings
    HttpClientSupport.applyHttpSettings(postMethod, settings);
  }
  @Override
  public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> httpRequest) {
    Settings settings = httpRequest.getSettings();
    String compressionAlg = settings.getString(HttpSettings.REQUEST_COMPRESSION, "None");
    if (!"None".equals(compressionAlg)) {
      try {
        ExtendedHttpMethod method =
            (ExtendedHttpMethod) context.getProperty(BaseHttpRequestTransport.HTTP_METHOD);
        if (method instanceof HttpEntityEnclosingRequest) {
          HttpEntity requestEntity = ((HttpEntityEnclosingRequest) method).getEntity();
          if (requestEntity != null) {
            ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
            requestEntity.writeTo(tempOut);

            byte[] compressedData =
                CompressionSupport.compress(compressionAlg, tempOut.toByteArray());
            ((HttpEntityEnclosingRequest) method).setEntity(new ByteArrayEntity(compressedData));
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 14
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);
  }
Esempio n. 15
0
  @SuppressWarnings("deprecation")
  @Override
  public void filterHttpRequest(SubmitContext context, HttpRequestInterface<?> request) {
    HttpRequestBase httpMethod =
        (HttpRequestBase) context.getProperty(BaseHttpRequestTransport.HTTP_METHOD);

    String path = PropertyExpander.expandProperties(context, request.getPath());
    StringBuffer query = new StringBuffer();
    String encoding =
        System.getProperty("soapui.request.encoding", StringUtils.unquote(request.getEncoding()));

    StringToStringMap responseProperties =
        (StringToStringMap) context.getProperty(BaseHttpRequestTransport.RESPONSE_PROPERTIES);

    MimeMultipart formMp =
        "multipart/form-data".equals(request.getMediaType())
                && httpMethod instanceof HttpEntityEnclosingRequestBase
            ? new MimeMultipart()
            : null;

    RestParamsPropertyHolder params = request.getParams();

    for (int c = 0; c < params.getPropertyCount(); c++) {
      RestParamProperty param = params.getPropertyAt(c);

      String value = PropertyExpander.expandProperties(context, param.getValue());
      responseProperties.put(param.getName(), value);

      List<String> valueParts =
          sendEmptyParameters(request) || (!StringUtils.hasContent(value) && param.getRequired())
              ? RestUtils.splitMultipleParametersEmptyIncluded(
                  value, request.getMultiValueDelimiter())
              : RestUtils.splitMultipleParameters(value, request.getMultiValueDelimiter());

      // skip HEADER and TEMPLATE parameter encoding (TEMPLATE is encoded by
      // the URI handling further down)
      if (value != null
          && param.getStyle() != ParameterStyle.HEADER
          && param.getStyle() != ParameterStyle.TEMPLATE
          && !param.isDisableUrlEncoding()) {
        try {
          if (StringUtils.hasContent(encoding)) {
            value = URLEncoder.encode(value, encoding);
            for (int i = 0; i < valueParts.size(); i++)
              valueParts.set(i, URLEncoder.encode(valueParts.get(i), encoding));
          } else {
            value = URLEncoder.encode(value);
            for (int i = 0; i < valueParts.size(); i++)
              valueParts.set(i, URLEncoder.encode(valueParts.get(i)));
          }
        } catch (UnsupportedEncodingException e1) {
          SoapUI.logError(e1);
          value = URLEncoder.encode(value);
          for (int i = 0; i < valueParts.size(); i++)
            valueParts.set(i, URLEncoder.encode(valueParts.get(i)));
        }
        // URLEncoder replaces space with "+", but we want "%20".
        value = value.replaceAll("\\+", "%20");
        for (int i = 0; i < valueParts.size(); i++)
          valueParts.set(i, valueParts.get(i).replaceAll("\\+", "%20"));
      }

      if (param.getStyle() == ParameterStyle.QUERY && !sendEmptyParameters(request)) {
        if (!StringUtils.hasContent(value) && !param.getRequired()) continue;
      }

      switch (param.getStyle()) {
        case HEADER:
          for (String valuePart : valueParts) httpMethod.addHeader(param.getName(), valuePart);
          break;
        case QUERY:
          if (formMp == null || !request.isPostQueryString()) {
            for (String valuePart : valueParts) {
              if (query.length() > 0) query.append('&');

              query.append(URLEncoder.encode(param.getName()));
              query.append('=');
              if (StringUtils.hasContent(valuePart)) query.append(valuePart);
            }
          } else {
            try {
              addFormMultipart(
                  request, formMp, param.getName(), responseProperties.get(param.getName()));
            } catch (MessagingException e) {
              SoapUI.logError(e);
            }
          }

          break;
        case TEMPLATE:
          try {
            value =
                getEncodedValue(
                    value,
                    encoding,
                    param.isDisableUrlEncoding(),
                    request.getSettings().getBoolean(HttpSettings.ENCODED_URLS));
            path = path.replaceAll("\\{" + param.getName() + "\\}", value == null ? "" : value);
          } catch (UnsupportedEncodingException e) {
            SoapUI.logError(e);
          }
          break;
        case MATRIX:
          try {
            value =
                getEncodedValue(
                    value,
                    encoding,
                    param.isDisableUrlEncoding(),
                    request.getSettings().getBoolean(HttpSettings.ENCODED_URLS));
          } catch (UnsupportedEncodingException e) {
            SoapUI.logError(e);
          }

          if (param.getType().equals(XmlBoolean.type.getName())) {
            if (value.toUpperCase().equals("TRUE") || value.equals("1")) {
              path += ";" + param.getName();
            }
          } else {
            path += ";" + param.getName();
            if (StringUtils.hasContent(value)) {
              path += "=" + value;
            }
          }
          break;
        case PLAIN:
          break;
      }
    }

    if (request.getSettings().getBoolean(HttpSettings.FORWARD_SLASHES))
      path = PathUtils.fixForwardSlashesInPath(path);

    if (PathUtils.isHttpPath(path)) {
      try {
        // URI(String) automatically URLencodes the input, so we need to
        // decode it first...
        URI uri = new URI(path, request.getSettings().getBoolean(HttpSettings.ENCODED_URLS));
        context.setProperty(BaseHttpRequestTransport.REQUEST_URI, uri);
        java.net.URI oldUri = httpMethod.getURI();
        httpMethod.setURI(
            HttpUtils.createUri(
                oldUri.getScheme(),
                oldUri.getRawUserInfo(),
                oldUri.getHost(),
                oldUri.getPort(),
                oldUri.getRawPath(),
                uri.getEscapedQuery(),
                oldUri.getRawFragment()));
      } catch (Exception e) {
        SoapUI.logError(e);
      }
    } else if (StringUtils.hasContent(path)) {
      try {
        java.net.URI oldUri = httpMethod.getURI();
        String pathToSet =
            StringUtils.hasContent(oldUri.getRawPath()) && !"/".equals(oldUri.getRawPath())
                ? oldUri.getRawPath() + path
                : path;
        java.net.URI newUri =
            URIUtils.createURI(
                oldUri.getScheme(),
                oldUri.getHost(),
                oldUri.getPort(),
                pathToSet,
                oldUri.getQuery(),
                oldUri.getFragment());
        httpMethod.setURI(newUri);
        context.setProperty(
            BaseHttpRequestTransport.REQUEST_URI,
            new URI(
                newUri.toString(), request.getSettings().getBoolean(HttpSettings.ENCODED_URLS)));
      } catch (Exception e) {
        SoapUI.logError(e);
      }
    }

    if (query.length() > 0 && !request.isPostQueryString()) {
      try {
        java.net.URI oldUri = httpMethod.getURI();
        httpMethod.setURI(
            URIUtils.createURI(
                oldUri.getScheme(),
                oldUri.getHost(),
                oldUri.getPort(),
                oldUri.getRawPath(),
                query.toString(),
                oldUri.getFragment()));
      } catch (Exception e) {
        SoapUI.logError(e);
      }
    }

    if (request instanceof RestRequest) {
      String acceptEncoding = ((RestRequest) request).getAccept();
      if (StringUtils.hasContent(acceptEncoding)) {
        httpMethod.setHeader("Accept", acceptEncoding);
      }
    }

    if (formMp != null) {
      // create request message
      try {
        if (request.hasRequestBody() && httpMethod instanceof HttpEntityEnclosingRequest) {
          String requestContent =
              PropertyExpander.expandProperties(
                  context, request.getRequestContent(), request.isEntitizeProperties());
          if (StringUtils.hasContent(requestContent)) {
            initRootPart(request, requestContent, formMp);
          }
        }

        for (Attachment attachment : request.getAttachments()) {
          MimeBodyPart part = new PreencodedMimeBodyPart("binary");

          if (attachment instanceof FileAttachment<?>) {
            String name = attachment.getName();
            if (StringUtils.hasContent(attachment.getContentID())
                && !name.equals(attachment.getContentID())) name = attachment.getContentID();

            part.setDisposition(
                "form-data; name=\"" + name + "\"; filename=\"" + attachment.getName() + "\"");
          } else part.setDisposition("form-data; name=\"" + attachment.getName() + "\"");

          part.setDataHandler(new DataHandler(new AttachmentDataSource(attachment)));

          formMp.addBodyPart(part);
        }

        MimeMessage message = new MimeMessage(AttachmentUtils.JAVAMAIL_SESSION);
        message.setContent(formMp);
        message.saveChanges();
        RestRequestMimeMessageRequestEntity mimeMessageRequestEntity =
            new RestRequestMimeMessageRequestEntity(message, request);
        ((HttpEntityEnclosingRequest) httpMethod).setEntity(mimeMessageRequestEntity);
        httpMethod.setHeader("Content-Type", mimeMessageRequestEntity.getContentType().getValue());
        httpMethod.setHeader("MIME-Version", "1.0");
      } catch (Throwable e) {
        SoapUI.logError(e);
      }
    } else if (request.hasRequestBody() && httpMethod instanceof HttpEntityEnclosingRequest) {
      if (StringUtils.hasContent(request.getMediaType()))
        httpMethod.setHeader(
            "Content-Type", getContentTypeHeader(request.getMediaType(), encoding));

      if (request.isPostQueryString()) {
        try {
          ((HttpEntityEnclosingRequest) httpMethod).setEntity(new StringEntity(query.toString()));
        } catch (UnsupportedEncodingException e) {
          SoapUI.logError(e);
        }
      } else {
        String requestContent =
            PropertyExpander.expandProperties(
                context, request.getRequestContent(), request.isEntitizeProperties());
        List<Attachment> attachments = new ArrayList<Attachment>();

        for (Attachment attachment : request.getAttachments()) {
          if (attachment.getContentType().equals(request.getMediaType())) {
            attachments.add(attachment);
          }
        }

        if (StringUtils.hasContent(requestContent) && attachments.isEmpty()) {
          try {
            byte[] content =
                encoding == null ? requestContent.getBytes() : requestContent.getBytes(encoding);
            ((HttpEntityEnclosingRequest) httpMethod).setEntity(new ByteArrayEntity(content));
          } catch (UnsupportedEncodingException e) {
            ((HttpEntityEnclosingRequest) httpMethod)
                .setEntity(new ByteArrayEntity(requestContent.getBytes()));
          }
        } else if (attachments.size() > 0) {
          try {
            MimeMultipart mp = null;

            if (StringUtils.hasContent(requestContent)) {
              mp = new MimeMultipart();
              initRootPart(request, requestContent, mp);
            } else if (attachments.size() == 1) {
              ((HttpEntityEnclosingRequest) httpMethod)
                  .setEntity(new InputStreamEntity(attachments.get(0).getInputStream(), -1));

              httpMethod.setHeader(
                  "Content-Type", getContentTypeHeader(request.getMediaType(), encoding));
            }

            if (((HttpEntityEnclosingRequest) httpMethod).getEntity() == null) {
              if (mp == null) mp = new MimeMultipart();

              // init mimeparts
              AttachmentUtils.addMimeParts(request, attachments, mp, new StringToStringMap());

              // create request message
              MimeMessage message = new MimeMessage(AttachmentUtils.JAVAMAIL_SESSION);
              message.setContent(mp);
              message.saveChanges();
              RestRequestMimeMessageRequestEntity mimeMessageRequestEntity =
                  new RestRequestMimeMessageRequestEntity(message, request);
              ((HttpEntityEnclosingRequest) httpMethod).setEntity(mimeMessageRequestEntity);
              httpMethod.setHeader(
                  "Content-Type",
                  getContentTypeHeader(
                      mimeMessageRequestEntity.getContentType().getValue(), encoding));
              httpMethod.setHeader("MIME-Version", "1.0");
            }
          } catch (Exception e) {
            SoapUI.logError(e);
          }
        }
      }
    }
  }
  public void filterRequest(SubmitContext context, Request wsdlRequest) {
    HttpRequestBase httpMethod =
        (HttpRequestBase) context.getProperty(BaseHttpRequestTransport.HTTP_METHOD);
    URI tempUri = (URI) context.getProperty(BaseHttpRequestTransport.REQUEST_URI);
    java.net.URI uri = null;

    try {
      uri = new java.net.URI(tempUri.toString());
    } catch (URISyntaxException e) {
      SoapUI.logError(e);
    }

    if (uri == null) {
      uri = httpMethod.getURI();
    }

    if (uri == null) {
      return;
    }

    EndpointDefaults def = defaults.get(uri.toString());

    if (def == null) {
      synchronized (defaults) {
        for (String ep : defaults.keySet()) {
          try {
            URL tempUrl = new URL(PropertyExpander.expandProperties(context, ep));
            if (tempUrl.toString().equalsIgnoreCase(uri.toString())) {
              def = defaults.get(ep);
              break;
            }
          } catch (Exception e) {
            // we can hide this exception for now, it could happen for
            // invalid property-expansions, etc
            // if the endpoint really is wrong there will be other
            // exception later on
          }
        }

        if (wsdlRequest instanceof RestRequestInterface) {
          for (String ep : defaults.keySet()) {
            try {
              URL tempUrl = new URL(PropertyExpander.expandProperties(context, ep));
              if (tempUrl.getHost().toString().equalsIgnoreCase(uri.getHost().toString())) {
                def = defaults.get(ep);
                break;
              }
            } catch (Exception e) {
              // we can hide this exception for now, it could happen for
              // invalid property-expansions, etc
              // if the endpoint really is wrong there will be other
              // exception later on
            }
          }
        }
      }

      if (def == null) {
        return;
      }
    }

    applyDefaultsToWsdlRequest(context, (AbstractHttpRequestInterface<?>) wsdlRequest, def);
  }
Esempio n. 17
0
 public void abortRequest(SubmitContext submitContext) {
   HttpMethodBase postMethod = (HttpMethodBase) submitContext.getProperty(HTTP_METHOD);
   if (postMethod != null) postMethod.abort();
 }