javax.xml.stream.XMLStreamReader Java Examples

The following examples show how to use javax.xml.stream.XMLStreamReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OutboundStreamHeader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We don't really expect this to be used, but just to satisfy
 * the {@link Header} contract.
 *
 * So this is rather slow.
 */
private void parseAttributes() {
    try {
        XMLStreamReader reader = readHeader();

        attributes = new FinalArrayList<Attribute>();

        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String localName = reader.getAttributeLocalName(i);
            final String namespaceURI = reader.getAttributeNamespace(i);
            final String value = reader.getAttributeValue(i);

            attributes.add(new Attribute(namespaceURI,localName,value));
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
    }
}
 
Example #2
Source File: DomReader.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private static Element readElement(Document d, XMLStreamReader reader) throws XMLStreamException {
    Element e = null;

    String local = reader.getLocalName();
    String ns = reader.getNamespaceURI();
    if (ns != null && !ns.equals("")) {
        String prefix = reader.getPrefix();
        String qualified = prefix != null && !prefix.isEmpty() ? prefix + ":" + local : local;
        e = d.createElementNS(ns, qualified);
    } else {
        e = d.createElement(local);
    }

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        Attr a = readAttribute(i, d, reader);
        if (a.getNamespaceURI() != null) {
            e.setAttributeNodeNS(a);
        } else {
            e.setAttributeNode(a);
        }
    }

    return e;
}
 
Example #3
Source File: OverloadSecurityIndex.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
public static OverloadSecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    String text = null;
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;
            case XMLEvent.END_ELEMENT:
                if ("fx".equals(xmlsr.getLocalName())) {
                    return new OverloadSecurityIndex(contingencyId, Double.parseDouble(text));
                }
                break;
            default:
                break;
        }
    }
    throw new AssertionError("fx element not found");
}
 
Example #4
Source File: NamespaceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRootElementNamespace() {
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        InputStream is = new java.io.ByteArrayInputStream(getXML().getBytes());
        XMLStreamReader sr = xif.createXMLStreamReader(is);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(rootElement)) {
                    Assert.assertTrue(sr.getNamespacePrefix(0).equals(prefix) && sr.getNamespaceURI(0).equals(namespaceURI));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example #5
Source File: DomReader.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public static Node read(Reader in) throws ParserConfigurationException, XMLStreamException, IOException {
    XMLStreamReader reader = null;
    try {
        Document d = BUILDER_FACTORY.newDocumentBuilder().newDocument();
        reader = XML_INPUT_FACTORY.createXMLStreamReader(in);
        return readNode(d, reader);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (XMLStreamException e2) {
                LOG.warn("Unable to close XML reader", e2);
            }
        }
    }
}
 
Example #6
Source File: JCA10TestCase.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Read
 * @throws Exception In case of an error
 */
@Test
public void testRead() throws Exception
{
   RaParser parser = new RaParser();

   InputStream is = JCA10TestCase.class.getClassLoader().getResourceAsStream("../../resources/test/spec/ra-1.0.xml");
   assertNotNull(is);

   XMLInputFactory inputFactory = XMLInputFactory.newInstance();
   inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);

   XMLStreamReader xsr = inputFactory.createXMLStreamReader(is);

   Connector c = parser.parse(xsr);
   assertNotNull(c);

   is.close();
   checkConnector(c);
}
 
Example #7
Source File: TaskXmlConverter.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void convertCommonTaskAttributes(XMLStreamReader xtr, Task task) {
    task.setName(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_NAME));

    String isBlockingString = xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_IS_BLOCKING);
    if (StringUtils.isNotEmpty(isBlockingString)) {
        task.setBlocking(Boolean.valueOf(isBlockingString));
    }

    String isBlockingExpressionString = xtr.getAttributeValue(CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE,
        CmmnXmlConstants.ATTRIBUTE_IS_BLOCKING_EXPRESSION);
    if (StringUtils.isNotEmpty(isBlockingExpressionString)) {
        task.setBlockingExpression(isBlockingExpressionString);
    }

    String isAsyncString = xtr.getAttributeValue(CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE,
        CmmnXmlConstants.ATTRIBUTE_IS_ASYNCHRONOUS);
    if (StringUtils.isNotEmpty(isAsyncString)) {
        task.setAsync(Boolean.valueOf(isAsyncString.toLowerCase()));
    }

    String isExclusiveString = xtr.getAttributeValue(CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE,
        CmmnXmlConstants.ATTRIBUTE_IS_EXCLUSIVE);
    if (StringUtils.isNotEmpty(isExclusiveString)) {
        task.setExclusive(Boolean.valueOf(isExclusiveString));
    }
}
 
