本文整理汇总了Java中org.springframework.xml.transform.StringResult.toString方法的典型用法代码示例。如果您正苦于以下问题:Java StringResult.toString方法的具体用法?Java StringResult.toString怎么用?Java StringResult.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.xml.transform.StringResult
的用法示例。
在下文中一共展示了StringResult.toString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
private String toString(final JAXBElement<?> jaxbElement)
{
if (jaxbElement == null)
{
return null;
}
try
{
final StringResult result = new StringResult();
jaxbMarshaller.marshal(jaxbElement, result);
return result.toString();
}
catch (final Exception ex)
{
throw new AdempiereException("Failed converting " + jaxbElement + " to String", ex);
}
}
示例2: getSOAPEnvelope
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
/**
* Gets original SOAP envelope.
*
* @param exchange the exchange
* @return envelope as string or {@code null} if input message isn't Spring web service message
*/
@Nullable
public static String getSOAPEnvelope(Exchange exchange) {
if (! (exchange.getIn() instanceof SpringWebserviceMessage)) {
return null;
}
try {
TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();
SpringWebserviceMessage inMsg = (SpringWebserviceMessage) exchange.getIn();
Source source = ((SaajSoapMessage) inMsg.getWebServiceMessage()).getEnvelope().getSource();
StringResult strRes = new StringResult();
aTransformer.transform(source, strRes);
return strRes.toString();
} catch (Exception ex) {
throw new IllegalStateException("Error occurred during conversion SOAP envelope to string", ex);
}
}
示例3: getSoapBody
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
/**
* Method reads SOAP body element from SOAP Envelope and transforms body payload to String.
*
* @param request
* @return
* @throws javax.xml.soap.SOAPException
* @throws java.io.IOException
* @throws javax.xml.transform.TransformerException
*/
public String getSoapBody(Message request) throws SOAPException, IOException, TransformerException {
MessageFactory msgFactory = MessageFactory.newInstance();
MimeHeaders mimeHeaders = new MimeHeaders();
mimeHeaders.addHeader("Content-Type", "text/xml; charset=" + Charset.forName(System.getProperty("citrus.file.encoding", "UTF-8")));
SOAPMessage message = msgFactory.createMessage(mimeHeaders, new ByteArrayInputStream(request.getPayload().toString().getBytes(System.getProperty("citrus.file.encoding", "UTF-8"))));
SOAPBody soapBody = message.getSOAPBody();
Document body = soapBody.extractContentAsDocument();
StringResult result = new StringResult();
transformerFactory.newTransformer().transform(new DOMSource(body), result);
return result.toString();
}
示例4: parseTpicHeaderFromResponseToBackend
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
@Test
public void parseTpicHeaderFromResponseToBackend() throws Exception {
final Map<String, String> context = new HashMap<>();
context.put("our key", "is our value");
final StringResult result = new StringResult();
new SoapHeaderTransport().renderSoapHeader(context, result);
final Source source = new StringSource(result.toString());
final SoapHeader soapHeader = mock(SoapHeader.class);
when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
final SoapHeaderElement element = mock(SoapHeaderElement.class);
when(element.getSource()).thenReturn(source);
when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(Collections.singletonList(element).iterator());
unit.handleResponse(messageContext);
assertThat(backend.size(), is(1));
assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
示例5: parseTpicHeaderFromFaultResponseToBackend
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
@Test
public void parseTpicHeaderFromFaultResponseToBackend() throws Exception {
final Map<String, String> context = new HashMap<>();
context.put("our key", "is our value");
final StringResult result = new StringResult();
new SoapHeaderTransport().renderSoapHeader(context, result);
final Source source = new StringSource(result.toString());
final SoapHeader soapHeader = mock(SoapHeader.class);
when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
final SoapHeaderElement element = mock(SoapHeaderElement.class);
when(element.getSource()).thenReturn(source);
when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(Collections.singletonList(element).iterator());
unit.handleFault(messageContext);
assertThat(backend.size(), is(1));
assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
示例6: parseTpicHeaderFromRequestToTraceeBackend
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
@Test
public void parseTpicHeaderFromRequestToTraceeBackend() throws Exception {
final Map<String, String> context = new HashMap<>();
context.put("our key", "is our value");
final StringResult result = new StringResult();
new SoapHeaderTransport().renderSoapHeader(context, result);
final Source source = new StringSource(result.toString());
final SoapHeader soapHeader = mock(SoapHeader.class);
when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(soapHeader);
final SoapHeaderElement element = mock(SoapHeaderElement.class);
when(element.getSource()).thenReturn(source);
when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(singletonList(element).iterator());
unit.handleRequest(messageContext, new Object());
assertThat(backend.size(), is(2));
assertThat(backend.copyToMap(), hasKey(INVOCATION_ID_KEY));
assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
示例7: soapMessageToString
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
public static String soapMessageToString(SOAPMessage soapMessage) throws Exception {
Source xmlInput = new DOMSource(soapMessage.getSOAPPart());
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
StringResult stringResult = new StringResult();
transformer.transform(xmlInput, stringResult);
return stringResult.toString();
}
示例8: KvitteringsReferanse
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
private KvitteringsReferanse(Reference reference) {
StringResult marshalledReference = new StringResult();
Jaxb2Marshaller marshallerSingleton = Marshalling.getMarshallerSingleton();
Marshalling.marshal(marshallerSingleton, reference, marshalledReference);
this.marshalled = marshalledReference.toString();
}
示例9: transform
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
private String transform(WebServiceMessage message) {
SaajSoapMessage saajSoapMessage = ((SaajSoapMessage) message);
StringResult stringResult = new StringResult();
try {
transformer.transform(new DOMSource(saajSoapMessage.getDocument()), stringResult);
} catch (TransformerException e) {
throw new RuntimeException(e);
}
return stringResult.toString();
}
示例10: serialize
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
/**
* Converts {@link Source} to {@link String}.
* @param source
* @return
*/
public static String serialize(Source source)
{
StringResult result = new StringResult();
transform(source, result);
return result.toString();
}
示例11: transform
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
/**
* Does XSLT transformation.
* @param template
* @param source
* @return
* @throws TransformerException
*/
Source transform(Source template, Source source)
{
try {
StringResult transformedExpectedDocument = new StringResult();
transform(template, source, transformedExpectedDocument);
return new StringSource(transformedExpectedDocument.toString());
} catch (TransformerException e) {
throw new IllegalArgumentException("Transformation error",e);
}
}
示例12: invokeInternalEx
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void invokeInternalEx(XTeeMessage<Document> request,
XTeeMessage<Element> response,
SOAPMessage requestMessage,
SOAPMessage responseMessage) throws Exception {
requestMessage.getSOAPHeader().detachNode();
Node bodyNode;
if (XRoadProtocolVersion.V2_0 == version) {
bodyNode = SOAPUtil.getNodeByXPath(requestMessage.getSOAPBody(), "//keha");
} else {
bodyNode = requestMessage.getSOAPBody();
}
Node reqNode = bodyNode.getParentNode();
NodeList nl = bodyNode.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node curNode = nl.item(i);
reqNode.appendChild(curNode.cloneNode(true));
}
reqNode.removeChild(bodyNode);
// Since Axis needs the XML as a String a transformation is required.
StringResult result = new StringResult();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(requestMessage.getSOAPPart().getEnvelope()), result);
Message axisMessage = new Message(result.toString());
// The context is very important, as the binding stub creates all the type bindings for proper unmarshalling.
axisMessage.setMessageContext(getContextHelper().getMessageContext());
// Adding the attachments is needed to handle "href" attributes where the data is in an attachment.
for (Iterator<AttachmentPart> i = requestMessage.getAttachments(); i.hasNext();) {
axisMessage.addAttachmentPart(i.next());
}
XTeeMessage<P> axisRequestMessage = new BeanXTeeMessage<P>(request.getHeader(),
(P) axisMessage.getSOAPEnvelope().getFirstBody().getObjectValue(getParingKehaClass()),
request.getAttachments());
XTeeMessage<V> axisResponseMessage =
new BeanXTeeMessage<V>(response.getHeader(), null, new ArrayList<XTeeAttachment>());
invoke(axisRequestMessage, axisResponseMessage);
V responseBean = axisResponseMessage.getContent();
// If response is null we return <keha/>, otherwise some marshalling needs to be done.
if (responseBean != null) {
String responseXml = AxisUtil.serialize(responseBean);
Document doc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(responseXml.getBytes("UTF-8")));
Node parent = response.getContent().getParentNode();
parent.removeChild(response.getContent());
parent.appendChild(parent.getOwnerDocument().importNode(doc.getFirstChild(), true));
}
}
示例13: serializeDocument
import org.springframework.xml.transform.StringResult; //导入方法依赖的package包/类
public String serializeDocument(Source source) {
StringResult result = new StringResult();
transform(source, result);
return result.toString();
}