本文整理汇总了Java中org.apache.cxf.staxutils.StaxUtils类的典型用法代码示例。如果您正苦于以下问题:Java StaxUtils类的具体用法?Java StaxUtils怎么用?Java StaxUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StaxUtils类属于org.apache.cxf.staxutils包,在下文中一共展示了StaxUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRouteBuilder
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(fromURI).process(new Processor() {
public void process(final Exchange exchange) throws Exception {
QName faultCode = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server");
SoapFault fault = new SoapFault("Get the null value of person name", faultCode);
Element details = StaxUtils.read(new StringReader(DETAILS)).getDocumentElement();
fault.setDetail(details);
exchange.setException(fault);
}
});
}
};
}
示例2: writeTo
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@Override
public void writeTo(OutputStream os) throws IOException {
// no body no write
if (getBodySources().size() == 0) {
return;
}
Source body = getBodySources().get(0);
if (body instanceof StreamCache) {
((StreamCache) body).writeTo(os);
} else {
try {
StaxUtils.copy(body, os);
} catch (XMLStreamException e) {
throw new IOException("Transformation failed", e);
}
}
}
示例3: createRouteBuilder
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(fromURI).process(new Processor() {
public void process(final Exchange exchange) throws Exception {
Element details = StaxUtils.read(new StringReader(FAULTS)).getDocumentElement();
List<Element> outElements = new ArrayList<Element>();
outElements.add(details);
CxfPayload<SoapHeader> responsePayload = new CxfPayload<SoapHeader>(null, outElements);
exchange.getOut().setBody(responsePayload);
exchange.getOut().setFault(true);
}
});
}
};
}
示例4: invokeStream
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
public SOAPMessage invokeStream(InputStream in) {
SOAPMessage response = null;
try {
Document doc = StaxUtils.read(in);
if (doc.getElementsByTagNameNS(greetMe.getNamespaceURI(),
sayHi.getLocalPart()).getLength() == 1) {
response = sayHiResponse;
} else if (doc.getElementsByTagNameNS(greetMe.getNamespaceURI(),
greetMe.getLocalPart()).getLength() == 1) {
response = greetMeResponse;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return response;
}
示例5: createRouteBuilder
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(fromURI).process(new Processor() {
public void process(final Exchange exchange) throws Exception {
JAXBContext context = JAXBContext.newInstance("org.apache.camel.wsdl_first.types");
QName faultCode = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server");
SoapFault fault = new SoapFault("Get the null value of person name", faultCode);
Element details = StaxUtils.read(new StringReader(DETAILS)).getDocumentElement();
UnknownPersonFault unknowPersonFault = new UnknownPersonFault();
unknowPersonFault.setPersonId("");
context.createMarshaller().marshal(unknowPersonFault, details);
fault.setDetail(details);
exchange.getOut().setBody(fault);
exchange.getOut().setFault(true);
}
});
}
};
}
示例6: process
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
List<SoapHeader> soapHeaders = CastUtils.cast((List<?>)exchange.getIn().getHeader(Header.HEADER_LIST));
// Insert a new header
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><outofbandHeader "
+ "xmlns=\"http://cxf.apache.org/outofband/Header\" hdrAttribute=\"testHdrAttribute\" "
+ "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" soap:mustUnderstand=\"1\">"
+ "<name>New_testOobHeader</name><value>New_testOobHeaderValue</value></outofbandHeader>";
SoapHeader newHeader = new SoapHeader(soapHeaders.get(0).getName(),
StaxUtils.read(new StringReader(xml)).getDocumentElement());
// make sure direction is IN since it is a request message.
newHeader.setDirection(Direction.DIRECTION_IN);
//newHeader.setMustUnderstand(false);
soapHeaders.add(newHeader);
}
示例7: testConsumer
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@Test
public void testConsumer() throws Exception {
if (MtomTestHelper.isAwtHeadless(logger, null)) {
return;
}
context.createProducerTemplate().send("cxf:bean:consumerEndpoint", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
assertEquals("Get a wrong Content-Type header", "application/xop+xml", exchange.getIn().getHeader("Content-Type"));
List<Source> elements = new ArrayList<Source>();
elements.add(new DOMSource(StaxUtils.read(new StringReader(getRequestMessage())).getDocumentElement()));
CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
elements, null);
exchange.getIn().setBody(body);
exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID,
new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID,
new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
}
});
}
示例8: process
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
CxfPayload<SoapHeader> in = exchange.getIn().getBody(CxfPayload.class);
// verify request
Assert.assertEquals(1, in.getBody().size());
DataHandler dr = exchange.getIn().getAttachment(MtomTestHelper.REQ_PHOTO_CID);
Assert.assertEquals("application/octet-stream", dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
dr = exchange.getIn().getAttachment(MtomTestHelper.REQ_IMAGE_CID);
Assert.assertEquals("image/jpeg", dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.requestJpeg, IOUtils.readBytesFromStream(dr.getInputStream()));
// create response
List<Source> elements = new ArrayList<Source>();
elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.MTOM_DISABLED_RESP_MESSAGE)).getDocumentElement()));
CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
elements, null);
exchange.getOut().setBody(body);
exchange.getOut().addAttachment(MtomTestHelper.RESP_PHOTO_CID,
new DataHandler(new ByteArrayDataSource(MtomTestHelper.RESP_PHOTO_DATA, "application/octet-stream")));
exchange.getOut().addAttachment(MtomTestHelper.RESP_IMAGE_CID,
new DataHandler(new ByteArrayDataSource(MtomTestHelper.responseJpeg, "image/jpeg")));
}
示例9: getNode
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
public synchronized Node getNode() {
Node nd = super.getNode();
if (nd == null) {
try {
InputSource src = new InputSource(resource.openStream());
src.setSystemId(this.getSystemId());
src.setPublicId(publicId);
Document doc = StaxUtils.read(src);
setNode(doc);
nd = super.getNode();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return nd;
}
示例10: getPrefixForNamespace
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
public String getPrefixForNamespace(String ns) {
try {
String pfx = writer.getPrefix(ns);
if (pfx == null) {
pfx = StaxUtils.getUniquePrefix(writer);
writer.setPrefix(pfx, ns);
writer.writeNamespace(pfx, ns);
}
return prefix;
} catch (XMLStreamException e) {
throw new DatabindingException("Error writing document.", e);
}
}
示例11: ElementReader
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
/**
* @param is
* @throws javax.xml.stream.XMLStreamException
*/
public ElementReader(InputStream is) throws XMLStreamException {
// XMLInputFactory factory = XMLInputFactory.newInstance();
// XMLStreamReader xmlReader = factory.createXMLStreamReader(is);
XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(is, null);
xmlReader.nextTag();
this.root = new DepthXMLStreamReader(xmlReader);
this.localName = root.getLocalName();
this.name = root.getName();
this.namespace = root.getNamespaceURI();
extractXsiType();
depth = root.getDepth();
}
示例12: writeObject
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@Override
public void writeObject(Object object, MessageWriter writer,
Context context) throws DatabindingException {
Document doc = (Document)object;
try {
Element docElement = doc.getDocumentElement();
if (docElement == null) {
if (isNillable()) {
writer.writeXsiNil();
} else {
throw new DatabindingException("Could not write xml: null document element.");
}
} else {
StaxUtils.writeElement(docElement, ((ElementWriter)writer).getXMLStreamWriter(), false);
}
} catch (XMLStreamException e) {
throw new DatabindingException("Could not write xml.", e);
}
}
示例13: write
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
protected void write(Source object, XMLStreamWriter writer) throws FactoryConfigurationError,
XMLStreamException, DatabindingException {
if (object == null) {
return;
}
if (object instanceof DOMSource) {
DOMSource ds = (DOMSource)object;
Element element = null;
if (ds.getNode() instanceof Element) {
element = (Element)ds.getNode();
} else if (ds.getNode() instanceof Document) {
element = ((Document)ds.getNode()).getDocumentElement();
} else {
throw new DatabindingException("Node type " + ds.getNode().getClass()
+ " was not understood.");
}
StaxUtils.writeElement(element, writer, false);
} else {
StaxUtils.copy(object, writer);
}
}
示例14: publishEndpointWithMtom
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@Test
public void publishEndpointWithMtom() throws Exception {
jaxwsEnvironment.publishEndpoint(
new EndpointBuilder("local://path", service)
.enableMtom());
verify(mockInvokerBuilder).create(any(), any(Invoker.class));
byte[] response = testutils.invokeBytes("local://path", LocalTransportFactory.TRANSPORT_ID, soapRequest.getBytes());
verify(mockInvoker).invoke(any(Exchange.class), any());
MimeMultipart mimeMultipart = new MimeMultipart(new ByteArrayDataSource(response,
"application/xop+xml; charset=UTF-8; type=\"text/xml\""));
assertThat(mimeMultipart.getCount(), equalTo(1));
testutils.assertValid("/soap:Envelope/soap:Body/a:fooResponse",
StaxUtils.read(mimeMultipart.getBodyPart(0).getInputStream()));
}
示例15: handleMessage
import org.apache.cxf.staxutils.StaxUtils; //导入依赖的package包/类
@Override
public void handleMessage(SoapMessage message) throws Fault
{
String mappedNamespace = message.getExchange().getService().getName().getNamespaceURI();
InputStream in = message.getContent(InputStream.class);
if( in != null )
{
// ripped from StaxInInterceptor
String contentType = (String) message.get(Message.CONTENT_TYPE);
if( contentType == null )
{
// if contentType is null, this is likely a an empty
// post/put/delete/similar, lets see if it's
// detectable at all
Map<String, List<String>> m = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
if( m != null )
{
List<String> contentLen = HttpHeaderHelper.getHeader(m, HttpHeaderHelper.CONTENT_LENGTH);
List<String> contentTE = HttpHeaderHelper.getHeader(m, HttpHeaderHelper.CONTENT_TRANSFER_ENCODING);
if( (StringUtils.isEmpty(contentLen) || "0".equals(contentLen.get(0)))
&& StringUtils.isEmpty(contentTE) )
{
return;
}
}
}
// Inject our LegacyPythonHack
XMLStreamReader reader = StaxUtils.createXMLStreamReader(in);
message.setContent(XMLStreamReader.class, new LegacyPythonClientXMLStreamReader(reader, mappedNamespace));
}
}