Exemplo n.º 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()));
  }
Exemplo n.º 2
0
  public void writeSchema(XMLStreamWriter out) throws XMLStreamException, JAXBException {
    out.writeStartElement("xsd", "schema", W3C_XML_SCHEMA_NS_URI);
    out.writeAttribute("version", "1.0");
    out.writeAttribute("targetNamespace", _namespace);
    out.writeNamespace(TARGET_NAMESPACE_PREFIX, _namespace);

    _context.generateSchemaWithoutHeader(out);

    for (AbstractAction action : _actionNames.values())
      action.writeSchema(out, _namespace, _context);

    out.writeEndElement(); // schema

    out.flush();
  }
Exemplo n.º 3
0
  /**
   * To be accurate, all of the actions must have been added before this method is run for the first
   * time.
   */
  public void generateWSDL() throws IOException, XMLStreamException, JAXBException {
    if (_wsdlGenerated) return;

    // We write to DOM so that we can pretty print it.  Since this only
    // happens once, it's not too much of a burden.
    DOMResult result = new DOMResult();
    XMLOutputFactory factory = getXMLOutputFactory();
    XMLStreamWriter out = factory.createXMLStreamWriter(result);

    out.writeStartDocument("UTF-8", "1.0");

    // <definitions>

    out.setDefaultNamespace(WSDL_NAMESPACE);
    out.writeStartElement(WSDL_NAMESPACE, "definitions");
    out.writeAttribute("targetNamespace", _namespace);
    out.writeAttribute("name", _serviceName);
    out.writeNamespace(TARGET_NAMESPACE_PREFIX, _namespace);
    out.writeNamespace("soap", _soapNamespaceURI);

    // <types>

    out.writeStartElement(WSDL_NAMESPACE, "types");

    if (_separateSchema) {
      out.writeStartElement(W3C_XML_SCHEMA_NS_URI, "schema");

      out.writeEmptyElement(W3C_XML_SCHEMA_NS_URI, "import");
      out.writeAttribute("namespace", _namespace);
      out.writeAttribute("schemaLocation", _serviceName + "_schema1.xsd");

      out.writeEndElement(); // schema
    } else writeSchema(out);

    out.writeEndElement(); // types

    // <messages>

    for (AbstractAction action : _actionNames.values())
      action.writeWSDLMessages(out, _soapNamespaceURI);

    // <portType>

    out.writeStartElement(WSDL_NAMESPACE, "portType");
    out.writeAttribute("name", _portType);

    for (AbstractAction action : _actionNames.values())
      action.writeWSDLOperation(out, _soapNamespaceURI);

    out.writeEndElement(); // portType

    // <binding>

    out.writeStartElement(WSDL_NAMESPACE, "binding");
    out.writeAttribute("name", _portName + "Binding");
    out.writeAttribute("type", TARGET_NAMESPACE_PREFIX + ':' + _portType);

    out.writeEmptyElement(_soapNamespaceURI, "binding");
    out.writeAttribute("transport", _soapTransport);
    out.writeAttribute("style", _soapStyle);

    for (AbstractAction action : _actionNames.values())
      action.writeWSDLBindingOperation(out, _soapNamespaceURI);

    out.writeEndElement(); // binding

    // <service>

    out.writeStartElement(WSDL_NAMESPACE, "service");
    out.writeAttribute("name", _serviceName);

    out.writeStartElement(WSDL_NAMESPACE, "port");
    out.writeAttribute("name", _portName);
    out.writeAttribute("binding", TARGET_NAMESPACE_PREFIX + ':' + _portName + "Binding");

    out.writeEmptyElement(_soapNamespaceURI, "address");
    out.writeAttribute("location", _wsdlLocation);

    out.writeEndElement(); // port

    out.writeEndElement(); // service

    out.writeEndElement(); // definitions

    _wsdlBuffer = new CharArrayWriter();

    XmlPrinter printer = new XmlPrinter(_wsdlBuffer);
    printer.setPrintDeclaration(true);
    printer.setStandalone("true");
    printer.printPrettyXml(result.getNode());

    _wsdlGenerated = true;
  }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
  public void addAction(Method method, AbstractAction action) {
    if (log.isLoggable(Level.FINER)) log.finer("Adding " + action + " to " + this);

    _actionNames.put(action.getInputName(), action);
    _actionMethods.put(method, action);
  }