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


Java StringResult类代码示例

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


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

示例1: testInvalidResponse

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
@Test
	@SuppressWarnings("unused")
	public void testInvalidResponse() throws IOException
	{
		WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
		webServiceTemplate.setCheckConnectionForFault(false);
		MockWebServiceMessageSender messageSender = new MockWebServiceMessageSender();
		DefaultResponseGenerator responseGenerator = new DefaultResponseGenerator();
		responseGenerator.setNeverCreateEnvelope(true);
		SimpleResourceLookup resourceLookup = new SimpleResourceLookup(new ClassPathResource("mock-responses/test/default-response-invalid.xml"));
		resourceLookup.setTemplateProcessor(new TemplateProcessor() {
			public Resource processTemplate(Resource resource, WebServiceMessage message) throws IOException {
				return resource;
			}
		});
		responseGenerator.setResourceLookup(resourceLookup);
		messageSender.setRequestProcessors(Arrays.asList(responseGenerator));
		webServiceTemplate.setMessageSender(messageSender);
		
		Source source = getValidMessage().getPayloadSource(); 
		StringResult result = new StringResult();
		//TODO uncomment
//		webServiceTemplate.sendSourceAndReceiveToResult(TEST_URI.toString(), source, result);		
	}
 
开发者ID:lukas-krecan,项目名称:spring-ws-test,代码行数:25,代码来源:InvalidMessagesTest.java

示例2: getTestResult

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
/**
 * Construct JSON test result from given test data.
 * @param test
 * @param cause
 * @param success
 * @return
 */
protected String getTestResult(TestCase test, Throwable cause, boolean success) {
    JSONObject resultObject = new JSONObject();
    JSONObject testObject = new JSONObject();

    testObject.put("name", test.getName());
    testObject.put("type", "JAVA");
    testObject.put("className", test.getTestClass().getSimpleName());
    testObject.put("packageName", test.getPackageName());

    resultObject.put("test", testObject);
    resultObject.put("processId", test.getName());
    resultObject.put("success", success);

    if (cause != null) {
        resultObject.put("errorMessage", cause.getMessage());
        resultObject.put("errorCause", cause.getCause() != null ? cause.getCause().getClass().getName() : cause.getClass().getName());

        StringResult stackTrace = new StringResult();
        cause.printStackTrace(new PrintWriter(stackTrace.getWriter()));
        resultObject.put("stackTrace", stackTrace.toString());
    }

    return resultObject.toJSONString();
}
 
开发者ID:christophd,项目名称:citrus-admin,代码行数:32,代码来源:WebSocketPushEventsListener.java

示例3: 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);
	}
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:19,代码来源:GOClientLogEvent.java

示例4: formatDate

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
private void formatDate(SaajSoapMessage saajMsg, Date date) throws TransformerException {
    if (date == null) {
        return;
    }
    SOAPPart soapPart = saajMsg.getSaajMessage().getSOAPPart();
    Source source = new DOMSource(soapPart);
    StringResult stringResult = new StringResult();
    TransformerFactory.newInstance().newTransformer().transform(source, stringResult);
    try {
        String from = dateWithTimezone.format(date);
        String to = dateWithoutTimezone.format(date);
        String content = StringUtils.replace(stringResult.toString(), from, to);
        soapPart.setContent(new StringSource(content));
    } catch (Exception e) {
        throw new TransformerException(e);
    }
}
 
开发者ID:nortal,项目名称:j-road,代码行数:18,代码来源:KirXTeeServiceImpl.java

示例5: substitute

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
/**
 * Substitutes all occurences of some given string inside the given {@link WebServiceMessage} with another value.
 *
 * @param message message to substitute in
 * @param from the value to substitute
 * @param to the value to substitute with
 * @throws TransformerException
 */
public static void substitute(WebServiceMessage message, String from, String to) throws TransformerException {
  SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
  SOAPPart soapPart = saajSoapMessage.getSaajMessage().getSOAPPart();

  Source source = new DOMSource(soapPart);
  StringResult stringResult = new StringResult();

  TransformerFactory.newInstance().newTransformer().transform(source, stringResult);

  String content = stringResult.toString().replaceAll(from, to);

  try {
    soapPart.setContent(new StringSource(content));
  } catch (SOAPException e) {
    throw new TransformerException(e);
  }
}
 
开发者ID:nortal,项目名称:j-road,代码行数:26,代码来源:SOAPUtil.java

示例6: 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);
    }
}
 
开发者ID:integram,项目名称:cleverbus,代码行数:28,代码来源:MessageTransformer.java

示例7: 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();
}
 
