Esempio n. 1
0
  public XMLizable send(
      String soapAction,
      QName requestElement,
      XMLizable request,
      QName responseElement,
      Class responseType)
      throws ConnectionException {

    long startTime = System.currentTimeMillis();

    try {
      boolean firstTime = true;
      while (true) {
        try {
          Transport transport = newTransport(config);
          OutputStream out = transport.connect(url, soapAction);
          sendRequest(out, request, requestElement);
          InputStream in = transport.getContent();
          XMLizable result;
          result = receive(transport, responseElement, responseType, in);
          return result;
        } catch (SessionTimedOutException se) {
          if (config.getSessionRenewer() == null || !firstTime) {
            throw (ConnectionException) se.getCause();
          } else {
            SessionRenewer.SessionRenewalHeader sessionHeader =
                config.getSessionRenewer().renewSession(config);
            if (sessionHeader != null) {
              addHeader(sessionHeader.name, sessionHeader.headerElement);
            }
          }
        }
        firstTime = false;
      }
    } catch (SocketTimeoutException e) {
      long timeTaken = System.currentTimeMillis() - startTime;
      throw new ConnectionException(
          "Request to "
              + url
              + " timed out. TimeTaken="
              + timeTaken
              + " ConnectionTimeout="
              + config.getConnectionTimeout()
              + " ReadTimeout="
              + config.getReadTimeout(),
          e);

    } catch (IOException e) {
      throw new ConnectionException("Failed to send request to " + url, e);
    }
  }
Esempio n. 2
0
  private Transport newTransport(ConnectorConfig config) throws ConnectionException {
    if (config.getTransportFactory() != null) {
      Transport t = config.getTransportFactory().createTransport();
      t.setConfig(config);
      return t;
    }

    try {
      Transport t = (Transport) config.getTransport().newInstance();
      t.setConfig(config);
      return t;
    } catch (InstantiationException e) {
      throw new ConnectionException("Failed to create new Transport " + config.getTransport());
    } catch (IllegalAccessException e) {
      throw new ConnectionException("Failed to create new Transport " + config.getTransport());
    }
  }
Esempio n. 3
0
  private XMLizable receive(
      Transport transport, QName responseElement, Class responseType, InputStream in)
      throws IOException, ConnectionException {

    XMLizable result;

    try {

      XmlInputStream xin = new XmlInputStream();
      xin.setInput(in, "UTF-8");

      if (transport.isSuccessful()) {
        result = bind(xin, responseElement, responseType);
      } else {
        throw createException(xin);
      }
    } catch (PullParserException e) {
      throw new ConnectionException("Failed to create/parse xml input stream ", e);
    } finally {
      in.close();
    }

    return result;
  }