directskeleton.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 699 行 · 第 1/2 页

JAVA
699
字号
    }    else if (attachments != null && attachments.size() > 0) {      Attachment body = attachments.get(0);      ByteArrayInputStream bais = new ByteArrayInputStream(body.getContents());      in = getXMLInputFactory().createXMLStreamReader(bais);      out = getXMLOutputFactory().createXMLStreamWriter(os);    }    else {      in = getXMLInputFactory().createXMLStreamReader(is);      out = getXMLOutputFactory().createXMLStreamWriter(os);    }    response.setStatus(invoke(service, in, out, attachments));    if (_handlerChain != null) {      Source source = new DOMSource(domResult.getNode());      _handlerChain.invokeServerOutbound(source, os);    }  }  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;  }  public void setSeparateSchema(boolean separateSchema)   {    if (_separateSchema != separateSchema) {      _separateSchema = separateSchema;      _wsdlGenerated = false;    }  }  public void dumpWSDL(OutputStream os)    throws IOException, XMLStreamException, JAXBException  {    OutputStreamWriter out = null;    try {      out = new OutputStreamWriter(os);      dumpWSDL(out);    }    finally {      if (out != null)        out.close();    }  }  public void dumpWSDL(Writer w)    throws IOException, XMLStreamException, JAXBException  {    generateWSDL();    _wsdlBuffer.writeTo(w);  }  /**   * 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;  }  public void dumpSchema(OutputStream os)    throws IOException, XMLStreamException, JAXBException  {    OutputStreamWriter out = null;    try {      out = new OutputStreamWriter(os);      dumpSchema(out);    }    finally {      if (out != null)        out.close();    }  }  public void dumpSchema(Writer w)    throws IOException, XMLStreamException, JAXBException  {    generateSchema();    _schemaBuffer.writeTo(w);  }  public void generateSchema()    throws IOException, XMLStreamException, JAXBException  {    if (_schemaGenerated)      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");    writeSchema(out);    _schemaBuffer = new CharArrayWriter();    XmlPrinter printer = new XmlPrinter(_schemaBuffer);    printer.setPrintDeclaration(true);    printer.setStandalone("true");    printer.printPrettyXml(result.getNode());        _schemaGenerated = true;  }  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();  }  /**   * Dumps a WSDL into the specified directory using the service name   * annotation if present.  (Mainly for TCK, wsgen)   */  public void dumpWSDL(String dir)    throws IOException, XMLStreamException, JAXBException  {    FileWriter wsdlOut = null;    FileWriter xsdOut = null;        try {      wsdlOut = new FileWriter(new File(dir, _serviceName + ".wsdl"));      dumpWSDL(wsdlOut);      if (_separateSchema) {        xsdOut = new FileWriter(new File(dir, _serviceName + "_schema1.xsd"));        dumpSchema(xsdOut);      }    }    finally {      if (wsdlOut != null)        wsdlOut.close();      if (xsdOut != null)        xsdOut.close();    }  }  public String toString()  {    return "DirectSkeleton[" + _api + "]";  }  private void writeClientFault(XMLStreamWriter out)    throws IOException, XMLStreamException, JAXBException  {    out.writeStartElement(SOAP_ENVELOPE_PREFIX, "Body", SOAP_ENVELOPE);    out.writeStartElement(Skeleton.SOAP_ENVELOPE_PREFIX,                           "Fault",                           Skeleton.SOAP_ENVELOPE);    out.writeStartElement("faultcode");    out.writeCharacters(Skeleton.SOAP_ENVELOPE_PREFIX + ":Client");    out.writeEndElement(); // faultcode    out.writeEndElement(); // Fault    out.writeEndElement(); // Body  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?