Example #8
Source File: XMLStreamFilterImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** Creates a new instance of XMLStreamFilterImpl */

    public XMLStreamFilterImpl(XMLStreamReader reader,StreamFilter filter){
        fStreamReader = reader;
        this.fStreamFilter = filter;

        //this is debatable to initiate at an acceptable event,
        //but it's neccessary in order to pass the TCK and yet avoid skipping element
        try {
            if (fStreamFilter.accept(fStreamReader)) {
                fEventAccepted = true;
            } else {
                findNextEvent();
            }
        }catch(XMLStreamException xs){
            System.err.println("Error while creating a stream Filter"+xs);
        }
    }
 
Example #9
Source File: XmlEntityConsumer.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private XMLStreamReader createStaxReader(final Object content) throws XMLStreamException, EntityProviderException {
  XMLInputFactory factory = XMLInputFactory.newInstance();
  factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
  factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);

  if (content == null) {
    throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
        .addContent("Got not supported NULL object as content to de-serialize."));
  }

  if (content instanceof InputStream) {
    XMLStreamReader streamReader = factory.createXMLStreamReader((InputStream) content, DEFAULT_CHARSET);
    // verify charset encoding set in content is supported (if not set UTF-8 is used as defined in 'http://www.w3.org/TR/2008/REC-xml-20081126/')
    String characterEncodingInContent = streamReader.getCharacterEncodingScheme();
    if (characterEncodingInContent != null && !DEFAULT_CHARSET.equalsIgnoreCase(characterEncodingInContent)) {
      throw new EntityProviderException(EntityProviderException.UNSUPPORTED_CHARACTER_ENCODING.addContent(characterEncodingInContent));
    }
    return streamReader;
  }
  throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
      .addContent("Found not supported content of class '" + content.getClass() + "' to de-serialize."));
}
 
Example #10
Source File: NamespaceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testChildElementNamespace() {
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        InputStream is = new java.io.ByteArrayInputStream(getXML().getBytes());
        XMLStreamReader sr = xif.createXMLStreamReader(is);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    QName qname = sr.getName();
                    Assert.assertTrue(qname.getPrefix().equals(prefix) && qname.getNamespaceURI().equals(namespaceURI)
                            && qname.getLocalPart().equals(childElement));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example #11
Source File: MappingConfigParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the <mapping> element
 * @param reader
 * @return
 * @throws XMLStreamException
 */
public List<MappingModuleEntry> parse(XMLStreamReader reader) throws XMLStreamException
{
   List<MappingModuleEntry> entries = new ArrayList<MappingModuleEntry>();
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT)
   {
      final Element element = Element.forName(reader.getLocalName());
      MappingModuleEntry entry = null;
      if (element.equals(Element.MAPPING_MODULE))
      {
         entry = getEntry(reader);
      }
      else
         throw StaxParserUtil.unexpectedElement(reader);
      entries.add(entry);
   }
   return entries;
}
 
Example #12
Source File: JBossDeploymentStructureParser10.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parsePath(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case PATH:
                path = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }

    final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1;
    if (literal) {
        if (path.charAt(path.length() - 1) == '/') {
            filters.add(new FilterSpecification(PathFilters.isChildOf(path), include));
        } else {
            filters.add(new FilterSpecification(PathFilters.is(path), include));
        }
    } else {
        filters.add(new FilterSpecification(PathFilters.match(path), include));
    }

    // consume remainder of element
    parseNoContent(reader);
}
 
Example #13
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testFunctionImportError() throws XMLStreamException, EntityProviderException {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[1]
          + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
          + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"NoReturn\" " +
          "EntitySet=\"Rooms\" m:HttpMethod=\"GET\"/>"
          + "<FunctionImport Name=\"SingleRoomReturnType\" ReturnType=\"RefScenario.Room\" " +
          "EntitySet=\"Rooms\" m:HttpMethod=\"GET\">"
          + "</FunctionImport>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmWithEntityContainer);
  parser.readMetadata(reader, true);
}
 
