Пример #1
0
  /**
   * Creates a new empty <CODE>AttachmentPart</CODE> object. Note that the method <CODE>
   * addAttachmentPart</CODE> must be called with this new <CODE>AttachmentPart</CODE> object as the
   * parameter in order for it to become an attachment to this <CODE>SOAPMessage</CODE> object.
   *
   * @return a new <CODE>AttachmentPart</CODE> object that can be populated and added to this <CODE>
   *     SOAPMessage</CODE> object
   */
  public AttachmentPart createAttachmentPart() {
    if (!isAttachmentSupportEnabled(getMessageContext())) {
      throw new RuntimeException(Messages.getMessage("noAttachments"));
    }

    try {
      return (AttachmentPart) mAttachments.createAttachmentPart();
    } catch (AxisFault af) {
      log.error(Messages.getMessage("exception00"), af);
    }
    return null;
  }
Пример #2
0
 /**
  * Adds the given <CODE>AttachmentPart</CODE> object to this <CODE>SOAPMessage</CODE> object. An
  * <CODE>
  * AttachmentPart</CODE> object must be created before it can be added to a message.
  *
  * @param attachmentpart an <CODE>
  *     AttachmentPart</CODE> object that is to become part of this <CODE>SOAPMessage</CODE> object
  * @throws java.lang.IllegalArgumentException
  */
 public void addAttachmentPart(AttachmentPart attachmentpart) {
   try {
     mAttachments.addAttachmentPart((org.apache.axis.Part) attachmentpart);
   } catch (AxisFault af) {
     log.error(Messages.getMessage("exception00"), af);
   }
 }
Пример #3
0
  private static synchronized boolean isAttachmentSupportEnabled(MessageContext mc) {
    if (checkForAttachmentSupport) {
      // aviod testing and possibly failing everytime.
      checkForAttachmentSupport = false;
      try {
        // Get the default setting from AxisProperties
        String attachImpName =
            AxisProperties.getProperty(
                AxisEngine.PROP_ATTACHMENT_IMPLEMENTATION, AxisEngine.DEFAULT_ATTACHMENT_IMPL);
        // override the default with any changes specified in the engine configuration
        if (null != mc) {
          AxisEngine ae = mc.getAxisEngine();
          if (null != ae) {
            attachImpName = (String) ae.getOption(AxisEngine.PROP_ATTACHMENT_IMPLEMENTATION);
          }
        }

        /** Attempt to resolve class name, verify that these are present... */
        ClassUtils.forName("javax.activation.DataHandler");
        ClassUtils.forName("javax.mail.internet.MimeMultipart");

        attachImpl = ClassUtils.forName(attachImpName);

        attachmentSupportEnabled = true;
      } catch (ClassNotFoundException ex) {
        // no support for it, leave mAttachments null.
      } catch (java.lang.NoClassDefFoundError ex) {
        // no support for it, leave mAttachments null.
      } catch (java.lang.SecurityException ex) {
        // no support for it, leave mAttachments null.
      }
      log.debug(Messages.getMessage("attachEnabled") + "  " + attachmentSupportEnabled);
    }
    return attachmentSupportEnabled;
  }
