コード例 #1
0
 private DOMSource toDOMSource(Source source) throws Exception {
   if (source instanceof DOMSource) {
     return (DOMSource) source;
   }
   Transformer trans = TransformerFactory.newInstance().newTransformer();
   DOMResult result = new DOMResult();
   trans.transform(source, result);
   return new DOMSource(result.getNode());
 }
  /** Invoke the handler chain for an inbound message. */
  public boolean invokeInbound(InputStream in, Map<String, DataHandler> attachments)
      throws WebServiceException {
    _outbound = false;
    _source = null;

    try {
      DOMResult dom = new DOMResult();
      getTransformer().transform(new StreamSource(in), dom);

      // XXX The TCK seems to assume a source that will stand up to repeated
      // reads... meaning that StreamSource and SAXSource are out, so DOM
      // must be what they want.
      _source = new DOMSource(dom.getNode());
    } catch (Exception e) {
      throw new WebServiceException(e);
    }

    // Set the mandatory properties
    _logicalContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.FALSE);
    _soapContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.FALSE);

    _logicalContext.put(INBOUND_MESSAGE_ATTACHMENTS, attachments);
    _soapContext.put(INBOUND_MESSAGE_ATTACHMENTS, attachments);

    // NOTE: the order is reversed for inbound messages
    for (_i = _chain.size() - 1; _i >= 0; _i--) {
      boolean success = handleMessage(_i);

      if (_protocolException != null) return false;

      if (_runtimeException != null) return false;

      if (!success) return false;
    }

    return true;
  }