Пример #1
0
  protected void writeStartElementWithNS(String namespaceURI, String localname)
      throws XMLStreamException {

    if (namespaceURI == null || namespaceURI.length() == 0) {
      writer.writeStartElement(localname);
    } else {
      if (writer.getNamespaceContext().getPrefix(namespaceURI) == null) {
        String prefix = nsToPrefix.get(namespaceURI);
        if (prefix != null) {
          writer.writeStartElement(prefix, localname, namespaceURI);
          writer.writeNamespace(prefix, namespaceURI);
        } else {
          nsToPrefix.put("ns" + ++prefixIndex, namespaceURI);
          LOG.warn(
              "No prefix for namespace '{}' configured. Using {}.",
              namespaceURI,
              "ns" + prefixIndex);
          writer.writeStartElement(prefix, localname, namespaceURI);
          writer.writeNamespace(prefix, namespaceURI);
        }
      } else {
        writer.writeStartElement(namespaceURI, localname);
      }
    }
  }
  /** Register a namespace prefix */
  private java.lang.String registerPrefix(
      javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace)
      throws javax.xml.stream.XMLStreamException {
    java.lang.String prefix = xmlWriter.getPrefix(namespace);

    if (prefix == null) {
      prefix = generatePrefix(namespace);

      javax.xml.namespace.NamespaceContext nsContext = xmlWriter.getNamespaceContext();

      while (true) {
        java.lang.String uri = nsContext.getNamespaceURI(prefix);

        if ((uri == null) || (uri.length() == 0)) {
          break;
        }

        prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
      }

      xmlWriter.writeNamespace(prefix, namespace);
      xmlWriter.setPrefix(prefix, namespace);
    }

    return prefix;
  }
Пример #3
0
 public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
   try {
     // Get output stream and use JAXB UTF-8 writer
     OutputStream os = XMLStreamWriterUtil.getOutputStream(sw);
     if (os != null) {
       bridge.marshal(jaxbObject, os, sw.getNamespaceContext());
     } else {
       bridge.marshal(jaxbObject, sw);
     }
   } catch (JAXBException e) {
     throw new XMLStreamException2(e);
   }
 }
 /** Register a namespace prefix */
 private java.lang.String registerPrefix(
     javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace)
     throws javax.xml.stream.XMLStreamException {
   java.lang.String prefix = xmlWriter.getPrefix(namespace);
   if (prefix == null) {
     prefix = generatePrefix(namespace);
     while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
       prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
     }
     xmlWriter.writeNamespace(prefix, namespace);
     xmlWriter.setPrefix(prefix, namespace);
   }
   return prefix;
 }
Пример #5
0
  @SuppressWarnings("unused")
  private String registerPrefix(final XMLStreamWriter xmlWriter, final String namespace)
      throws XMLStreamException {
    String prefix = xmlWriter.getPrefix(namespace);
    if (prefix == null) {
      prefix = GetStatus.generatePrefix(namespace);
      while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
        prefix = BeanUtil.getUniquePrefix();
      }
      xmlWriter.writeNamespace(prefix, namespace);
      xmlWriter.setPrefix(prefix, namespace);
    }

    return prefix;
  }
  private String registerPrefix(final XMLStreamWriter xmlWriter, final String namespace)
      throws XMLStreamException {
    String prefix = xmlWriter.getPrefix(namespace);
    if (prefix == null) {
      prefix = OperationRequestType.generatePrefix(namespace);
      while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
        prefix = BeanUtil.getUniquePrefix();
      }

      xmlWriter.writeNamespace(prefix, namespace);
      xmlWriter.setPrefix(prefix, namespace);
    }

    return prefix;
  }
 public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
   try {
     AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachmentSet);
     // Get output stream and use JAXB UTF-8 writer
     OutputStream os = XMLStreamWriterUtil.getOutputStream(sw);
     if (os != null) {
       bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), am);
     } else {
       bridge.marshal(jaxbObject, sw, am);
     }
     am.cleanup();
   } catch (JAXBException e) {
     // bug 6449684, spec 4.3.4
     throw new WebServiceException(e);
   }
 }
Пример #8
0
 protected void writeAttributeWithNS(String namespaceURI, String localname, String value)
     throws XMLStreamException {
   if (namespaceURI == null || namespaceURI.length() == 0) {
     writer.writeAttribute(localname, value);
   } else {
     String prefix = writer.getNamespaceContext().getPrefix(namespaceURI);
     if (prefix == null) {
       prefix = nsToPrefix.get(namespaceURI);
       if (prefix != null) {
         writer.setPrefix(prefix, namespaceURI);
         writer.writeNamespace(prefix, namespaceURI);
       } else {
         LOG.warn(
             "No prefix for namespace '{}' configured. Depending on XMLStream auto-repairing.",
             namespaceURI);
       }
     }
     writer.writeAttribute(prefix, namespaceURI, localname, value);
   }
 }
