当前位置: 首页>>代码示例>>Java>>正文


Java StAXUtils类代码示例

本文整理汇总了Java中org.apache.axiom.om.util.StAXUtils的典型用法代码示例。如果您正苦于以下问题:Java StAXUtils类的具体用法?Java StAXUtils怎么用?Java StAXUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StAXUtils类属于org.apache.axiom.om.util包,在下文中一共展示了StAXUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBuilder

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
/**
 * Creates an OMBuilder for a plain XML message.
 *
 * @param inStream   InputStream for a XML message
 * @param charSetEnc Character set encoding to be used
 * @return Handler to a OMBuilder implementation instance
 * @throws javax.xml.stream.XMLStreamException
 */
public static StAXBuilder getBuilder(InputStream inStream, String charSetEnc) throws XMLStreamException {
    XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(inStream, charSetEnc);
    try {
        return new StAXSOAPModelBuilder(xmlReader);
    } catch (OMException e) {
        log.info("OMException in getSOAPBuilder", e);
        try {
            log.info("Remaining input stream :[" +
                    new String(IOUtils.getStreamAsByteArray(inStream), charSetEnc) + "]");
        } catch (IOException e1) {
            // Nothing here?
        }
        throw e;
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-gateway-framework,代码行数:24,代码来源:XMLUtil.java

示例2: getSOAPBuilder

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
/**
 * Creates an OMBuilder for a SOAP message. Default character set encording is used.
 *
 * @param inStream InputStream for a SOAP message
 * @return Handler to a OMBuilder implementation instance
 * @throws javax.xml.stream.XMLStreamException
 */
public static StAXBuilder getSOAPBuilder(InputStream inStream) throws XMLStreamException {
    XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(inStream);
    try {
        return new StAXSOAPModelBuilder(xmlReader);
    } catch (OMException e) {
        log.info("OMException in getSOAPBuilder", e);
        try {
            log.info("Remaining input stream :[" +
                    new String(IOUtils.getStreamAsByteArray(inStream) , "UTF-8") + "]");
        } catch (IOException e1) {
            // Nothing here?
        }
        throw e;
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-gateway-framework,代码行数:23,代码来源:XMLUtil.java

示例3: testEchoXMLSync

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
public void testEchoXMLSync() throws Exception {
    OMElement payload = createPayload();

    Options options = new Options();
    options.setTo(targetEPR);
    options.setTransportInProtocol(Constants.TRANSPORT_TCP);
    options.setAction(Constants.AXIS2_NAMESPACE_URI+"/"+operationName.getLocalPart());

    ServiceClient sender = new ServiceClient(configContext, clientService);
    sender.setOptions(options);
    OMElement result = sender.sendReceive(operationName, payload);

    result.serialize(StAXUtils.createXMLStreamWriter(
            System.out));
    sender.cleanup();
}
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:17,代码来源:TCPEchoRawXMLTest.java

示例4: testEchoXMLCompleteSync

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
public void testEchoXMLCompleteSync() throws Exception {
    OMFactory fac = OMAbstractFactory.getOMFactory();

    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement payloadElement = fac.createOMElement("echoOMElement", omNs);
    OMElement value = fac.createOMElement("myValue", omNs);
    value.setText("Isaac Asimov, The Foundation Trilogy");
    payloadElement.addChild(value);

    Options options = new Options();
    options.setTo(targetEPR);
    options.setAction(Constants.AXIS2_NAMESPACE_URI+"/"+operationName.getLocalPart());
    options.setTransportInProtocol(Constants.TRANSPORT_TCP);
    options.setUseSeparateListener(true);

    ServiceClient sender = new ServiceClient(configContext, clientService);
    sender.setOptions(options);
    OMElement result = sender.sendReceive(operationName, payloadElement);

    result.serialize(StAXUtils.createXMLStreamWriter(
            System.out));
    sender.cleanup();

}
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:25,代码来源:TCPEchoRawXMLTest.java

示例5: getStringXML

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
/**
 * Util method to convert the pullstream to a string
 *
 * @param reader
 * @return
 */
private String getStringXML(XMLStreamReader reader) throws XMLStreamException {
    //the returned pullparser starts at an Element rather than the start
    //document event. This is somewhat disturbing but since an ADBBean
    //denotes an XMLFragment, it is justifiable to keep the current event
    //at the Start-element rather than the start document
    //What it boils down to is that we need to wrap the reader in a
    //stream wrapper to get a fake start-document event

    StreamingOMSerializer ser = new StreamingOMSerializer();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);
    ser.serialize(
            new StreamWrapper(reader),
            writer);
    writer.flush();
    return byteArrayOutputStream.toString();
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:24,代码来源:ADBXMLStreamReaderTest.java

示例6: testStateMachine

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
public void testStateMachine() throws Exception {
    String xmlDoc =
            "<wrapper><myIntVal>200</myIntVal><myIntVal>200</myIntVal><myIntVal>200</myIntVal>" +
                    "<myIntVal>200</myIntVal><myIntVal>200</myIntVal><myIntVal>200</myIntVal></wrapper>";
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(
            new StringReader(xmlDoc));
    SimpleArrayReaderStateMachine sm = new SimpleArrayReaderStateMachine();
    sm.setElementNameToTest(new QName("myIntVal"));
    try {
        sm.read(reader);
    } catch (XMLStreamException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }

    assertEquals(6, sm.getTextArray().length);

}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:18,代码来源:SimpleArrayReaderStateMachineTest.java

示例7: testStateMachineEmptyArray

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
public void testStateMachineEmptyArray() throws Exception {
    String xmlDoc = "<wrapper></wrapper>";
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(
            new StringReader(xmlDoc));
    SimpleArrayReaderStateMachine sm = new SimpleArrayReaderStateMachine();
    sm.setElementNameToTest(new QName("myIntVal"));
    try {
        sm.read(reader);
    } catch (Exception e) {

    }

    assertEquals(0, sm.getTextArray().length);


}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:17,代码来源:SimpleArrayReaderStateMachineTest.java

示例8: getInputObject

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
protected Object[] getInputObject(List inputObjects, Operation operation)
        throws XMLStreamException, XmlSerializingException, XmlParsingException {
    StringWriter inputStringWriter = new StringWriter();
    XMLStreamWriter inputXmlStreamWriter = StAXUtils.createXMLStreamWriter(inputStringWriter);
    this.javaObjectSerializer.serializeInputElement(inputObjects.toArray(),
            operation.getInputElement(),
            operation.getInputParameters(),
            inputXmlStreamWriter);
    inputXmlStreamWriter.flush();
    String inputXmlString = inputStringWriter.toString();

    System.out.println("input Xml String ==> " + inputXmlString);

    XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(inputXmlString.getBytes()));
    Object[] objects = this.xmlStreamParser.getInputParameters(xmlReader, operation);
    return objects;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:18,代码来源:RequestResponseTest.java

示例9: getReturnObject

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
protected Object getReturnObject(Object returnObject, Operation operation)
        throws XMLStreamException, XmlSerializingException, XmlParsingException {
    // get the response xml serializer
    StringWriter outputStringWriter = new StringWriter();
    XMLStreamWriter outputXMLStringWriter = StAXUtils.createXMLStreamWriter(outputStringWriter);

    this.javaObjectSerializer.serializeOutputElement(returnObject,
            operation.getOutPutElement(),
            operation.getOutputParameter(),
            outputXMLStringWriter);
    outputXMLStringWriter.flush();
    String outputXmlString = outputStringWriter.toString();
    System.out.println("output Xml String ==> " + outputXmlString);

    XMLStreamReader outputXmlReader =
            StAXUtils.createXMLStreamReader(new ByteArrayInputStream(outputXmlString.getBytes()));

    return this.xmlStreamParser.getOutputObject(outputXmlReader, operation);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:20,代码来源:RequestResponseTest.java

示例10: _getReaderFromBO

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
@Override
protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext)
        throws XMLStreamException, WebServiceException {
    try {
        if (busObj instanceof DataSource) {
            XMLInputFactory f = StAXUtils.getXMLInputFactory();

            XMLStreamReader reader = f.createXMLStreamReader(((DataSource)busObj).getInputStream());
            StAXUtils.releaseXMLInputFactory(f);
            return reader;
        }
        throw ExceptionFactory.makeWebServiceException(
                Messages.getMessage("SourceNotSupported", busObject.getClass().getName()));
    } catch (Exception e) {
        String className = (busObj == null) ? "none" : busObj.getClass().getName();
        throw ExceptionFactory
                .makeWebServiceException(Messages.getMessage("SourceReadErr", className), e);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:20,代码来源:DataSourceBlockImpl.java

示例11: _slow_getReaderFromSource

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
/** Creates an XMLStreamReader from a Source using a slow but proven algorithm. */
private XMLStreamReader _slow_getReaderFromSource(Source src) throws XMLStreamException {
    if (log.isDebugEnabled()) {
        log.debug("Start _slow_getReaderFromSource");
    }
    byte[] bytes = (byte[]) ConvertUtils.convert(src, byte[].class);
    if (log.isDebugEnabled()) {
        log.debug("Successfully converted to ByteArray");
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(bais);
    if (log.isDebugEnabled()) {
        log.debug("End _slow_getReaderFromSource =" + reader);
    }
    return reader;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:17,代码来源:SourceBlockImpl.java

示例12: toOM

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
private org.apache.axiom.soap.SOAPEnvelope toOM(String xml)
        throws WebServiceException {
	if (log.isDebugEnabled()) {
	    log.debug("Converting SAAJ SOAPEnvelope String to an OM SOAPEnvelope");
	    log.debug("The conversion occurs due to " + JavaUtils.stackToString());
	} 
	
    XMLStreamReader reader;
    try {
        reader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(xml.getBytes()));
    } catch (XMLStreamException e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
    // Get a SOAP OM Builder.  Passing null causes the version to be automatically triggered
    StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(reader, null);
    // Create and return the OM Envelope
    return builder.getSOAPEnvelope();
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:19,代码来源:SAAJConverterImpl.java

示例13: _postPivot_getXMLStreamReader

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
/**
 * Called if we have passed the pivot point but someone wants to output the block. The actual
 * block implementation may choose to override this setting.
 */
protected XMLStreamReader _postPivot_getXMLStreamReader()
        throws XMLStreamException, WebServiceException {
    if (log.isDebugEnabled()) {
        QName theQName = isQNameAvailable() ? getQName() : new QName("unknown");
        log.debug("The Block for " + theQName +
                " is already consumed and therefore it is only partially read.");
        log.debug("If you need this block preserved, please set the " + Constants
                .SAVE_REQUEST_MSG + " property on the MessageContext.");
    }
    QName qName = getQName();
    String text = "";
    if (qName.getNamespaceURI().length() > 0) {
        text = "<prefix:" + qName.getLocalPart() + " xmlns:prefix='" + qName.getNamespaceURI() +
                "'/>";
    } else {
        text = "<" + qName.getLocalPart() + "/>";
    }
    StringReader sr = new StringReader(text);
    return StAXUtils.createXMLStreamReader(sr);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:25,代码来源:BlockImpl.java

示例14: getBuilder

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
/**
 * Creates an OMBuilder for a plain XML message.
 *
 * @param inStream   InputStream for a XML message
 * @param charSetEnc Character set encoding to be used
 * @return Handler to a OMBuilder implementation instance
 * @throws XMLStreamException
 */
public static StAXBuilder getBuilder(InputStream inStream, String charSetEnc)
        throws XMLStreamException {
    XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(inStream, charSetEnc);
    try {
        return new StAXSOAPModelBuilder(xmlReader);
    } catch (OMException e) {
        log.info("OMException in getSOAPBuilder", e);
        try {
            log.info("Remaining input stream :[" +
                     new String(IOUtils.getStreamAsByteArray(inStream), charSetEnc) + "]");
        } catch (IOException e1) {
            // Nothing here?
        }
        throw e;
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:25,代码来源:BuilderUtil.java

示例15: getSOAPBuilder

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
/**
 * Creates an OMBuilder for a SOAP message. Default character set encording is used.
 *
 * @param inStream InputStream for a SOAP message
 * @return Handler to a OMBuilder implementation instance
 * @throws XMLStreamException
 */
public static StAXBuilder getSOAPBuilder(InputStream inStream) throws XMLStreamException {
    XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(inStream);
    try {
        return new StAXSOAPModelBuilder(xmlReader);
    } catch (OMException e) {
        log.info("OMException in getSOAPBuilder", e);
        try {
            log.info("Remaining input stream :[" +
                     new String(IOUtils.getStreamAsByteArray(inStream)) + "]");
        } catch (IOException e1) {
            // Nothing here?
        }
        throw e;
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:23,代码来源:BuilderUtil.java


注:本文中的org.apache.axiom.om.util.StAXUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。