Пример #4
0
 /**
  * Updates this <CODE>SOAPMessage</CODE> object with all the changes that have been made to it.
  * This method is called automatically when a message is sent or written to by the methods <CODE>
  * ProviderConnection.send</CODE>, <CODE>
  *   SOAPConnection.call</CODE>, or <CODE>
  *   SOAPMessage.writeTo</CODE>. However, if changes are made to a message that was received or to
  * one that has already been sent, the method <CODE>saveChanges</CODE> needs to be called
  * explicitly in order to save the changes. The method <CODE>saveChanges</CODE> also generates any
  * changes that can be read back (for example, a MessageId in profiles that support a message id).
  * All MIME headers in a message that is created for sending purposes are guaranteed to have valid
  * values only after <CODE>saveChanges</CODE> has been called.
  *
  * <p>In addition, this method marks the point at which the data from all constituent <CODE>
  * AttachmentPart</CODE> objects are pulled into the message.
  *
  * @throws SOAPException if there was a problem saving changes to this message.
  */
 public void saveChanges() throws SOAPException {
   headers.removeHeader("Content-Length");
   if (mAttachments != null && 0 < mAttachments.getAttachmentCount()) {
     try {
       headers.setHeader("Content-Type", mAttachments.getContentType());
     } catch (AxisFault af) {
       log.error(Messages.getMessage("exception00"), af);
     }
   }
   saveRequired = false;
   try {
     /* Fix for Bug 16418 - Start from scratch */
     mSOAPPart.saveChanges();
   } catch (AxisFault axisFault) {
     log.error(Messages.getMessage("exception00"), axisFault);
   }
 }
  /**
   * Creates a socket.
   *
   * @param host
   * @param port
   * @param otherHeaders
   * @param useFullURL
   * @return Socket
   * @throws Exception
   */
  public Socket create(String host, int port, StringBuffer otherHeaders, BooleanHolder useFullURL)
      throws Exception {

    int timeout = 0;
    if (attributes != null) {
      String value = (String) attributes.get(CONNECT_TIMEOUT);
      timeout = (value != null) ? Integer.parseInt(value) : 0;
    }

    TransportClientProperties tcp = TransportClientPropertiesFactory.create("http");

    Socket sock = null;
    boolean hostInNonProxyList = isHostInNonProxyList(host, tcp.getNonProxyHosts());

    if (tcp.getProxyUser().length() != 0) {
      StringBuffer tmpBuf = new StringBuffer();

      tmpBuf.append(tcp.getProxyUser()).append(":").append(tcp.getProxyPassword());
      otherHeaders
          .append(HTTPConstants.HEADER_PROXY_AUTHORIZATION)
          .append(": Basic ")
          .append(Base64.encode(tmpBuf.toString().getBytes()))
          .append("\r\n");
    }
    if (port == -1) {
      port = 80;
    }
    if ((tcp.getProxyHost().length() == 0)
        || (tcp.getProxyPort().length() == 0)
        || hostInNonProxyList) {
      sock = create(host, port, timeout);
      if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("createdHTTP00"));
      }
    } else {
      sock = create(tcp.getProxyHost(), new Integer(tcp.getProxyPort()).intValue(), timeout);
      if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("createdHTTP01", tcp.getProxyHost(), tcp.getProxyPort()));
      }
      useFullURL.value = true;
    }
    return sock;
  }
Пример #6
0
 /**
  * Retrieves all the <CODE>AttachmentPart</CODE> objects that are part of this <CODE>SOAPMessage
  * </CODE> object.
  *
  * @return an iterator over all the attachments in this message
  */
 public Iterator getAttachments() {
   try {
     if (mAttachments != null && 0 != mAttachments.getAttachmentCount()) {
       return mAttachments.getAttachments().iterator();
     }
   } catch (AxisFault af) {
     log.error(Messages.getMessage("exception00"), af);
   }
   return Collections.EMPTY_LIST.iterator();
 }
Пример #7
0
 /**
  * Writes this <CODE>SOAPMessage</CODE> object to the given output stream. The externalization
  * format is as defined by the SOAP 1.1 with Attachments specification.
  *
  * <p>If there are no attachments, just an XML stream is written out. For those messages that have
  * attachments, <CODE>writeTo</CODE> writes a MIME-encoded byte stream.
  *
  * @param os the <CODE>OutputStream</CODE> object to which this <CODE>SOAPMessage</CODE> object
  *     will be written
  * @throws SOAPException if there was a problem in externalizing this SOAP message
  * @throws IOException if an I/O error occurs
  */
 public void writeTo(java.io.OutputStream os) throws SOAPException, IOException {
   // Do it the old fashion way.
   if (getSendType() == Attachments.SEND_TYPE_NONE
       || mAttachments == null
       || 0 == mAttachments.getAttachmentCount()) {
     try {
       String charEncoding = XMLUtils.getEncoding(this, msgContext);
       ;
       mSOAPPart.setEncoding(charEncoding);
       mSOAPPart.writeTo(os);
     } catch (java.io.IOException e) {
       log.error(Messages.getMessage("javaIOException00"), e);
     }
   } else {
     try {
       mAttachments.writeContentToStream(os);
     } catch (java.lang.Exception e) {
       log.error(Messages.getMessage("exception00"), e);
     }
   }
 }
  /**
   * Check if the specified host is in the list of non proxy hosts.
   *
   * @param host host name
   * @param nonProxyHosts string containing the list of non proxy hosts
   * @return true/false
   */
  protected boolean isHostInNonProxyList(String host, String nonProxyHosts) {

    if ((nonProxyHosts == null) || (host == null)) {
      return false;
    }

    /*
     * The http.nonProxyHosts system property is a list enclosed in
     * double quotes with items separated by a vertical bar.
     */
    StringTokenizer tokenizer = new StringTokenizer(nonProxyHosts, "|\"");

    while (tokenizer.hasMoreTokens()) {
      String pattern = tokenizer.nextToken();

      if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("match00", new String[] {"HTTPSender", host, pattern}));
      }
      if (match(pattern, host, false)) {
        return true;
      }
    }
    return false;
  }
