Java Code Examples for javax.xml.soap.SOAPMessage#writeTo()

The following examples show how to use javax.xml.soap.SOAPMessage#writeTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXWSHandler.java    From cxf with Apache License 2.0 7 votes vote down vote up
protected void logToSystemOut(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (outboundProperty.booleanValue()) {
        out.println("\nOutbound message:");
    } else {
        out.println("\nInbound message:");
    }

    SOAPMessage message = smc.getMessage();
    try {
        message.writeTo(out);
        out.println();
    } catch (Exception e) {
        out.println("Exception in handler: " + e);
    }

    out.println("WSDL_SERVICE = " + smc.get(MessageContext.WSDL_SERVICE));
    out.println("WSDL_INTERFACE = " + smc.get(MessageContext.WSDL_INTERFACE));
    out.println("WSDL_PORT = " + smc.get(MessageContext.WSDL_PORT));
    out.println("WSDL_OPERATION = " + smc.get(MessageContext.WSDL_OPERATION));
}
 
Example 2
Source File: LoggingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void logToSystemOut(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean)
        smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (outboundProperty.booleanValue()) {
        out.println("\nOutbound message:");
    } else {
        out.println("\nInbound message:");
    }

    SOAPMessage message = smc.getMessage();
    try {
        message.writeTo(out);
        out.println();
    } catch (Exception e) {
        out.println("Exception in handler: " + e);
    }
}
 
Example 3
Source File: SoapRequestBean.java    From openxds with Apache License 2.0 6 votes vote down vote up
private static void printMessage(SOAPMessage message, String headerType) throws IOException, SOAPException {
    if (message != null) {
        //get the mime headers and print them
        System.out.println("\n\nHeader: " + headerType);
        if (message.saveRequired()) {
            message.saveChanges();
        }
        MimeHeaders headers = message.getMimeHeaders();
        printHeaders(headers);
        
        //print the message itself
        System.out.println("\n\nMessage: " + headerType);
        message.writeTo(System.out);
        System.out.println();
    }
}
 
Example 4
Source File: LoggingHandler.java    From jplag with GNU General Public License v3.0 6 votes vote down vote up
private String logSOAPMessage(MessageContext context) {
		StringBuffer stringBuffer = new StringBuffer();
		SOAPMessageContext smc = (SOAPMessageContext) context;
		SOAPMessage soapMessage = smc.getMessage();
/*		try
		{
			SOAPBody soapBody = soapMessage.getSOAPBody();
			NodeList list=soapBody.getElementsByTagName("inputZipFile");
		}
		catch(Exception e)
		{
			// ignore filtering
		}*/

		ByteArrayOutputStream bout= new ByteArrayOutputStream();
		try {
			soapMessage.writeTo(bout);
		} catch(Exception e) {
			e.printStackTrace(System.out);
		}
		stringBuffer.append(bout.toString() + "\n");

		return stringBuffer.toString();
	}
 
Example 5
Source File: LoggingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void logToSystemOut(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (outboundProperty.booleanValue()) {
        //out.println("\nOutbound message:");
    } else {
        //out.println("\nInbound message:");
    }

    SOAPMessage message = smc.getMessage();
    try {
        message.writeTo(out);
        //out.println();
    } catch (Exception e) {
        //out.println("Exception in handler: " + e);
        e.printStackTrace();
    }
}
 
