コード例 #1
0
ファイル: Message.java プロジェクト: hugosato/apache-axis
  /**
   * Do the work of construction.
   *
   * @param initialContents may be String, byte[], InputStream, SOAPEnvelope, or AxisFault
   * @param bodyInStream is true if initialContents is an InputStream containing just the SOAP body
   *     (no SOAP-ENV)
   * @param contentType this if the contentType has been already determined (as in the case of
   *     servlets)
   * @param contentLocation the location of the content
   * @param mimeHeaders mime headers for attachments
   */
  private void setup(
      Object initialContents,
      boolean bodyInStream,
      String contentType,
      String contentLocation,
      javax.xml.soap.MimeHeaders mimeHeaders) {

    if (contentType == null && mimeHeaders != null) {
      String contentTypes[] = mimeHeaders.getHeader("Content-Type");
      contentType = (contentTypes != null) ? contentTypes[0] : null;
    }
    if (contentLocation == null && mimeHeaders != null) {
      String contentLocations[] = mimeHeaders.getHeader("Content-Location");
      contentLocation = (contentLocations != null) ? contentLocations[0] : null;
    }
    if (contentType != null) {
      int delimiterIndex = contentType.lastIndexOf("charset");
      if (delimiterIndex > 0) {
        String charsetPart = contentType.substring(delimiterIndex);
        int delimiterIndex2 = charsetPart.indexOf(';');
        if (delimiterIndex2 != -1) {
          charsetPart = charsetPart.substring(0, delimiterIndex2);
        }
        int charsetIndex = charsetPart.indexOf('=');
        String charset = charsetPart.substring(charsetIndex + 1).trim();
        if ((charset.startsWith("\"") || charset.startsWith("\'"))) {
          charset = charset.substring(1, charset.length());
        }
        if ((charset.endsWith("\"") || charset.endsWith("\'"))) {
          charset = charset.substring(0, charset.length() - 1);
        }
        try {
          setProperty(SOAPMessage.CHARACTER_SET_ENCODING, charset);
        } catch (SOAPException e) {
        }
      }
    }
    // Try to construct an AttachmentsImpl object for attachment
    // functionality.
    // If there is no org.apache.axis.attachments.AttachmentsImpl class,
    // it must mean activation.jar is not present and attachments are not
    // supported.
    if (isAttachmentSupportEnabled(getMessageContext())) {
      // Construct one, and cast to Attachments.
      // There must be exactly one constructor of AttachmentsImpl, which
      // must take an org.apache.axis.Message!
      Constructor attachImplConstr = attachImpl.getConstructors()[0];
      try {
        mAttachments =
            (Attachments)
                attachImplConstr.newInstance(
                    new Object[] {initialContents, contentType, contentLocation});

        // If it can't support it, it wont have a root part.
        mSOAPPart = (SOAPPart) mAttachments.getRootPart();
      } catch (InvocationTargetException ex) {
        log.fatal(Messages.getMessage("invocationTargetException00"), ex);
        throw new RuntimeException(ex.getMessage());
      } catch (InstantiationException ex) {
        log.fatal(Messages.getMessage("instantiationException00"), ex);
        throw new RuntimeException(ex.getMessage());
      } catch (IllegalAccessException ex) {
        log.fatal(Messages.getMessage("illegalAccessException00"), ex);
        throw new RuntimeException(ex.getMessage());
      }
    } else if (contentType != null && contentType.startsWith("multipart")) {
      throw new RuntimeException(Messages.getMessage("noAttachments"));
    }

    // text/xml
    if (null == mSOAPPart) {
      mSOAPPart = new SOAPPart(this, initialContents, bodyInStream);
    } else mSOAPPart.setMessage(this);

    // The stream was not determined by a more complex type so default to
    if (mAttachments != null) mAttachments.setRootPart(mSOAPPart);

    headers = (mimeHeaders == null) ? new MimeHeaders() : new MimeHeaders(mimeHeaders);
  }