Beispiel #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);
    }
  }
Beispiel #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());
    }
  }
Beispiel #3
0
  private void sendRequest(OutputStream out, XMLizable request, QName requestElement)
      throws IOException {
    XmlOutputStream xout = new XmlOutputStream(out, config.isPrettyPrintXml());
    xout.startDocument();

    xout.setPrefix("env", Constants.SOAP_ENVELOPE_NS);
    xout.setPrefix("xsd", Constants.SCHEMA_NS);
    xout.setPrefix("xsi", Constants.SCHEMA_INSTANCE_NS);

    xout.writeStartTag(Constants.SOAP_ENVELOPE_NS, "Envelope");

    if (headers.size() > 0) {
      writeHeaders(xout);
    }

    writeBody(xout, requestElement, request);

    xout.writeEndTag(Constants.SOAP_ENVELOPE_NS, "Envelope");

    xout.endDocument();
    xout.close();
  }