private void serializeRuntimeException() throws WebServiceException {
    try {
      MessageFactory factory = _soapContext.getMessageFactory();
      SOAPMessage message = factory.createMessage();

      QName faultcode =
          new QName(
              message.getSOAPBody().getNamespaceURI(), "Server", message.getSOAPBody().getPrefix());

      message.getSOAPBody().addFault(faultcode, _runtimeException.getMessage());

      _soapContext.setMessage(message);
      _source = _soapContext.getMessage().getSOAPPart().getContent();
    } catch (SOAPException se) {
      throw new WebServiceException(se);
    }
  }
  private boolean handleFault(int i) {
    Handler handler = _chain.get(i);

    boolean success = false;
    _invoked[i] = true;

    try {
      if (handler instanceof LogicalHandler) {
        _logicalContext.getMessage().setPayload(_source);
        success = handler.handleFault(_logicalContext);
        _source = _logicalContext.getMessage().getPayload();
      } else if (handler instanceof SOAPHandler) {
        try {
          _soapContext.setMessage(_source);
          success = handler.handleFault(_soapContext);
          _source = _soapContext.getMessage().getSOAPPart().getContent();
        } catch (SOAPException e) {
          throw new WebServiceException(e);
        }
      } else {
        throw new WebServiceException(
            L.l("Unsupported Handler type: {0}", handler.getClass().getName()));
      }

      _protocolException = null;
    } catch (ProtocolException e) {
      _protocolException = e;
      serializeProtocolException();
    } catch (RuntimeException e) {
      _runtimeException = e;
      serializeRuntimeException();
    }

    return success;
  }
  private void importAppProperties(boolean request) {
    if (_bindingProvider == null) return;

    if (request) {
      _logicalContext.putAll(_bindingProvider.getRequestContext(), Scope.APPLICATION);
      _soapContext.putAll(_bindingProvider.getRequestContext(), Scope.APPLICATION);
    } else {
      _logicalContext.putAll(_bindingProvider.getResponseContext(), Scope.APPLICATION);
      _soapContext.putAll(_bindingProvider.getResponseContext(), Scope.APPLICATION);
    }
  }
  public void reverseDirection() {
    Boolean direction = (Boolean) _logicalContext.get(MESSAGE_OUTBOUND_PROPERTY);

    if (direction != null) {
      if (Boolean.TRUE.equals(direction)) {
        _logicalContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.FALSE);
        _soapContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.FALSE);
      } else {
        _logicalContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.TRUE);
        _soapContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.TRUE);
      }
    }
  }
  private void serializeProtocolException() throws WebServiceException {
    if (_protocolException instanceof SOAPFaultException) {
      SOAPFaultException sfe = (SOAPFaultException) _protocolException;
      SOAPFault fault = sfe.getFault();

      try {
        MessageFactory factory = _soapContext.getMessageFactory();
        SOAPMessage message = factory.createMessage();
        message.getSOAPBody().addChildElement(fault);
        _soapContext.setMessage(message);
        _source = _soapContext.getMessage().getSOAPPart().getContent();
      } catch (SOAPException se) {
        throw new WebServiceException(se);
      }
    } else {
      throw new WebServiceException(L.l("Unsupported ProtocolException: {0}", _protocolException));
    }
  }
  private void exportAppProperties(boolean request) {
    if (_bindingProvider == null) return;

    if (request) {
      Map<String, Object> map = null;

      map = _logicalContext.getScopedSubMap(Scope.APPLICATION);
      _bindingProvider.getRequestContext().putAll(map);

      map = _soapContext.getScopedSubMap(Scope.APPLICATION);
      _bindingProvider.getRequestContext().putAll(map);
    } else {
      Map<String, Object> map = null;

      map = _logicalContext.getScopedSubMap(Scope.APPLICATION);
      _bindingProvider.getResponseContext().putAll(map);

      map = _soapContext.getScopedSubMap(Scope.APPLICATION);
      _bindingProvider.getResponseContext().putAll(map);
    }
  }
  private void close(int i) {
    Handler handler = _chain.get(i);

    if (!_invoked[i]) return;

    _invoked[i] = false;

    if (handler instanceof LogicalHandler) {
      _logicalContext.getMessage().setPayload(_source);
      handler.close(_logicalContext);
      _source = _logicalContext.getMessage().getPayload();
    } else if (handler instanceof SOAPHandler) {
      try {
        _soapContext.setMessage(_source);
        handler.close(_soapContext);
        _source = _soapContext.getMessage().getSOAPPart().getContent();
      } catch (SOAPException e) {
        throw new WebServiceException(e);
      }
    }
  }
  public void prepare(Map<String, Object> httpProperties, boolean request) {
    _logicalContext = new LogicalMessageContextImpl();
    _soapContext = new SOAPMessageContextImpl();
    _runtimeException = null;
    _protocolException = null;
    _request = request;

    _logicalContext.putAll(httpProperties);
    _soapContext.putAll(httpProperties);

    importAppProperties(request);
  }
  /** Invoke the handler chain for an outbound message. */
  public boolean invokeOutbound(Source source, Map<String, DataHandler> attachments)
      throws WebServiceException {
    _source = source;

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

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

    for (_i = 0; _i < _chain.size(); _i++) {
      boolean success = handleMessage(_i);

      if (_protocolException != null) return false;

      if (_runtimeException != null) return false;

      if (!success) return false;
    }

    return true;
  }
