List of usage examples for javax.xml.soap MessageFactory newInstance
public static MessageFactory newInstance() throws SOAPException
From source file:org.apache.axis2.saaj.AttachmentTest.java
@Validated @Test//from w ww . j a v a 2 s.c om public void testClearContent() throws Exception { try { InputStream in1 = TestUtils.getTestFile("attach.xml"); MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); AttachmentPart ap = message.createAttachmentPart(); MimeHeader mh = null; //Setting Mime Header ap.setMimeHeader("Content-Description", "some text"); //Setting Content Id Header ap.setContentId("id@abc.com"); //Setting Content ap.setContent(new StreamSource(in1), "text/xml"); //Clearing Content ap.clearContent(); try { //Getting Content InputStream is = (InputStream) ap.getContent(); fail("Error: SOAPException should have been thrown"); } catch (SOAPException e) { //Error thrown.(expected) } Iterator iterator = ap.getAllMimeHeaders(); int cnt = 0; boolean foundHeader1 = false; boolean foundHeader2 = false; boolean foundDefaultHeader = false; while (iterator.hasNext()) { cnt++; mh = (MimeHeader) iterator.next(); String name = mh.getName(); String value = mh.getValue(); if (name.equals("Content-Description") && value.equals("some text")) { if (!foundHeader1) { foundHeader1 = true; //MimeHeaders do match for header1 } else { fail("Error: Received the same header1 header twice"); } } else if (name.equalsIgnoreCase("Content-Id") && value.equals("id@abc.com")) { if (!foundHeader2) { foundHeader2 = true; //MimeHeaders do match for header2 } else { fail("Error: Received the same header2 header twice"); } } else if (name.equals("Content-Type") && value.equals("text/xml")) { if (!foundDefaultHeader) { foundDefaultHeader = true; //MimeHeaders do match for default header } else { fail("Error: Received the same default header header twice"); } } else { fail("Error: Received an invalid header"); } } if (!(foundHeader1 && foundHeader2)) { fail("Error: did not receive both headers"); } } catch (Exception e) { fail("Exception: " + e); } }
From source file:org.apache.axis2.saaj.AttachmentTest.java
@Validated @Test// w ww. j a v a 2 s .c om public void testGetContent() throws Exception { try { MessageFactory factory = MessageFactory.newInstance(); SOAPMessage msg = factory.createMessage(); AttachmentPart ap = msg.createAttachmentPart(); Image image = ImageIO.read(TestUtils.getTestFileURL("attach.gif")); ap = msg.createAttachmentPart(image, "image/gif"); //Getting Content should return an Image object Object o = ap.getContent(); if (o != null) { if (o instanceof Image) { //Image object was returned (ok) } else { fail("Unexpected object was returned"); } } } catch (Exception e) { fail("Exception: " + e); } }
From source file:org.apache.axis2.saaj.AttachmentTest.java
@Validated @Test//from w w w .j a v a2 s .c om public void testGetRawContents() { try { MessageFactory factory = MessageFactory.newInstance(); SOAPMessage msg = factory.createMessage(); AttachmentPart ap = msg.createAttachmentPart(); ap = msg.createAttachmentPart(); byte data1[] = null; data1 = ap.getRawContentBytes(); } catch (SOAPException e) { //Caught expected SOAPException } catch (NullPointerException e) { //Caught expected NullPointerException } catch (Exception e) { fail(); } }
From source file:org.apache.axis2.saaj.AttachmentTest.java
@Validated @Test//from ww w . ja va 2s. c o m public void testSetBase64Content() { try { MessageFactory factory = MessageFactory.newInstance(); SOAPMessage msg = factory.createMessage(); AttachmentPart ap = msg.createAttachmentPart(); String urlString = "http://ws.apache.org/images/project-logo.jpg"; if (isNetworkedResourceAvailable(urlString)) { URL url = new URL(urlString); DataHandler dh = new DataHandler(url); //Create InputStream from DataHandler's InputStream InputStream is = dh.getInputStream(); byte buf[] = IOUtils.getStreamAsByteArray(is); //Setting Content via InputStream for image/jpeg mime type ByteArrayOutputStream bos = new ByteArrayOutputStream(); Base64.encode(buf, 0, buf.length, bos); buf = bos.toByteArray(); InputStream stream = new ByteArrayInputStream(buf); ap.setBase64Content(stream, "image/jpeg"); //Getting Content.. should return InputStream object InputStream r = ap.getBase64Content(); if (r != null) { if (r instanceof InputStream) { //InputStream object was returned (ok) } else { fail("Unexpected object was returned"); } } } } catch (Exception e) { fail("Exception: " + e); } }
From source file:org.apache.hise.engine.jaxws.HISEJaxWSClient.java
@PostConstruct public void init() throws Exception { evaluator.declareNamespace("wsa", "http://www.w3.org/2005/08/addressing"); messageFactory = MessageFactory.newInstance(); destinationService = Service.create(wsdlDocumentLocation, serviceName); destinationPort = null;//from w ww . j ava 2s . c o m { Iterator<QName> it = destinationService.getPorts(); while (it.hasNext()) { QName p = it.next(); System.out.println(p); destinationPort = p; } } Validate.notNull(destinationPort, "Can't find port for service " + serviceName + " in " + wsdlDocumentLocation); }
From source file:org.apache.hise.engine.jaxws.HISEJaxWSService.java
public HISEJaxWSService() throws Exception { messageFactory = MessageFactory.newInstance(); }
From source file:org.apache.ws.scout.transport.SaajTransport.java
private SOAPMessage createSOAPMessage(Element elem) throws Exception { String prefix = ""; MessageFactory msgFactory = MessageFactory.newInstance(); SOAPFactory factory = SOAPFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); message.getSOAPHeader().detachNode(); SOAPPart soapPart = message.getSOAPPart(); SOAPBody soapBody = soapPart.getEnvelope().getBody(); //Create the outer body element Name bodyName = factory.createName(elem.getNodeName(), prefix, UDDI_V2_NAMESPACE); SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName); bodyElement.addNamespaceDeclaration(prefix, UDDI_V2_NAMESPACE); appendAttributes(bodyElement, elem.getAttributes(), factory); appendElements(bodyElement, elem.getChildNodes(), factory); return message; }
From source file:org.belio.service.gateway.SafcomGateway.java
private static SOAPMessage getSoapMessageFromString(String xml) throws SOAPException, IOException { MessageFactory factory = MessageFactory.newInstance(); javax.xml.soap.SOAPMessage message = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")))); return message; }
From source file:org.eevolution.LMX.engine.vendor.LMXFoliosDigitalesService.java
public String getXMLSealed(final String respxml) throws AdempiereException, IOException, SOAPException { String[] respuesta = null;/*w w w .jav a 2s . c o m*/ MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(respxml.getBytes(Charset.forName("UTF-8")))); SOAPBody body = message.getSOAPBody(); NodeList returnList = body.getElementsByTagName("TimbrarPruebaCFDIResult"); NodeList innerRes = returnList.item(0).getChildNodes(); boolean failed = false; respuesta = new String[innerRes.getLength()]; String messageError = null; for (int i = 0; i < innerRes.getLength(); i++) { respuesta[i] = innerRes.item(i).getTextContent(); if (i < 3 && !respuesta[i].equals("")) { failed = true; messageError = respuesta[i]; //System.out.println(messageError); } } if (failed) throw new AdempiereException(messageError); respuesta[3] = StringEscapeUtils.unescapeXml(respuesta[3]); return respuesta[3]; }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
private static SOAPMessage createSOAPRequest(String date) throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = "http://ws.i-em.eu/v4/"; // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("example", serverURI); // SOAP Body//from w ww .j ava 2s .c o m SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("Get72hPlantForecast", "example"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("plantID", "example"); soapBodyElem1.addTextNode("telecom_02"); SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("quantityID", "example"); soapBodyElem2.addTextNode("frc_pac"); SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("timestamp", "example"); soapBodyElem3.addTextNode(date); SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("langID", "example"); soapBodyElem4.addTextNode("en"); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + "Get72hPlantForecast"); soapMessage.saveChanges(); return soapMessage; }