public Message copy() {
    try {
      // copy the payload
      XMLStreamReader clone;
      XMLStreamReader clonedReader;

      if (hasPayload()) {
        assert unconsumed();
        consumedAt = null; // but we don't want to mark it as consumed
        MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();

        // the boolean value tells the first body part is written.
        // based on this we do the right thing
        StreamReaderBufferCreator c = new StreamReaderBufferCreator(xsb);
        while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
          String name = reader.getLocalName();
          String nsUri = reader.getNamespaceURI();
          if (name.equals("Body") && nsUri.equals(soapVersion.nsUri)
              || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT)) {
            break;
          }
          c.create(reader);
        }
        XMLStreamReaderFactory.recycle(reader);

        reader = xsb.readAsXMLStreamReader();
        reader = new VerifiedMessageXMLStreamReader(reader, bodyEnvNs);
        clone = xsb.readAsXMLStreamReader();
        clonedReader = new VerifiedMessageXMLStreamReader(clone, bodyEnvNs);
        // advance to the start tag of the first element
        proceedToRootElement(reader);
        proceedToRootElement(clonedReader);
      } else {
        // it's tempting to use EmptyMessageImpl, but it doesn't presere the infoset
        // of <envelope>,<header>, and <body>, so we need to stick to StreamMessage.
        clone = reader;
        clonedReader = reader;
      }

      return new VerifiedStreamMessage(
          envelopeTag,
          headerTag,
          attachmentSet,
          HeaderList.copy(headers),
          bodyTag,
          clone,
          soapVersion,
          this.bodyEnvNs);
    } catch (XMLStreamException e) {
      throw new WebServiceException("Failed to copy a message", e);
    }
  }
예제 #2
0
 public void XtestNamespaceAsLastItem1() throws Exception {
   MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
   XMLStreamWriter w = xsb.createFromXMLStreamWriter(); // new StreamWriterBufferCreator(xsb);
   w.writeStartElement("p1", "tag", "ns1");
   w.writeAttribute("a", "x");
   w.writeNamespace("p", "ns");
   w.writeEndElement();
   XMLStreamReader xr = xsb.readAsXMLStreamReader();
   boolean tested = false;
   while (xr.hasNext()) {
     int i = xr.next();
     //            if (xr.isStartElement() && xr.getLocalName().equals("tag")) {
     //                assertEquals(1,xr.getAttributeCount());
     //                assertEquals("ns",xr.getNamespaceURI("p"));
     //                tested = true;
     //            }
   }
   //        assertTrue(tested);
 }
  private void cacheMessage() {

    if (buffer == null) {
      try {
        buffer = new com.sun.xml.stream.buffer.MutableXMLStreamBuffer();
        buffer.createFromXMLStreamReader(reader);
      } catch (javax.xml.stream.XMLStreamException ex) {
        logger.log(Level.SEVERE, LogStringsMessages.WSS_1611_PROBLEM_CACHING(), ex);
        throw new com.sun.xml.wss.impl.XWSSecurityRuntimeException(ex);
      }

      try {
        reader = buffer.readAsXMLStreamReader();
        reader = new VerifiedMessageXMLStreamReader(reader, bodyEnvNs);
        reader.next();
      } catch (XMLStreamException ex) {
        logger.log(Level.SEVERE, LogStringsMessages.WSS_1612_ERROR_READING_BUFFER(), ex);
        throw new com.sun.xml.wss.impl.XWSSecurityRuntimeException(ex);
      }
    }
  }