Having installed a new 10g database and then installed the cmsxdb onto it, I followed the instructions for deploying the application. This completed, and the application was started using the web browser.Upon attempting to login the following error is displayed :Stack Trace : oracle.otnsamples.cmsxdb.exception.CMSAccessException: Error sending request : java.io.IOException: Premature EOF
at oracle.otnsamples.cmsxdb.useraction.ServletUtils.sendRequest(ServletUtils.java:165)
at oracle.otnsamples.cmsxdb.useraction.DataUtils.serveRequest(DataUtils.java:330)
at _Contents_2e_jsp._jspService(_Contents_2e_jsp.java:121)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:365)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:519)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:423)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:771)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:298)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:829)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:291)
at java.lang.Thread.run(Thread.java:534)谁用过cmsxdb这个示例程序,所有的运行时参数我按照安装说明已成功配置,但在运行时总是出现上述错误,我调试了很久了,大约有半个多月了,快郁闷坏了,谁能帮助我??请各位大虾不吝赐教!

解决方案 »

  1.   

    代码如下:
    public HttpURLConnection getServerConnection( String server, String username,
                                                String password ) 
          throws Exception {    HttpURLConnection urlConn = null;
        
        URL url = new URL(server);    // Build the string to be used for Basic Authentication <username>:<password>
        String userPassword =  username + ":" + password;    // Base64 encode the authentication string
        String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());    //URLConnection
        urlConn = (HttpURLConnection) url.openConnection();    // Enable writing to server ( to write request )
        urlConn.setDoOutput(true);
          
        // Enable reading from server ( to read response )
        urlConn.setDoInput(true);    // Disable cache
        urlConn.setUseCaches(false);
        urlConn.setDefaultUseCaches(false);    // Set Basic Authentication parameters
        urlConn.setRequestProperty ("Authorization", "Basic " + encoding);    return urlConn;    
      }  /**
       * This method sends the specified request to the given url and returns the
       * response as an Object. If the returned Object is an instance of 
       * CMSAccessException, throws it.
       * 
       * @param     req  HttpServletRequest that has to be sent to the server
       * @param     servletUrl URL of the server to send request
       * @param     username user name to be used for authentication with server
       * @param     password password to be user for authentication with server
       * 
       * @return  Response from the server
       * 
       * @exception CMSAccessException if server could not handle the request
       */
      public Object sendRequest(HttpServletRequest req, String servletUrl,
                                String username, String password)
          throws CMSAccessException {    // Response from server
        Object responseObj = null;
        
        HttpURLConnection urlConn = null;    try {      String res = "Nothing was returned";      urlConn = this.getServerConnection(servletUrl, username, password);      String contenttype = req.getHeader( "Content-Type" );      // Set Content Type 
          if (contenttype != null) {
            urlConn.setRequestProperty("Content-Type", contenttype);
          } else {
            urlConn.setRequestProperty("Content-Type", "text/plain");
          }      // Get output stream of server to send the request
          BufferedOutputStream connOut = new BufferedOutputStream(urlConn.getOutputStream());      // Establish connection to server
          urlConn.connect();      byte[] buffer = new byte[ BUFFSIZE ]; 
          int len = 0;      // Get the input stream for request
          ServletInputStream in = req.getInputStream();      // Write request
          while ((len = in.read(buffer,0,buffer.length )) >-1) {
            connOut.write(buffer,0,len);
          }      // Close 
          connOut.flush();
          connOut.close();
          in.close();      // Completed sending request, now read response      // Read the object send by server
          ObjectInputStream inputFromServlet = new ObjectInputStream(urlConn.getInputStream());
          responseObj = inputFromServlet.readObject();
          inputFromServlet.close();    } catch (Exception ex) {      throw new CMSAccessException ( "Error sending request  : " +
                                         ex.toString() );    } finally {      // Disconnect
          if( urlConn != null ) {
            urlConn.disconnect();
            urlConn = null;
          }      }    // Check if response is an error message
        if ( responseObj instanceof CMSAccessException ) {
          throw (CMSAccessException)responseObj;
        }    return responseObj;  }
    当调试到responseObj = inputFromServlet.readObject()时就出现premature EOF错误!
      

  2.   

    Oracle XML DB之cmsxdb示例程序可到http://www.oracle.com/technology/sample_code/tech/xml/xmldb/index.html
    下载。
      

  3.   

    解决了,编码和解码的问题。因为在向服务器发送请求时使用了URLEncoding.encode(URL),导致在服务器端无法正确读取uRL信息,使得返回的对象为空,所以在读取的时候总是出现Premature EOF错误;解决的方法是将URLEncoding.encode(URL)改为URLEncoding.encode(URL)即可。