You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.0 KiB
110 lines
3.0 KiB
package de.superx.bin; |
|
|
|
import java.io.BufferedWriter; |
|
import java.io.ByteArrayOutputStream; |
|
import java.io.File; |
|
import java.io.FileWriter; |
|
import java.util.logging.Logger; |
|
|
|
import javax.xml.soap.SOAPConnection; |
|
import javax.xml.soap.SOAPConnectionFactory; |
|
import javax.xml.soap.SOAPMessage; |
|
|
|
import de.memtext.util.LogUtils; |
|
|
|
public class WebserviceChecker extends AbstractWebserviceClient { |
|
public static String[] args; |
|
private static final Logger log = Logger.getLogger("wc"); |
|
|
|
public void run() { |
|
String testparam = ""; |
|
if (args.length > 3) |
|
testparam = args[3]; |
|
if (testparam.equals("multipletests")) |
|
multipletests(); |
|
else { |
|
singlerun(); |
|
} |
|
} |
|
|
|
private void singlerun() { |
|
SOAPMessage soapResponse = null; |
|
try { |
|
// Create SOAP Connection |
|
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); |
|
SOAPConnection soapConnection = soapConnectionFactory.createConnection(); |
|
|
|
// Send SOAP Message to SOAP Server |
|
StringBuffer url = readFile(new File(args[1])); |
|
|
|
SOAPMessage sr = getSoapMessageFromString(readFile(new File(args[0])).toString()); |
|
|
|
addAuthentification(sr); |
|
sr.getMimeHeaders().addHeader("SOAPAction", "http://sap.com/xi/WebService/soap1.1"); |
|
soapResponse = soapConnection.call(sr, adaptURL(url.toString())); |
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
soapResponse.writeTo(out); |
|
String strMsg = new String(out.toByteArray()); |
|
|
|
/** |
|
* old code problem with namespace when using OpenJDK 15 Transformer transformer |
|
* = TransformerFactory.newInstance() .newTransformer(); |
|
* |
|
* // optional indenting transformer.setOutputProperty(OutputKeys.INDENT, |
|
* "yes"); transformer.setOutputProperty( |
|
* "{http://xml.apache.org/xslt}indent-amount", "2"); //new |
|
* DOMSource(soapResponse.getSOAPPart(). |
|
* |
|
* transformer.transform(new DOMSource(soapResponse.getSOAPPart()), new |
|
* StreamResult(new File(args[2]))); |
|
* |
|
*/ |
|
|
|
BufferedWriter writer = new BufferedWriter(new FileWriter(args[2])); |
|
writer.write(format(strMsg)); |
|
|
|
writer.close(); |
|
soapConnection.close(); |
|
} catch (Exception e) { |
|
System.out.println("Es ist ein Fehler aufgetreten: " + e); |
|
try { |
|
System.out.println(soapResponse.getSOAPPart().getChildNodes().item(0)); |
|
} catch (Exception e1) { |
|
|
|
} |
|
|
|
e.printStackTrace(); |
|
} |
|
} |
|
|
|
private void multipletests() { |
|
System.out.println("Versuche ggfs. mehrfach aufzurufen"); |
|
try { |
|
LogUtils.initRawFileDateTime("wc", "WebserviceClient.log", 100000, 1, true, false); |
|
StringBuffer url = readFile(new File(args[1])); |
|
File f = createSoapFile(readFile(new File(args[0])).toString(), adaptURL(url.toString())); |
|
System.out.println("Outfile: " + f); |
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
} |
|
|
|
} |
|
|
|
public static void main(String a[]) { |
|
args = a; |
|
if (args.length < 3 || args.length > 4) { |
|
System.out |
|
.println("Usage path/to/envelope.xml path/to/urlfile /path/to/ouputfile.xml optional:multipleruns"); |
|
System.exit(-1); |
|
} |
|
WebserviceChecker wc = new WebserviceChecker(); |
|
wc.run(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
}
|
|
|