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

Java StringResult类代码示例

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

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



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


示例16: 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();
}
 
开发者ID:koen-serneels,项目名称:ws-proxy,代码行数:11,代码来源:LoggingInterceptor.java


示例17: testResponse

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
private void testResponse(String response) throws IOException, SAXException {
	mockControl.returnResponse(response);
	
	StringResult responseResult = new StringResult();
	template.sendSourceAndReceiveToResult(TEST_URI.toString(),createMessage("xml/valid-message.xml").getPayloadSource(), responseResult );
	
	Diff diff = XMLUnit.compareXML(new InputStreamReader(new ClassPathResource(response).getInputStream()), responseResult.toString());
	assertTrue(diff.toString(), diff.similar());
}
 
开发者ID:lukas-krecan,项目名称:spring-ws-test,代码行数:10,代码来源:AnnotationConfigTest.java


示例18: doTemplateTest

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
private void doTemplateTest(MockWebServiceMessageSender sender) throws IOException, SAXException {
	assertNotNull(sender);
	assertEquals(2, sender.getRequestProcessors().size());
	
	WsTestContextHolder.getTestContext().setAttribute("number", 2);
	
	WebServiceTemplate template = new WebServiceTemplate();
	template.setMessageSender(sender);
	StringResult responseResult = new StringResult();
	template.sendSourceAndReceiveToResult(URI,createMessage("xml/valid-message2.xml").getPayloadSource(), responseResult);
	
	Diff diff = XMLUnit.compareXML(new InputStreamReader(new ClassPathResource("xml/resolved-different-response.xml").getInputStream()), responseResult.toString());
	assertTrue(diff.toString(), diff.similar());
}
 
开发者ID:lukas-krecan,项目名称:spring-ws-test,代码行数:15,代码来源:WsMockControlTest.java


示例19: testExpectResourceNotFound

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
@Test(expected=WebServiceIOException.class)
public void testExpectResourceNotFound() throws IOException
{
	MockWebServiceMessageSender sender = (MockWebServiceMessageSender)new WsMockControl().expectRequest("xml/does-not-exist.xml").returnResponse("mock-responses/test/default-response.xml").createMock();
	assertNotNull(sender);
	assertEquals(2, sender.getRequestProcessors().size());
	
	
	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,代码行数:14,代码来源:WsMockControlTest.java


示例20: testVerifyUri

import org.springframework.xml.transform.StringResult; //导入依赖的package包/类
@Test(expected=WsTestException.class)
public void testVerifyUri() throws IOException, URISyntaxException
{
	MockWebServiceMessageSender sender = (MockWebServiceMessageSender)new WsMockControl().expectUri(new URI("http://example.com")).returnResponse("mock-responses/test/default-response.xml").createMock();
	assertNotNull(sender);
	assertEquals(2, sender.getRequestProcessors().size());
	
	
	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,代码行数:14,代码来源:WsMockControlTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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