WebServiceTemplate template = new WebServiceTemplate(messageFactory); Result result = new DOMResult(); template.sendSourceAndReceiveToResult( new StringSource("<content xmlns=\"http://tempuri.org\"/>"), new SoapActionCallback("http://tempuri.org/SOAPAction"), result);
getWebServiceTemplate().marshalSendAndReceive("https://soap.endpoint", requestObj, new WebServiceMessageCallback() { public void doWithMessage(WebServiceMessage message) { try { SoapMessage soapMessage = (SoapMessage)message; SoapHeader header = soapMessage.getSoapHeader(); StringSource headerSource = new StringSource("<Security><UsernameToken><SiteId>testlab1</SiteId>"+ "<Password>abcd1234</Password></UsernameToken></Security> "); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(headerSource, header.getResult()); } catch (Exception e) { // exception handling } } });
/** @inheritDoc */ public ImmutableGraph getGraph(EnhancementJobManager jobManager, ContentItemFactory ciFactory) throws EnhancementException { if(graph == null) { ContentItem ci; try { ci = ciFactory.createContentItem(new StringSource(inputText)); } catch (IOException e) { throw new IllegalStateException("Unable to create a ContentItem" + "using '"+ciFactory.getClass().getSimpleName()+"'!",e); } if(chain == null){ jobManager.enhanceContent(ci); } else { //parsing null as chain does not work! jobManager.enhanceContent(ci,chain); } graph = ci.getMetadata().getImmutableGraph(); } return graph; } }
.build()); ContentItem ci = ciFactory.createContentItem(new StringSource(content)); if(!buildAjaxview){ //rewrite to a normal EnhancementRequest return enhanceFromData(ci, false, null, false, null, false, null, headers);
.build()); ContentItem ci = ciFactory.createContentItem(new StringSource(content)); if(!buildAjaxview){ //rewrite to a normal EnhancementRequest return enhanceFromData(ci, false, null, false, null, false, null, headers);
/** * Tests correct handling of UTF-8 as default charset * @throws IOException */ @Test public void testString() throws IOException{ String test = "Exámplê"; //first via a StringSource ContentSource cs = new StringSource(test); Blob blob = createBlob(cs); Assert.assertEquals("text/plain", blob.getMimeType()); Assert.assertTrue(blob.getParameter().containsKey("charset")); Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset")); String value = new String(IOUtils.toByteArray(blob.getStream()),UTF8); Assert.assertEquals(test, value); } /**
/** * Tests correct handling of UTF-8 as default charset * @throws IOException */ @Test public void testString() throws IOException{ String test = "Exámplê"; //first via a StringSource ContentSource cs = new StringSource(test); Blob blob = createBlob(cs); Assert.assertEquals("text/plain", blob.getMimeType()); Assert.assertTrue(blob.getParameter().containsKey("charset")); Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset")); String value = new String(IOUtils.toByteArray(blob.getStream()),UTF8); Assert.assertEquals(test, value); } /**
/** * This tests that texts with custom charsets are converted to UTF-8. * @throws IOException */ @Test public void testStringWithCustomCharset() throws IOException{ String test = "Exámplê"; Charset ISO8859_4 = Charset.forName("ISO-8859-4"); //first via a StringSource ContentSource cs = new StringSource(test,ISO8859_4,"text/plain"); Blob blob = createBlob(cs); Assert.assertEquals("text/plain", blob.getMimeType()); Assert.assertTrue(blob.getParameter().containsKey("charset")); Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset")); //2nd via a ByteArray byte[] data = test.getBytes(ISO8859_4); cs = new ByteArraySource(data,"text/plain; charset="+ISO8859_4.name()); blob = createBlob(cs); Assert.assertEquals("text/plain", blob.getMimeType()); Assert.assertTrue(blob.getParameter().containsKey("charset")); Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset")); //3rd as Stream cs = new StreamSource(new ByteArrayInputStream(data), "text/plain; charset="+ISO8859_4.name()); blob = createBlob(cs); Assert.assertEquals("text/plain", blob.getMimeType()); Assert.assertTrue(blob.getParameter().containsKey("charset")); Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset")); cs = new StreamSource(new ByteArrayInputStream(data), "text/plain; "+ISO8859_4.name()); } /**
/** * This tests that texts with custom charsets are converted to UTF-8. * @throws IOException */ @Test public void testStringWithCustomCharset() throws IOException{ String test = "Exámplê"; Charset ISO8859_4 = Charset.forName("ISO-8859-4"); //first via a StringSource ContentSource cs = new StringSource(test,ISO8859_4,"text/plain"); Blob blob = createBlob(cs); Assert.assertEquals("text/plain", blob.getMimeType()); Assert.assertTrue(blob.getParameter().containsKey("charset")); Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset")); //2nd via a ByteArray byte[] data = test.getBytes(ISO8859_4); cs = new ByteArraySource(data,"text/plain; charset="+ISO8859_4.name()); blob = createBlob(cs); Assert.assertEquals("text/plain", blob.getMimeType()); Assert.assertTrue(blob.getParameter().containsKey("charset")); Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset")); //3rd as Stream cs = new StreamSource(new ByteArrayInputStream(data), "text/plain; charset="+ISO8859_4.name()); blob = createBlob(cs); Assert.assertEquals("text/plain", blob.getMimeType()); Assert.assertTrue(blob.getParameter().containsKey("charset")); Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset")); cs = new StreamSource(new ByteArrayInputStream(data), "text/plain; "+ISO8859_4.name()); } /**