Example #14
Source File: MessageFlowParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
  String id = xtr.getAttributeValue(null, ATTRIBUTE_ID);
  if (StringUtils.isNotEmpty(id)) {
    MessageFlow messageFlow = new MessageFlow();
    messageFlow.setId(id);

    String name = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
    if (StringUtils.isNotEmpty(name)) {
      messageFlow.setName(name);
    }

    String sourceRef = xtr.getAttributeValue(null, ATTRIBUTE_FLOW_SOURCE_REF);
    if (StringUtils.isNotEmpty(sourceRef)) {
      messageFlow.setSourceRef(sourceRef);
    }

    String targetRef = xtr.getAttributeValue(null, ATTRIBUTE_FLOW_TARGET_REF);
    if (StringUtils.isNotEmpty(targetRef)) {
      messageFlow.setTargetRef(targetRef);
    }

    String messageRef = xtr.getAttributeValue(null, ATTRIBUTE_MESSAGE_REF);
    if (StringUtils.isNotEmpty(messageRef)) {
      messageFlow.setMessageRef(messageRef);
    }

    model.addMessageFlow(messageFlow);
  }
}
 
Example #15
Source File: JibxMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected Object unmarshalXmlEventReader(XMLEventReader eventReader) {
	try {
		XMLStreamReader streamReader = StaxUtils.createEventStreamReader(eventReader);
		return unmarshalXmlStreamReader(streamReader);
	}
	catch (XMLStreamException ex) {
		return new UnmarshallingFailureException("JiBX unmarshalling exception", ex);
	}
}
 
