So I have a script file we are using in house for testing. I want to use the script for testing over the internet but when I give it a url instead of a ip address it throws a java.lang.NoClassDefFoundError,
Why is this and what can I do to fix it
this is the script file:
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class SOAPClient4XG
{
public static void main(String[] paramArrayOfString)
throws Exception
{
if (paramArrayOfString.length < 2) {
System.err.println("Usage: java SOAPClient4XG http://soapURL soapEnvelopefile.xml [SOAPAction]");
System.err.println("SOAPAction is optional.");
System.exit(1);
}
String str1 = paramArrayOfString[0];
String str2 = paramArrayOfString[1];
String str3 = "";
if (paramArrayOfString.length > 2) {
str3 = paramArrayOfString[2];
}
URL localURL = new URL(str1);
URLConnection localURLConnection = localURL.openConnection();
HttpURLConnection localHttpURLConnection = (HttpURLConnection)localURLConnection;
FileInputStream localFileInputStream = new FileInputStream(str2);
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
copy(localFileInputStream, localByteArrayOutputStream);
localFileInputStream.close();
byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
localHttpURLConnection.setRequestProperty("Content-Length", String.valueOf(arrayOfByte.length));
localHttpURLConnection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
localHttpURLConnection.setRequestProperty("SOAPAction", str3);
localHttpURLConnection.setRequestMethod("POST");
localHttpURLConnection.setDoOutput(true);
localHttpURLConnection.setDoInput(true);
OutputStream localOutputStream = localHttpURLConnection.getOutputStream();
localOutputStream.write(arrayOfByte);
localOutputStream.close();
InputStreamReader localInputStreamReader = new InputStreamReader(localHttpURLConnection.getInputStream());
BufferedReader localBufferedReader = new BufferedReader(localInputStreamReader);
String str4;
while ((str4 = localBufferedReader.readLine()) != null) {
System.out.println(str4);
}
localBufferedReader.close();
}
public static void copy(InputStream paramInputStream, OutputStream paramOutputStream)
throws IOException
{
synchronized ()
{
synchronized (paramOutputStream)
{
byte[] arrayOfByte = new byte['Ā'];
for (;;) {
int i = paramInputStream.read(arrayOfByte);
if (i == -1) break;
paramOutputStream.write(arrayOfByte, 0, i);
}
}
}
}
}
and the bat file used to run it is this:
echo Check in inquiry sending:
java -cp .SOAPClient4XG http://foobar/gotdns/com:8080/axis2/services/HTNGListener checkininquiry.sms http://htng.org/1.1/Listener.Wsdl#ReceiveMessageAsync
here is the stack trace:
C:\Documents and Settings\accounting\Desktop\springer_miller_docs>java -cp .SOAP
Client4XG http://foobar.gotdns.com:8080/axis2/services/HTNGListener checkinin
quiry.sms http://htng.org/1.1/Listener.Wsdl#ReceiveMessageAsync
Exception in thread "main" java.lang.NoClassDefFoundError: http://foobar/gotd
ns/com:8080/axis2/services/HTNGListener
Your problem has nothing to do with your code but how you’re executing it.
Your command line says put the main file onto the class path and then execute main in a class named the first URL.
Leave off -cp and you should be fine (at least from this stack trace).
For reference: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html