Example 6
Source File: ServiceModelTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getFormatedDocument(SOAPMessage message) {
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformerFactory.setAttribute("indent-number", new Integer(4));
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");

        StreamResult result = new StreamResult(new StringWriter());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        message.writeTo(bos);
        String output = bos.toString();
        InputStream bis = new ByteArrayInputStream(output.getBytes());
        StreamSource source = new StreamSource(bis);

        transformer.transform(source, result);

        return result.getWriter().toString();
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
Example 7
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static  String getFormatedDocument(SOAPMessage message) {
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformerFactory.setAttribute("indent-number", 4);
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        
        StreamResult result = new StreamResult(new StringWriter());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        message.writeTo(bos);
        InputStream bis = new ByteArrayInputStream(bos.toByteArray());
        StreamSource source = new StreamSource(bis);
        
        transformer.transform(source, result);
        
        return result.getWriter().toString();
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
Example 8
Source File: LoggingHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
/** {@inheritDoc} */
public boolean handleMessage(SOAPMessageContext c) {

	SOAPMessage msg = c.getMessage();
	try {

		ByteArrayOutputStream out = new ByteArrayOutputStream();			
		msg.writeTo(out);			
		LOG.debug(out.size() + " bytes - " + out.toString());


		if( MessageDumper.getInstance().isDumpEnabled() ){
			final Boolean outboundProperty = (Boolean) c.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
			if (outboundProperty) {
				MessageDumper.getInstance().dump(out, MessageDumper.getOperationName(c), MessageDumper.OUT);
			} else {
				MessageDumper.getInstance().dump(out, MessageDumper.getOperationName(c), MessageDumper.IN);
			}
		}
		out.close();
	} catch (Throwable t) {
		LOG.warn("SOAPException when logging the message: ",t);
	}
	return true;
}
 
Example 9
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getEnvelope(SOAPMessage message) throws SOAPException, IOException {
   ByteArrayOutputStream stream = new ByteArrayOutputStream();

   String var3;
   try {
      message.writeTo(stream);
      if (stream.size() >= 1232896) {
         var3 = "message to large to log";
         return var3;
      }

      var3 = stream.toString(Charset.UTF_8.getName());
   } finally {
      ConnectorIOUtils.closeQuietly((Object)stream);
   }

   return var3;
}
 
Example 10
Source File: LoggingHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
/** {@inheritDoc} */
public boolean handleMessage(SOAPMessageContext c) {

	SOAPMessage msg = c.getMessage();
	try {

		ByteArrayOutputStream out = new ByteArrayOutputStream();			
		msg.writeTo(out);			
		LOG.debug(out.size() + " bytes - " + out.toString());


		if( MessageDumper.getInstance().isDumpEnabled() ){
			final Boolean outboundProperty = (Boolean) c.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
			if (outboundProperty) {
				MessageDumper.getInstance().dump(out, MessageDumper.getOperationName(c), MessageDumper.OUT);
			} else {
				MessageDumper.getInstance().dump(out, MessageDumper.getOperationName(c), MessageDumper.IN);
			}
		}
		out.close();
	} catch (Throwable t) {
		LOG.warn("SOAPException when logging the message: ",t);
	}
	return true;
}
 
Example 11
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getEnvelope(SOAPMessage message) throws SOAPException, IOException {
   ByteArrayOutputStream stream = new ByteArrayOutputStream();

   String var3;
   try {
      message.writeTo(stream);
      if (stream.size() >= 1232896) {
         var3 = "message to large to log";
         return var3;
      }

      var3 = stream.toString(Charset.UTF_8.getName());
   } finally {
      ConnectorIOUtils.closeQuietly((Object)stream);
   }

   return var3;
}
 
Example 12
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getEnvelope(SOAPMessage message) throws SOAPException, IOException {
   ByteArrayOutputStream stream = new ByteArrayOutputStream();

   String var3;
   try {
      message.writeTo(stream);
      if (stream.size() >= 1232896) {
         var3 = "message to large to log";
         return var3;
      }

      var3 = stream.toString(Charset.UTF_8.getName());
   } finally {
      ConnectorIOUtils.closeQuietly((Object)stream);
   }

   return var3;
}
 
Example 13
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getEnvelope(SOAPMessage message) throws SOAPException, IOException {
   ByteArrayOutputStream stream = new ByteArrayOutputStream();

   String var3;
   try {
      message.writeTo(stream);
      if (stream.size() >= 1232896) {
         var3 = "message to large to log";
         return var3;
      }

      var3 = stream.toString(Charset.UTF_8.getName());
   } finally {
      ConnectorIOUtils.closeQuietly((Object)stream);
   }

   return var3;
}
 
Example 14
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getEnvelope(SOAPMessage message) throws SOAPException, IOException {
   ByteArrayOutputStream stream = new ByteArrayOutputStream();

   String var3;
   try {
      message.writeTo(stream);
      if (stream.size() < 1232896) {
         var3 = stream.toString(Charset.UTF_8.getName());
         return var3;
      }

      var3 = "message to large to log";
   } finally {
      ConnectorIOUtils.closeQuietly((Object)stream);
   }

   return var3;
}
 
Example 15
Source File: InsurabilityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleMessage(SOAPMessageContext c) {
   try {
      Boolean outboundProperty = (Boolean)c.get("javax.xml.ws.handler.message.outbound");
      if (!outboundProperty.booleanValue()) {
         SOAPMessage msg = c.getMessage();
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         msg.writeTo(out);
         Node elementsGetPrescriptionForExecutorResponse = (Node)msg.getSOAPBody().getChildElements().next();
         NodeList elements = elementsGetPrescriptionForExecutorResponse.getChildNodes();

         for(int i = 0; i < elements.getLength(); ++i) {
            org.w3c.dom.Node element = elements.item(i);
            if (element.getLocalName() != null && (element.getLocalName().equals("GetInsurabilityForPharmacistResponse") || element.getLocalName().equals("InsurabilityResponse"))) {
               initMessageID(msg);
               Transformer t = TransformerFactory.newInstance().newTransformer();
               StringWriter sw = new StringWriter();
               t.transform(new DOMSource(element), new StreamResult(sw));
               insurability = sw.toString();
               break;
            }
         }
      }
   } catch (Throwable var11) {
      LOG.warn("SOAPException when retrieving insurability the message", var11);
   }

   return true;
}
 
Example 16
Source File: XmlTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void test() throws Exception {

        File file = new File("message.xml");
        file.deleteOnExit();

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage msg = createMessage(mf);

        // Save the soap message to file
        try (FileOutputStream sentFile = new FileOutputStream(file)) {
            msg.writeTo(sentFile);
        }

        // See if we get the image object back
        try (FileInputStream fin = new FileInputStream(file)) {
            SOAPMessage newMsg = mf.createMessage(msg.getMimeHeaders(), fin);

            newMsg.writeTo(new ByteArrayOutputStream());

            Iterator<?> i = newMsg.getAttachments();
            while (i.hasNext()) {
                AttachmentPart att = (AttachmentPart) i.next();
                Object obj = att.getContent();
                if (!(obj instanceof StreamSource)) {
                    fail("Got incorrect attachment type [" + obj.getClass() + "], " +
                         "expected [javax.xml.transform.stream.StreamSource]");
                }
            }
        }

    }
 
Example 17
Source File: SugarUtil.java    From Java-OCA-OCPP with MIT License 5 votes vote down vote up
public static String soapMessageToString(SOAPMessage message) {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  try {
    message.writeTo(out);
  } catch (SOAPException | IOException e) {
    return "";
  }
  return new String(out.toByteArray());
}
 
Example 18
Source File: SoapRequestBean.java    From openxds with Apache License 2.0 5 votes vote down vote up
private ByteArrayOutputStream printWebMessage(SOAPMessage message, String headerType, ByteArrayOutputStream bye) throws IOException, SOAPException {
    
    PrintStream printStream = new PrintStream(bye);
    bye.reset();
    
    printStream.println("\n************************************************");
    if (message != null) {
        //get the mime headers and print them
        printStream.println("\n\nHeader: " + headerType);
        if (message.saveRequired()) {
            message.saveChanges();
        }
        MimeHeaders headers = message.getMimeHeaders();
        Iterator iter = headers.getAllHeaders();
        while (iter.hasNext()) {
            MimeHeader header = (MimeHeader)iter.next();
            System.out.println("the header is " + header.getValue());
            printStream.println("\t" + header.getName() + " : " + header.getValue());
        }
        
        //print the message itself
        
        printStream.println("\n\nMessage: " + headerType);
        message.writeTo(bye);
    }
    return bye;
}
 
Example 19
Source File: CompilatioAPIUtil.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public static Document callCompilatioReturnDocument(String apiURL, Map<String, String> parameters, String secretKey,
		final int timeout) throws TransientSubmissionException, SubmissionException {

	SOAPConnectionFactory soapConnectionFactory;
	Document xmlDocument = null;
	try {
		soapConnectionFactory = SOAPConnectionFactory.newInstance();

		SOAPConnection soapConnection = soapConnectionFactory.createConnection();

		MessageFactory messageFactory = MessageFactory.newInstance();
		SOAPMessage soapMessage = messageFactory.createMessage();
		SOAPPart soapPart = soapMessage.getSOAPPart();
		SOAPEnvelope envelope = soapPart.getEnvelope();
		SOAPBody soapBody = envelope.getBody();
		SOAPElement soapBodyAction = soapBody.addChildElement(parameters.get("action"));
		parameters.remove("action");
		// api key
		SOAPElement soapBodyKey = soapBodyAction.addChildElement("key");
		soapBodyKey.addTextNode(secretKey);

		Set<Entry<String, String>> ets = parameters.entrySet();
		Iterator<Entry<String, String>> it = ets.iterator();
		while (it.hasNext()) {
			Entry<String, String> param = it.next();
			SOAPElement soapBodyElement = soapBodyAction.addChildElement(param.getKey());
			soapBodyElement.addTextNode(param.getValue());
		}
		
		URL endpoint = new URL(null, apiURL, new URLStreamHandler() {
			@Override
			protected URLConnection openConnection(URL url) throws IOException {
				URL target = new URL(url.toString());
				URLConnection connection = target.openConnection();
				// Connection settings
				connection.setConnectTimeout(timeout);
				connection.setReadTimeout(timeout);
				return(connection);
			}
		});
		
		SOAPMessage soapResponse = soapConnection.call(soapMessage, endpoint);

		// loading the XML document
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		soapResponse.writeTo(out);
		DocumentBuilderFactory builderfactory = DocumentBuilderFactory.newInstance();
		builderfactory.setNamespaceAware(true);

		DocumentBuilder builder = builderfactory.newDocumentBuilder();
		xmlDocument = builder.parse(new InputSource(new StringReader(out.toString())));
		soapConnection.close();

	} catch (UnsupportedOperationException | SOAPException | IOException | ParserConfigurationException | SAXException e) {
		log.error(e.getLocalizedMessage(), e);
	}
	return xmlDocument;

}
 
Example 20
Source File: SignCodeMojo.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
private String makeSigningRequest(SignedFiles signedFiles) throws SOAPException, IOException, MojoExecutionException {
    log("Constructing the code signing request");

    SOAPMessage message = SOAP_MSG_FACTORY.createMessage();
    SOAPBody body = populateEnvelope(message, NS);

    SOAPElement requestSigning = body.addChildElement("requestSigning", NS);
    SOAPElement requestSigningRequest =
            requestSigning.addChildElement("requestSigningRequest", NS);

    addCredentials(requestSigningRequest, this.userName, this.password, this.partnerCode);

    SOAPElement applicationName =
            requestSigningRequest.addChildElement("applicationName", NS);
    applicationName.addTextNode(this.applicationName);

    SOAPElement applicationVersion =
            requestSigningRequest.addChildElement("applicationVersion", NS);
    applicationVersion.addTextNode(this.applicationVersion);

    SOAPElement signingServiceName =
            requestSigningRequest.addChildElement("signingServiceName", NS);
    signingServiceName.addTextNode(this.signingService);

    SOAPElement commaDelimitedFileNames =
            requestSigningRequest.addChildElement("commaDelimitedFileNames", NS);
    commaDelimitedFileNames.addTextNode(signedFiles.getCommaSeparatedUploadFileNames());

    SOAPElement application =
            requestSigningRequest.addChildElement("application", NS);
    application.addTextNode(signedFiles.getApplicationString());

    // Send the message
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();

    log("Sending signing request to server and waiting for response");
    SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);

    if ( getLog().isDebugEnabled()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(2 * 1024);
        response.writeTo(baos);
        getLog().debug(baos.toString("UTF-8"));
    }

    log("Processing response");
    SOAPElement responseBody = response.getSOAPBody();

    // Should come back signed
    NodeList bodyNodes = responseBody.getChildNodes();
    NodeList requestSigningResponseNodes = bodyNodes.item(0).getChildNodes();
    NodeList returnNodes = requestSigningResponseNodes.item(0).getChildNodes();

    String signingSetID = null;
    String signingSetStatus = null;
    StringBuilder errors = new StringBuilder();

    for (int i = 0; i < returnNodes.getLength(); i++) {
        Node returnNode = returnNodes.item(i);
        if (returnNode.getLocalName().equals("signingSetID")) {
            signingSetID = returnNode.getTextContent();
        } else if (returnNode.getLocalName().equals("signingSetStatus")) {
            signingSetStatus = returnNode.getTextContent();
        } else if (returnNode.getLocalName().equals("result") ) {
            final NodeList returnChildNodes = returnNode.getChildNodes();
            for (int j = 0; j < returnChildNodes.getLength(); j++ ) {
                if ( returnChildNodes.item(j).getLocalName().equals("errors") ) {
                    extractErrors(returnChildNodes.item(j), errors);
                }
            }
        }
    }

    if (!signingService.contains("TEST") && !"SIGNED".equals(signingSetStatus) ||
            signingService.contains("TEST") && !"INITIALIZED".equals(signingSetStatus) ) {
        throw new BuildException("Signing failed. Status was: " + signingSetStatus + " . Reported errors: " + errors + ".");
    }

    return signingSetID;
}