Ejemplo n.º 10
0
 protected QName getOpQName(Exchange ex, Object data) {
   SOAPMessageContextImpl sm = (SOAPMessageContextImpl) data;
   try {
     SOAPMessage msg = sm.getMessage();
     if (msg == null) {
       return null;
     }
     SOAPBody body = msg.getSOAPBody();
     if (body == null) {
       return null;
     }
     org.w3c.dom.Node nd = body.getFirstChild();
     while (nd != null && !(nd instanceof org.w3c.dom.Element)) {
       nd = nd.getNextSibling();
     }
     if (nd != null) {
       return new QName(nd.getNamespaceURI(), nd.getLocalName());
     }
   } catch (SOAPException e) {
     // ignore, nothing we can do
   }
   return null;
 }
  /** 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;
  }
Ejemplo n.º 12
0
  @Override
  protected MessageContext createProtocolMessageContext(SoapMessage message) {
    SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message);

    Exchange exch = message.getExchange();
    setupBindingOperationInfo(exch, sm);
    SOAPMessage msg = sm.getMessage();
    try {
      List<SOAPElement> params = new ArrayList<SOAPElement>();
      message.put(MessageContext.REFERENCE_PARAMETERS, params);
      SOAPHeader head = msg.getSOAPHeader();
      if (head != null) {
        Iterator<Node> it = CastUtils.cast(head.getChildElements());
        while (it != null && it.hasNext()) {
          Node nd = it.next();
          if (nd instanceof SOAPElement) {
            SOAPElement el = (SOAPElement) nd;
            if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")
                && ("1".equals(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter"))
                    || Boolean.parseBoolean(
                        el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")))) {
              params.add(el);
            }
          }
        }
      }
      if (msg.getSOAPPart().getEnvelope().getBody() != null
          && msg.getSOAPPart().getEnvelope().getBody().hasFault()) {
        return null;
      }
    } catch (SOAPException e) {
      throw new Fault(e);
    }

    return sm;
  }
  /**
   * When a message direction is reversed within the chain, this method runs the message backwards
   * through the previous handlers. This method should only be invoked when a handler returns false,
   * but does not throw any kind of exception.
   */
  public boolean uninvokeInbound() throws WebServiceException {
    // Set the mandatory properties
    _logicalContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.TRUE);
    _soapContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.TRUE);

    for (_i++; _i < _chain.size(); _i++) {
      boolean success = handleMessage(_i);

      if (_protocolException != null) return false;

      if (_runtimeException != null) return false;

      if (!success) return false;
    }

    return true;
  }
  /**
   * When a message direction is reversed within the chain, this method runs the message backwards
   * through the previous handlers. This method should only be invoked when a handler returns false,
   * but does not throw any kind of exception.
   */
  public boolean uninvokeOutbound() throws WebServiceException {
    // Set the mandatory properties
    _logicalContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.FALSE);
    _soapContext.put(MESSAGE_OUTBOUND_PROPERTY, Boolean.FALSE);

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

      if (_protocolException != null) return false;

      if (_runtimeException != null) return false;

      if (!success) return false;
    }

    return true;
  }