Skip to content

Commit

Permalink
Relying on XML_Utilities Library
Browse files Browse the repository at this point in the history
  • Loading branch information
CheariX committed Jan 19, 2017
1 parent dfc0a28 commit 6abe8d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 87 deletions.
5 changes: 5 additions & 0 deletions framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
<artifactId>SoapHttpClient</artifactId>
<version>1.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>wsattacker.library</groupId>
<artifactId>XML_Utilities_Library</artifactId>
<version>1.8-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
Expand Down
89 changes: 3 additions & 86 deletions framework/src/main/java/wsattacker/util/SoapUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,22 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Node;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import wsattacker.library.xmlutilities.dom.DomUtilities;

public class SoapUtilities
{
Expand Down Expand Up @@ -118,7 +105,7 @@ else if ( soapString.contains( SOAP_12_NAMESPACE_URL ) )
public static String soapToString( SOAPElement element )
{
// use the dom hepler function
return domToString( element.getOwnerDocument() );
return DomUtilities.domToString( element.getOwnerDocument() );
}

/**
Expand All @@ -132,77 +119,7 @@ public static String soapToString( SOAPElement element )
public static Document stringToDom( String xmlString )
throws SAXException
{
return stringToDom( xmlString, false );
}

/**
* Converts a String to a DOM. Sometimes, you might prefer DOM to SOAPElement.
*
* @param xmlString
* @param useNamespaces : Should the returned Document contain namespace prefixes?
* @return
* @throws SAXException
*/
public static Document stringToDom( String xmlString, boolean useNamespaces )
throws SAXException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware( useNamespaces );
StringReader reader = new StringReader( xmlString );
InputSource input = new InputSource( reader );
DocumentBuilder builder;
try
{
builder = factory.newDocumentBuilder();
}
catch ( ParserConfigurationException e )
{
log.fatal( "### Error - this should never happen: " + e.getMessage() );
return null;
}
Document dom;
try
{
dom = builder.parse( input );
}
catch ( IOException e )
{
log.fatal( "### Error - this should never happen: " + e.getMessage() );
return null;
}
return dom;
}

/**
* Converts a DOM to a String
*
* @param domDoc
* @return
*/
public static String domToString( Document domDoc )
{
StringWriter output = new StringWriter();
Transformer transformer = null;
try
{
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
transformer.transform( new DOMSource( domDoc ), new StreamResult( output ) );
}
catch ( TransformerConfigurationException e )
{
log.fatal( "### Error - Misconfigured Transformer Configuration, this should never happen: "
+ e.getMessage() );
}
catch ( TransformerFactoryConfigurationError e )
{
log.fatal( "### Error - Misconfigured Transformer Factory, this should never happen: " + e.getMessage() );
}
catch ( TransformerException e )
{
log.fatal( "### Error - Illegal Input, this should never happen: " + e.getMessage() );
}
return output.toString();
return DomUtilities.stringToDom( xmlString, false );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,18 @@ public static void writeDocument( Document doc, String filename, boolean prettyP
// String/DOM Conversation
public static Document stringToDom( String xmlString )
throws SAXException
{
return stringToDom( xmlString, true );
}

// *****************************************************************
// String/DOM Conversation
public static Document stringToDom( String xmlString, boolean namespaceAwareness )
throws SAXException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
factory.setNamespaceAware( true );
factory.setNamespaceAware( namespaceAwareness );
try
{
factory.setFeature( XMLConstants.FEATURE_SECURE_PROCESSING, true );
Expand Down

0 comments on commit 6abe8d6

Please sign in to comment.