Пример #9
0
 /*     */ public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException /*     */ {
   /*     */ try {
     /* 300 */ AttachmentMarshaller am =
         (sw instanceof MtomStreamWriter)
             ? ((MtomStreamWriter) sw).getAttachmentMarshaller()
             : new AttachmentMarshallerImpl(this.attachmentSet);
     /*     */
     /* 305 */ OutputStream os = XMLStreamWriterUtil.getOutputStream(sw);
     /* 306 */ if (os != null)
       /* 307 */ this.bridge.marshal(this.jaxbObject, os, sw.getNamespaceContext(), am);
     /*     */ else {
       /* 309 */ this.bridge.marshal(this.jaxbObject, sw, am);
       /*     */ }
     /*     */
     /*     */ }
   /*     */ catch (JAXBException e)
   /*     */ {
     /* 315 */ throw new WebServiceException(e);
     /*     */ }
   /*     */ }
Пример #10
0
 protected void writeEmptyElementWithNS(String namespaceURI, String localname)
     throws XMLStreamException {
   if (namespaceURI == null || namespaceURI.length() == 0) {
     writer.writeEmptyElement(localname);
   } else {
     if (writer.getNamespaceContext().getPrefix(namespaceURI) == null) {
       String prefix = nsToPrefix.get(namespaceURI);
       if (prefix != null) {
         writer.writeEmptyElement(prefix, localname, namespaceURI);
         writer.writeNamespace(prefix, namespaceURI);
       } else {
         LOG.warn(
             "No prefix for namespace '{}' configured. Depending on XMLStream auto-repairing.",
             namespaceURI);
         writer.writeEmptyElement(namespaceURI, localname);
       }
     } else {
       writer.writeEmptyElement(namespaceURI, localname);
     }
   }
 }
 public NamespaceContext getNamespaceContext() {
   return writer.getNamespaceContext();
 }
  @Override
  protected void writeParts(
      Message message,
      Exchange exchange,
      BindingOperationInfo operation,
      MessageContentsList objs,
      List<MessagePartInfo> parts) {
    // TODO Auto-generated method stub
    OutputStream out = message.getContent(OutputStream.class);
    XMLStreamWriter origXmlWriter = message.getContent(XMLStreamWriter.class);
    Service service = exchange.getService();
    XMLStreamWriter xmlWriter = origXmlWriter;
    CachingXmlEventWriter cache = null;

    Object en = message.getContextualProperty(OUT_BUFFERING);
    boolean allowBuffer = true;
    boolean buffer = false;
    if (en != null) {
      buffer = Boolean.TRUE.equals(en) || "true".equals(en);
      allowBuffer = !(Boolean.FALSE.equals(en) || "false".equals(en));
    }
    // need to cache the events in case validation fails or buffering is enabled
    if (buffer || (allowBuffer && shouldValidate(message) && !isRequestor(message))) {
      cache = new CachingXmlEventWriter();
      try {
        cache.setNamespaceContext(origXmlWriter.getNamespaceContext());
      } catch (XMLStreamException e) {
        // ignorable, will just get extra namespace decls
      }
      xmlWriter = cache;
      out = null;
    }

    if (out != null
        && writeToOutputStream(message, operation.getBinding(), service)
        && !MessageUtils.isTrue(message.getContextualProperty(DISABLE_OUTPUTSTREAM_OPTIMIZATION))) {
      if (xmlWriter != null) {
        try {
          xmlWriter.writeCharacters("");
          xmlWriter.flush();
        } catch (XMLStreamException e) {
          throw new Fault(e);
        }
      }

      DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class);

      for (MessagePartInfo part : parts) {
        if (objs.hasValue(part)) {
          Object o = objs.get(part);
          osWriter.write(o, part, out);
        }
      }
    } else {
      DataWriter<XMLStreamWriter> dataWriter = new CustomDataWriter(prismContext);

      for (MessagePartInfo part : parts) {
        if (objs.hasValue(part)) {
          Object o = objs.get(part);
          dataWriter.write(o, part, xmlWriter);
        }
      }
    }
    if (cache != null) {
      try {
        for (XMLEvent event : cache.getEvents()) {
          StaxUtils.writeEvent(event, origXmlWriter);
        }
      } catch (XMLStreamException e) {
        throw new Fault(e);
      }
    }
  }