예제 #1
0
  /** Invokes the request on a remote object using an outbound XML stream. */
  public Object invoke(Method method, String url, Object[] args, HandlerChainInvoker handlerChain)
      throws IOException, XMLStreamException, MalformedURLException, JAXBException, Throwable {
    AbstractAction action = _actionMethods.get(method);

    if (action != null) return action.invoke(url, args, handlerChain);
    else if ("toString".equals(method.getName()))
      return "SoapStub[" + (_api != null ? _api.getName() : "") + "]";
    else throw new RuntimeException(L.l("not a web method: {0}", method.getName()));
  }
예제 #2
0
  private int invoke(
      Object service, XMLStreamReader in, XMLStreamWriter out, List<Attachment> attachments)
      throws IOException, XMLStreamException, Throwable {
    in.nextTag();

    // XXX Namespace
    in.require(XMLStreamReader.START_ELEMENT, null, "Envelope");

    in.nextTag();

    XMLStreamReader header = null;

    if ("Header".equals(in.getName().getLocalPart())) {
      in.nextTag();

      XMLOutputFactory outputFactory = getXMLOutputFactory();
      CharArrayWriter writer = new CharArrayWriter();
      StreamResult result = new StreamResult(writer);
      XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(result);

      StaxUtil.copyReaderToWriter(in, xmlWriter);

      CharArrayReader reader = new CharArrayReader(writer.toCharArray());

      XMLInputFactory inputFactory = getXMLInputFactory();
      header = inputFactory.createXMLStreamReader(reader);

      in.nextTag();
    }

    // XXX Namespace?
    in.require(XMLStreamReader.START_ELEMENT, null, "Body");

    in.nextTag();

    String actionName = in.getName().getLocalPart();

    // services/1318: special corner case where no method name is given
    // May happen with Document BARE methods w/no arguments
    if ("Body".equals(actionName) && in.getEventType() == in.END_ELEMENT) actionName = "";

    out.writeStartDocument("UTF-8", "1.0");
    out.writeStartElement(SOAP_ENVELOPE_PREFIX, "Envelope", SOAP_ENVELOPE);
    out.writeNamespace(SOAP_ENVELOPE_PREFIX, SOAP_ENVELOPE);
    // out.writeNamespace("xsi", XMLNS_XSI);
    out.writeNamespace("xsd", XMLNS_XSD);

    AbstractAction action = _actionNames.get(actionName);

    // XXX: exceptions<->faults
    int responseCode = 500;

    if (action != null) responseCode = action.invoke(service, header, in, out, attachments);
    else {
      // skip the unknown action
      while (in.getEventType() != in.END_ELEMENT || !"Body".equals(in.getName().getLocalPart()))
        in.nextTag();

      writeClientFault(out);
    }

    // XXX Namespace?
    in.require(XMLStreamReader.END_ELEMENT, null, "Body");
    in.nextTag();
    in.require(XMLStreamReader.END_ELEMENT, null, "Envelope");

    out.writeEndElement(); // Envelope

    out.flush();

    return responseCode;
  }