Пример #9
0
  /**
   * 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);
  }
 /**
  * The registerValueTarget code above causes this set function to be invoked when each value is
  * known.
  *
  * @param value is the value of an element
  * @param hint is the key
  */
 public void setChildValue(Object value, Object hint) throws SAXException {
   if (log.isDebugEnabled()) {
     log.debug(Messages.getMessage("gotValue00", "MapDeserializer", "" + value));
   }
   ((Map) this.value).put(hint, value);
 }
Пример #11
0
 /*      */ public static QName getOperationQName(
     BindingOperation bindingOper, BindingEntry bEntry, SymbolTable symbolTable)
       /*      */ {
   /*  813 */ Operation operation = bindingOper.getOperation();
   /*  814 */ String operationName = operation.getName();
   /*      */
   /*  821 */ if ((bEntry.getBindingStyle() == Style.DOCUMENT) && (symbolTable.isWrapped()))
   /*      */ {
     /*  823 */ Input input = operation.getInput();
     /*      */
     /*  825 */ if (input != null) {
       /*  826 */ Map parts = input.getMessage().getParts();
       /*      */
       /*  828 */ if ((parts != null) && (!parts.isEmpty())) {
         /*  829 */ Iterator i = parts.values().iterator();
         /*  830 */ Part p = (Part) i.next();
         /*      */
         /*  832 */ return p.getElementName();
         /*      */ }
       /*      */ }
     /*      */ }
   /*      */
   /*  837 */ String ns = null;
   /*      */
   /*  842 */ BindingInput bindInput = bindingOper.getBindingInput();
   /*      */
   /*  844 */ if (bindInput != null) {
     /*  845 */ Iterator it = bindInput.getExtensibilityElements().iterator();
     /*      */
     /*  847 */ while (it.hasNext()) {
       /*  848 */ ExtensibilityElement elem = (ExtensibilityElement) it.next();
       /*      */
       /*  850 */ if ((elem instanceof SOAPBody)) {
         /*  851 */ SOAPBody body = (SOAPBody) elem;
         /*      */
         /*  853 */ ns = body.getNamespaceURI();
         /*  854 */ if ((bEntry.getInputBodyType(operation) != Use.ENCODED)
             || ((ns != null) && (ns.length() != 0))) break;
         /*  855 */ log.warn(
             Messages.getMessage(
                 "badNamespaceForOperation00", bEntry.getName(), operation.getName()));
         break;
         /*      */ }
       /*      */
       /*  861 */ if ((elem instanceof MIMEMultipartRelated)) {
         /*  862 */ Object part = null;
         /*  863 */ MIMEMultipartRelated mpr = (MIMEMultipartRelated) elem;
         /*      */
         /*  865 */ List l = mpr.getMIMEParts();
         /*      */
         /*  868 */ int j = 0;
         /*  869 */ while ((l != null) && (j < l.size()) && (part == null))
         /*      */ {
           /*  871 */ MIMEPart mp = (MIMEPart) l.get(j);
           /*      */
           /*  873 */ List ll = mp.getExtensibilityElements();
           /*      */
           /*  876 */ int k = 0;
           /*  877 */ for (; (ll != null) && (k < ll.size()) && (part == null); k++) {
             /*  878 */ part = ll.get(k);
             /*      */
             /*  880 */ if ((part instanceof SOAPBody)) {
               /*  881 */ SOAPBody body = (SOAPBody) part;
               /*      */
               /*  883 */ ns = body.getNamespaceURI();
               /*  884 */ if ((bEntry.getInputBodyType(operation) != Use.ENCODED)
                   || ((ns != null) && (ns.length() != 0))) break;
               /*  885 */ log.warn(
                   Messages.getMessage(
                       "badNamespaceForOperation00", bEntry.getName(), operation.getName()));
               break;
               /*      */ }
             /*      */
             /*  892 */ part = null;
             /*      */ }
           /*  870 */ j++;
           /*      */ }
         /*      */
         /*      */ }
       /*  896 */ else if ((elem instanceof UnknownExtensibilityElement))
       /*      */ {
         /*  899 */ UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) elem;
         /*      */
         /*  901 */ QName name = unkElement.getElementType();
         /*      */
         /*  904 */ if ((name.getNamespaceURI().equals("http://schemas.xmlsoap.org/wsdl/soap12/"))
             && (name.getLocalPart().equals("body")))
         /*      */ {
           /*  906 */ ns = unkElement.getElement().getAttribute("namespace");
           /*      */ }
         /*      */
         /*      */ }
       /*      */
       /*      */ }
     /*      */
     /*      */ }
   /*      */
   /*  916 */ if (ns == null) {
     /*  917 */ ns = "";
     /*      */ }
   /*      */
   /*  920 */ return new QName(ns, operationName);
   /*      */ }