日期:2014-05-17  浏览次数:20911 次

java.io.IOException:Server returned HTTP response code: 500 for URL 高手入内,高分结帖!!!!


我做的是用SOAP传输XML信息到服务器。我觉得代码没有问题,但总是报以下错误。
我用的是JDK1.6 Tomcat   5.0     Eclipse   3.1.2   操作系统是Windows   Server   2003
程序清单和运行结果如下所示。
程序如下:

package   cn;

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.net.HttpURLConnection;
import   java.net.URL;
import   java.net.URLConnection;

public   class   SOAPClient4XG   {

public   static   void   main(String[]   args)   throws   Exception   {

String   SOAPUrl   =   "http://localhost:8080/soap/servlet/rpcrouter ";
String   xmlFile2Send   =   "src/cn/weattherreq.xml ";
String   SOAPAction   =   " ";

// if   (args.length   >   2)
// SOAPAction   =   args[2];

//   Create   the   connection   where   we 're   going   to   send   the   file.
URL   url   =   new   URL(SOAPUrl);
URLConnection   connection   =   url.openConnection();
HttpURLConnection   httpConn   =   (HttpURLConnection)connection;
//   Open   the   input   file.After   we   copy   it   to   a   byte   array,   we   can   see
//   how   big   it   is   so   that   we   can   set   the   HTTP   Cotent-Length
//   property.(See   complete   e-mail   below   for   more   on   this.)

FileInputStream   fin   =   new   FileInputStream(xmlFile2Send);

System.out.println(fin);
System.out.println( "............................................... ");

ByteArrayOutputStream   bout   =   new   ByteArrayOutputStream();

//   Copy   the   SOAP   file   to   the   open   connection.
copy(fin,   bout);
fin.close();
byte[]   b   =   bout.toByteArray();

//   Set   the   appropriate   HTTP   parameters.
httpConn.setRequestProperty( "Content-Length ",   String.valueOf(b.length));
httpConn.setRequestProperty( "Content-Type ",   "text/xml;   charset=utf-8 ");
httpConn.setRequestProperty( "SOAPAction ",   SOAPAction);
httpConn.setRequestMethod( "POST ");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
System.out.println( "111111111111111111111111111 ");
//   Everything 's   set   up;   send   the   XML   that   was   read   in   to   b.
OutputStream   out   =   httpConn.getOutputStream();
out.write(b);
out.close();
System.out.println( "2222222222222222222222222 ");
//   Read   the   response   and   write   it   to   standard   out.
InputStreamReader   isr   =   new   InputStreamReader(httpConn.getInputStream());
BufferedReader   in