Example #16
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseModuleAlias(final XMLStreamReader reader, final ModuleStructureSpec moduleSpec) throws XMLStreamException {
    final int count = reader.getAttributeCount();
    String name = null;
    String slot = null;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case SLOT:
                slot = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case END_ELEMENT: {
                moduleSpec.addAlias(ModuleIdentifier.create(name, slot));
                return;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example #17
Source File: PolicyWSDLParserExtension.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean bindingOperationOutputElements(final EditableWSDLBoundOperation operation, final XMLStreamReader reader) {
    LOGGER.entering();
    final boolean result = processSubelement(operation, reader, getHandlers4BindingOutputOpMap());
    LOGGER.exiting();
    return result;
}
 
Example #18
Source File: PolicyWSDLParserExtension.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean portTypeOperationInputElements(final EditableWSDLInput input, final XMLStreamReader reader) {
    LOGGER.entering();
    final boolean result = processSubelement(input, reader, getHandlers4InputMap());
    LOGGER.exiting();
    return result;
}
 
Example #19
Source File: PolicyWSDLParserExtension.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void processAttributes(final WSDLObject element, final XMLStreamReader reader, final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {
    final String[] uriArray = getPolicyURIsFromAttr(reader);
    if (null != uriArray) {
        for (String policyUri : uriArray) {
            processReferenceUri(policyUri, element, reader, map);
        }
    }
}
 
Example #20
Source File: JAXBUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static <T> JAXBElement<T> unmarshall(JAXBContext c,
                                            XMLStreamReader reader,
                                            Class<T> cls) throws JAXBException {
    Unmarshaller u = c.createUnmarshaller();
    try {
        u.setEventHandler(null);
        return u.unmarshal(reader, cls);
    } finally {
        closeUnmarshaller(u);
    }
}
 
Example #21
Source File: BasicJavaClientREST.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
/**
 * Convert XMLStreamReader To String
 * 
 * @param XMLStreamReader
 * @return String
 * @throws XMLStreamException
 *           , TransformerException, IOException,
 *           ParserConfigurationException, SAXException
 */
public String convertXMLStreamReaderToString(XMLStreamReader reader) throws XMLStreamException, TransformerException, IOException, ParserConfigurationException, SAXException {
  String str = null;
  while (reader.hasNext())
  {
    reader.next();
    int a = reader.getEventType();
    if (reader.hasText())
      if (reader.getText() != "null")
        str = str + reader.getText().trim();
  }
  return str;
}
 
Example #22
Source File: XMLStreamReaderFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public XMLStreamReader doCreate(String systemId, Reader in, boolean rejectDTDs) {
    try {
        return xif.get().createXMLStreamReader(systemId,in);
    } catch (XMLStreamException e) {
        throw new XMLReaderException("stax.cantCreate",e);
    }
}
 
Example #23
Source File: SecureXmlParserFactory.java    From analysis-model with MIT License 5 votes vote down vote up
/**
 * Creates a new instance of a {@link XMLStreamReader} that does not resolve external entities.
 *
 * @param reader
 *         the reader to wrap
 *
 * @return a new instance of a {@link XMLStreamReader}
 */
public XMLStreamReader createXmlStreamReader(final Reader reader) {
    try {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        factory.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
        return factory.createXMLStreamReader(reader);
    }
    catch (XMLStreamException exception) {
        throw new IllegalArgumentException("Can't create instance of XMLStreamReader", exception);
    }
}
 
Example #24
Source File: StaxUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopy() throws Exception {

    // do the stream copying
    String soapMessage = "./resources/headerSoapReq.xml";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(getTestStream(soapMessage));
    XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(baos);
    StaxUtils.copy(reader, writer);
    writer.flush();
    baos.flush();

    // write output to a string
    String output = baos.toString();
    baos.close();

    // re-read the input xml doc to a string
    String input = IOUtils.toString(getTestStream(soapMessage));

    // seach for the first begin of "<soap:Envelope" to escape the apache licenses header
    int beginIndex = input.indexOf("<soap:Envelope");
    input = input.substring(beginIndex);
    beginIndex = output.indexOf("<soap:Envelope");
    output = output.substring(beginIndex);

    output = output.replace("\r\n", "\n");
    input = input.replace("\r\n", "\n");

    // compare the input and output string
    assertEquals(input, output);
}
 
Example #25
Source File: PolicyWSDLParserExtension.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean bindingOperationFaultElements(final EditableWSDLBoundFault fault, final XMLStreamReader reader) {
    LOGGER.entering();
    final boolean result = processSubelement(fault, reader, getHandlers4BindingFaultOpMap());
    LOGGER.exiting(result);
    return result;
}
 
Example #26
Source File: XmlUtil.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
public static String readUntilEndElementWithDepth(String endElementName, XMLStreamReader reader, XmlEventHandlerWithDepth eventHandler) throws XMLStreamException {
    Objects.requireNonNull(endElementName);
    Objects.requireNonNull(reader);

    String text = null;
    int event;
    int depth = 0;
    while (!((event = reader.next()) == XMLStreamConstants.END_ELEMENT
            && reader.getLocalName().equals(endElementName))) {
        text = null;
        switch (event) {
            case XMLStreamConstants.START_ELEMENT:
                if (eventHandler != null) {
                    String startLocalName = reader.getLocalName();
                    eventHandler.onStartElement(depth);
                    // if handler has already consumed end element we must decrease the depth
                    if (reader.getEventType() == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals(startLocalName)) {
                        depth--;
                    }
                }
                depth++;
                break;

            case XMLStreamConstants.END_ELEMENT:
                depth--;
                break;

            case XMLStreamConstants.CHARACTERS:
                text = reader.getText();
                break;

            default:
                break;
        }
    }
    return text;
}
 
Example #27
Source File: StAXStreamConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean getBoolProp(XMLStreamReader r, String n) {
    try {
        Object o = r.getProperty(n);
        if(o instanceof Boolean)    return (Boolean)o;
        return false;
    } catch (Exception e) {
        // be defensive against broken StAX parsers since javadoc is not clear
        // about when an error happens
        return false;
    }
}
 
Example #28
Source File: XMLStreamReaderFactory.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public XMLStreamReader doCreate(String systemId, InputStream in, boolean rejectDTDs) {
    try {
        return xif.get().createXMLStreamReader(systemId,in);
    } catch (XMLStreamException e) {
        throw new XMLReaderException("stax.cantCreate",e);
    }
}
 
Example #29
Source File: DeploymentDescriptorParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected static void failWithLocalName(String key, XMLStreamReader reader, String arg) {
    throw new ServerRtException(
            key,
            reader.getLocation().getLineNumber(),
            reader.getLocalName(),
            arg);
}
 
Example #30
Source File: EndpointArgumentsBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void readRequest(Message msg, Object[] args) throws JAXBException, XMLStreamException {
    if (dynamicWrapper) {
        readWrappedRequest(msg, args);
    } else {
        if (parts.length>0) {
            if (!msg.hasPayload()) {
                throw new WebServiceException("No payload. Expecting payload with "+wrapperName+" element");
            }
            XMLStreamReader reader = msg.readPayload();
            XMLStreamReaderUtil.verifyTag(reader, wrapperName);
            Object wrapperBean = wrapper.unmarshal(reader, (msg.getAttachments() != null) ?
                    new AttachmentUnmarshallerImpl(msg.getAttachments()): null);

            try {
                for (PartBuilder part : parts) {
                    part.readRequest(args,wrapperBean);
                }
            } catch (DatabindingException e) {
                // this can happen when the set method throw a checked exception or something like that
                throw new WebServiceException(e);    // TODO:i18n
            }

            // we are done with the body
            reader.close();
            XMLStreamReaderFactory.recycle(reader);
        } else {
            msg.consume();
        }
    }
}