开发者ID:christophd,项目名称:citrus-simulator,代码行数:25,代码来源:SoapMessageHelper.java

示例8: testExpectAndReturn

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
@Test
public void testExpectAndReturn() throws IOException
{
	MockWebServiceMessageSender sender = (MockWebServiceMessageSender)new WsMockControl().expectRequest("xml/control-message-test.xml").returnResponse("mock-responses/test/default-response.xml").createMock();
	assertNotNull(sender);
	assertEquals(2, sender.getRequestProcessors().size());
	
	SimpleResourceLookup lookup1 = (SimpleResourceLookup)((XmlCompareRequestValidator)extractRequestProcessor(sender,0)).getControlResourceLookup();
	assertEquals("control-message-test.xml", lookup1.getResultResource().getFilename());
	assertTrue(((XmlCompareRequestValidator)extractRequestProcessor(sender, 0)).isIgnoreWhitespace());
	
	SimpleResourceLookup lookup2 = (SimpleResourceLookup)((DefaultResponseGenerator)extractRequestProcessor(sender,1)).getResourceLookup();
	assertEquals("default-response.xml", lookup2.getResultResource().getFilename());
	
	WebServiceTemplate template = new WebServiceTemplate();
	template.setMessageSender(sender);
	StringResult responseResult = new StringResult();
	template.sendSourceAndReceiveToResult(URI,createMessage("xml/valid-message.xml").getPayloadSource(), responseResult );
}
 
开发者ID:lukas-krecan,项目名称:spring-ws-test,代码行数:20,代码来源:WsMockControlTest.java

示例9: 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"));
}
 
开发者ID:tracee,项目名称:tracee,代码行数:19,代码来源:TraceeClientInterceptorTest.java

示例10: 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"));
}
 
开发者ID:tracee,项目名称:tracee,代码行数:19,代码来源:TraceeClientInterceptorTest.java

示例11: 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"));
}
 
开发者ID:tracee,项目名称:tracee,代码行数:20,代码来源:TraceeEndpointInterceptorTest.java

示例12: testCall

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
@Test
public void testCall() throws IOException, InterruptedException {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("com.sabre.api.sacs.contract.travelitinerary");
    Result marshalledRequest = new StringResult();
    marshaller.marshal(getRequestBody("ABCD"), marshalledRequest);
    Source requestPayload = new StringSource(marshalledRequest.toString());
    Source responsePayload = new StringSource(getResponseBody());
    mockServer.expect(payload(requestPayload)).andRespond(withSoapEnvelope(responsePayload));
    tir.setRequest(getRequestBody("ABCD"));
    tir.setLastInFlow(true);
    TravelItineraryReadRS response = tir.executeRequest(context);
    Assert.assertEquals(configuration.getSoapProperty("TravelItineraryReadRQVersion"), response.getVersion());
    mockServer.verify();
}
 
开发者ID:SabreDevStudio,项目名称:SACS-Java,代码行数:16,代码来源:TravelItineraryReadTest.java

示例13: 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();
}
 
开发者ID:thehyve,项目名称:Open-Clinica-Data-Uploader,代码行数:10,代码来源:SoapUtils.java

示例14: testCustomizeFaultObjectExceptionSoapFault

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
/**
 * Test method for
 * {@link py.una.pol.karaku.services.server.EndpointExceptionResolver#customizeFault(java.lang.Object, java.lang.Exception, org.springframework.ws.soap.SoapFault)}
 * .
 * 
 * @throws SecurityException
 * @throws NoSuchMethodException
 */
@Test
public void testCustomizeFaultObjectExceptionSoapFault() throws Exception {

	Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
	marshaller.setClassesToBeBound(HTTPExceptionDTO.class);

	EndpointExceptionResolver eer = new EndpointExceptionResolver();
	eer.setMarshaller(marshaller);

	Method m = Endpoint.class.getMethod("call", String.class);

	MethodEndpoint me = new MethodEndpoint(new Endpoint(), m);

	Fault f = new Fault();
	eer.customizeFault(me, new HTTPException("1", "code"), f);

	StringResult result = f.getFaultDetail().getResult();

	// @formatter:off
	String expectedResult = ""
			+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
			+ "<ns2:HTTPException xmlns:ns2=\"http://sigh.med.una.py/2013/schemas/base\">"
			+ "<code>1</code>"
			+ "<summary>code</summary>"
			+ "</ns2:HTTPException>";
	// @formatter:on
	assertEquals(result.toString(), expectedResult);

}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:38,代码来源:EndpointExceptionResolverTest.java

示例15: 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();
}
 
开发者ID:digipost,项目名称:sdp-shared,代码行数:9,代码来源:KvitteringsReferanse.java


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