Hi
guys i got solution by which i can push my data in the form of serialized Java bean to servlet using following sample code , if any one have better approach let me know.
 
Cheers
Suhel
 

URL curPage = getCodeBase();
      String protocol = curPage.getProtocol();
      String host = curPage.getHost();
      int port = curPage.getPort();
      String urlSuf = "/servlet/com.sony.spe.gemgpms.productioservlet";
      URL dataURL = new URL(protocol,host,port,urlSuf);
      System.out.println("dataURL:"+dataURL);
      System.out.println("Connecting ..");
      URLConnection conn = dataURL.openConnection();
      System.out.println("Connected.");
      System.out.println("con:"+conn);
      conn.setUseCaches(false);
      //conn.setDoInput(true);
      conn.setDoOutput(true);
      conn.setRequestProperty("Content-Type", "application/x-java-serialized-object");
      //conn.setRequestProperty("Content-Type", "java-internal/"+iData.getClass().getName());
      //conn.setRequestProperty("Content-Type", "application/octet-stream");
      //conn.connect();
      ObjectOutputStream oi = new ObjectOutputStream(conn.getOutputStream());
      oi.writeObject(iData);//iData is not null or empty, it is serializable.
      oi.flush();
      //oi.close();
      //ByteArrayOutputStream bos = new ByteArrayOutputStream(512);
      //bos.write(new char[]{1,2,3});
      //bos.flush()
      //System.out.println("oi:"+oi);
      //System.out.println("Content length "+String.valueOf(bos.size()));
      //conn.setRequestProperty("Content-Length", String.valueOf(bos.size()));
      //bos.writeTo(conn.getOutputStream());
      //os.flush();
      //os.close();
      System.out.println("Content length:"+ conn.getContentLength());

Log in Java Console :
dataURL:http://c1008180.spe.sony.com/servlet/com.sony.spe.gemgpms.productioservlet?
Connecting ..
Connected.
con:sun.plugin.protocol.jdk12.http.HttpURLConnection:http://c1008180.spe.sony.com/servlet/com.sony.spe.gemgpms.productioservlet
Content length:0

servlet code doPost() -

gemgpmsLog.logMessage("doPost() called.");//I could see this in the log.
ObjectInputStream i = new ObjectInputStream(request.getInputStream());
ProductData lData = (ProductData)i.readObject();//This is where above exception is thrown.
gemgpmsLog.logMessage("Got Product "+lData.getPrimaryTitle());
gemgpmsLog.logMessage("Got ProductID "+lData.getProductID());
gemgpmsLog.logMessage("Got Product Runtime "+lData.getRunTimeMins());
i.close();
//For reading bytes I used BufferedStreamReader.read() which returns -1 after a while.

Reply via email to