• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java StAXUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: startUp

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
public void startUp(ConfigurationContext configctx,
                    AxisService service) {
    try {
        String tempDir = System.getProperty("java.io.tmpdir");
        File tempFile = new File(tempDir);
        File libFile = new File(tempFile, "library.xml");
        OMElement libraryElement;
        boolean noFile = true;
        if (!libFile.exists()) {
            //Service starting at the first time or user has clean the temp.dir
            Parameter allBooks = service.getParameter(LibraryConstants.ALL_BOOK);
            libraryElement = allBooks.getParameterElement();
        } else {
            InputStream in = new FileInputStream(libFile);
            XMLStreamReader xmlReader = StAXUtils
                    .createXMLStreamReader(in);
            StAXOMBuilder staxOMBuilder = new StAXOMBuilder(xmlReader);
            libraryElement = staxOMBuilder.getDocumentElement();
            noFile = false;
        }
        processOmelemnt(libraryElement, service, noFile);
    } catch (Exception exception) {
        log.info(exception);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:26,代码来源:LibraryLifeCycle.java


示例17: testPopulate

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

            XMLStreamReader reader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(xmlString.getBytes()));
            Class clazz = Class.forName("org.soapinterop.xsd.Myobject");
            Class innerClazz = Util.getFactory(clazz);
            Method parseMethod = innerClazz.getMethod("parse",new Class[]{XMLStreamReader.class});
            Object obj = parseMethod.invoke(null,new Object[]{reader});


            Object myObject = null ;
            BeanInfo beanInfo =  Introspector.getBeanInfo(obj.getClass());
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            for (int i = 0; i < propertyDescriptors.length; i++) {
                PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
                if ("myobject".equals(propertyDescriptor.getDisplayName())){
                    Method readMethod = propertyDescriptor.getReadMethod();
                    myObject = readMethod.invoke(obj,new Object[]{});
                    break;
                }


            }

            assertNotNull(myObject);
    }
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:26,代码来源:PopulateArrayInArrayTest.java


示例18: testSerializeDeserializeUsingMTOMWithoutOptimize

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
private static void testSerializeDeserializeUsingMTOMWithoutOptimize(Object bean, Object expectedResult) throws Exception {
        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        envelope.getBody().addChild(ADBBeanUtil.getOMElement(bean));
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        OMOutputFormat format = new OMOutputFormat();
        MultipartWriter mpWriter = JavaMailMultipartWriterFactory.INSTANCE.createMultipartWriter(buffer, format.getMimeBoundary());
        OutputStream rootPartWriter = mpWriter.writePart("application/xop+xml; charset=UTF-8; type=\"text/xml\"", "binary", format.getRootContentId());
        envelope.serialize(rootPartWriter, format);
        rootPartWriter.close();
        mpWriter.complete();
//        System.out.write(buffer.toByteArray());
        String contentType = format.getContentTypeForMTOM("text/xml");
        Attachments attachments = new Attachments(new ByteArrayInputStream(buffer.toByteArray()), contentType);
        MTOMStAXSOAPModelBuilder builder = new MTOMStAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream()), attachments);
        OMElement bodyElement = builder.getSOAPEnvelope().getBody().getFirstElement();
        assertBeanEquals(expectedResult, ADBBeanUtil.parse(bean.getClass(), bodyElement.getXMLStreamReaderWithoutCaching()));
    }
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:18,代码来源:AbstractTestCase.java


示例19: buildOMElement

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
private static OMElement buildOMElement() {
    String xmlString = "<ns1:Project xmlns:ns1=\"http://axis2.apache.org/sample\">\n" +
            "    <ns1:Developer>\n" +
            "        <ns1:name>AAA</ns1:name>\n" +
            "        <ns1:location>Colombo</ns1:location>\n" +
            "    </ns1:Developer>\n" +
            "</ns1:Project>";
    OMElement omElement = null;
    try {
        XMLStreamReader xmlStreamReader =
                StAXUtils.createXMLStreamReader(new ByteArrayInputStream(xmlString.getBytes()));
        StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(xmlStreamReader);
        omElement = stAXOMBuilder.getDocumentElement();
    } catch (XMLStreamException e) {
        e.printStackTrace();
    }
    return omElement;
}
 
开发者ID:syodage,项目名称:Axis2-Samples,代码行数:19,代码来源:OMElementBuilder.java


示例20: buildSoapEnvelope

import org.apache.axiom.om.util.StAXUtils; //导入依赖的package包/类
private static SOAPEnvelope buildSoapEnvelope() {

        String xmlString = "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">\n" +
                "    <soapenv:Body>\n" +
                "        <ns1:Project xmlns:ns1=\"http://axis2.apache.org/sample\">\n" +
                "            <ns1:Developer>\n" +
                "                <ns1:name>AAA</ns1:name>\n" +
                "                <ns1:location>Colombo</ns1:location>\n" +
                "            </ns1:Developer>\n" +
                "        </ns1:Project>\n" +
                "    </soapenv:Body>\n" +
                "</soapenv:Envelope>";

        SOAPEnvelope soapEnvelope = null;
        try {
            XMLStreamReader xmlStreamReader =
                    StAXUtils.createXMLStreamReader(new ByteArrayInputStream(xmlString.getBytes()));
            StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(xmlStreamReader);
            soapEnvelope = stAXSOAPModelBuilder.getSOAPEnvelope();
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }
        return soapEnvelope;
    }
 
开发者ID:syodage,项目名称:Axis2-Samples,代码行数:25,代码来源:SoapElementBuilder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EncryptionInfo类代码示例发布时间:2022-05-22
下一篇:
Java BruteForceInferencer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap