ObjectInputStream Question

For reasons too long to go into I have written a client server with SSL sockets that passes both objects of my own creation and vector containing Strings. My problem is detecting on the server end if the object stream contains my Object or the vectors before I write them to the database.
So i would like to be able to either be able to tell the type of object in the stream or get a look at what is in the object and then use an if/else to act depending on which object is in the stream. If I use readObject() it means that the data is already deserialized and so by the time I know what my object is it is too late to make a decision about how to process the data.
Does anyone know a creative use of one of the methods that would give me this info without deserializing the data? Or any suggestions would be very much appreciated
thanks

You can use a BufferedInputStream's mark() feature. Something like this should work:
InputStream is=soc.getInputStream();
BufferedInputStream bis=new BufferedInputStream();
bis.mark(10*1024); // at most 10 Kb before mark gets invalidated
ObjectInputStream ois=new ObjectInputStream(bis);
Object o=ois.readObject();
if(o instanceof Vector)
   bis.reset(); // now a second call to ois.readObject() will return the same object
else
   handle(o);

Similar Messages

  • Java Crash through Trasformation, whats the problem?

    I'm writeing a component, that draws recursivly a hierarchy as a kind of tree (exactly a herring bone diagram).
    I used Java2D and a lot of transformations (rotation and translation) to draw this diagram. In this way I used the TextLayout.getOutline function to draw some texts and use a AffineTransform as argument to position the text. This works very well until I have a lot of objects to draw. Then java(!!) crashes (access violation in jvw.dll). When I comment out the transformation it works well.
    Is anyone out there, who has an idea, how to solve this problem? It's very important.

    Thanks for you quick answer.
    I was just wandering by in the forlorn hope the someone had posted a response to my ObjectInputStream question.
    I create this AffineTransformation objects for all
    objects. And when any object becomes visible the first
    time (and only the first time), I use the translate
    function of the AffineTransform object.If you only ever call translate() once for each drawn object (presumably you hang on to the object returned by translate()) do you need to maintain a reference to the AffineTransform afterwards? You could try setting the AffineTransform reference variable to null after the call to translate(). This should allow the garbage collector to reclaim the memory.

  • Trying to send multiple types in a byte array -- questions?

    Hi,
    I have a question which I would really appreciate any help on.
    I am trying to send a byte array, that contains multiple types using a UDP app. and then receive it on the other end.
    So far I have been able to do this using the following code. Please note that I create a new String, Float or Double object to be able to correctly send and receive. Here is the code:
    //this is on the client side...
    String mymessage ="Here is your stuff from your client" ;
    int nbr = 22; Double nbr2 = new Double(1232.11223);
    Float nbr3 = new Float(8098098.809808);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(mymessage);
    oos.writeInt(nbr);
    oos.writeObject(nbr2);
    oos.writeObject(nbr3);
    oos.close();
    byte[] buffer = baos.toByteArray();
    socket.send(packet);
    //this is on the server side...
    byte [] buffer = new byte [5000];
    String mymessage = null; int nbr = 0; Double nbr2 = null;
    Float nbr3 = null;
    mymessage = (String)ois.readObject();
    nbr = ois.readInt();
    nbr2 = (Double) ois.readObject();
    nbr3 = (Float) ois.readObject();
    My main question here is that I have to create a new Float and Double object to be able to send and receive this byte array correctly. However, I would like to be able to have to only create 1object, stuff it with the String, int, Float and Double, send it and then correctly receive it on the other end.
    So I tried creating another class, and then creating an obj of this class and stuffing it with the 4 types:
    public class O_struct{
    //the indiv. objects to be sent...
    public String mymessage; public int nbr; public Double nbr2;
    public Float nbr3;
    //construct...
    public O_struct(String mymessage_c, int nbr_c, double nbr2_c, float nbr3_c){
    my_message = my_message_c;
    nbr = nbr_c;
    nbr2 = new Double(nbr2_c);
    nbr3 = new Float(nbr3_c);
    Then in main, using this new class:
    in main():
    O_struct some_obj_client = new O_struct("Here is your stuff from your client", 22, 1232.1234, 890980980.798);
    oos.writeObject(some_obj_client);
    oos.close();
    send code....according to UDP
    However on the receiving side, I am not sure how to be able to correctly retrieve the 4 types. Before I was explicitely creating those objects for sending, then I was casting them again on the receiving side to retrieve then and it does work.
    But if I create a O_struct object and cast it as I did before with the indiv objects on the receiving end, I can't get the correct retrievals.
    My code, on the server side:
    O_struct some_obj_server = new O_struct(null, null, null. null);
    some_obj_server = (O_struct)ois.readObject();
    My main goal is to be able to send 4 types in a byte array, but the way I have written this code, I have to create a Float and Double obj to be able to send and receive correctly. I would rather not have to directly create these objects, but instead be able to stuff all 4 types into a byte array and then send it and correctly be able to retrieve all the info on the receiver's side.
    I might be making this more complicated than needed, but this was the only way I could figure out how to do this and any help will be greatly appreciated.
    If there an easier way to do I certainly will appreciate that advise as well.
    Thanks.

    public class O_struct implements Serializable {
    // writing
    ObjectOutputStream oos = ...;
    O_struct struct = ...;
    oos.writeObject(struct);
    // reading
    ObjectInputStream ois = ...;
    O_struct struct = (O_struct)ois.readObject();
    I will be sending 1000s of these byte arrays, and I'm sure having to create a new Double or Float on both ends will hinder this.
    I am worried that having to create new objs every time it is sending a byte array will affect my application.
    That's the wrong way to approach this. You're talking about adding complexity to your code and fuglifying it because you think it might improve performance. But you don't know if it will, or by how much, or even if it needs to be improved.
    Personally, I'd guess that the I/O will have a much bigger affect on performance than object creation (which, contrary to popular belief, is generally quite fast now: http://www-128.ibm.com/developerworks/java/library/j-jtp01274.html)
    If you think object creation is going to be a problem, then before you go and cock up your real code to work around it, create some tests that measure how fast it is one way vs. the other. Then only use the cock-up if the normal, easier to write and maintain way is too slow AND the cock-up is significantly faster.

  • Determine the Size of an Object in ObjectInputStream

    Hi all,
    I have a quick question. I have a class that is being written over a socket using ObjectOutputStream and ObjectInputStream. I want to be able to set the buffer size of the socket to fit only ONE object. Can anybody tell me how to determine the size of that object?
    (Note, the object has a Properties object within it, but for the time being, it can be assumed that properties object will always be the same.)
    - Adam

    Having written it to the outputStream, thought, can
    the size be determined somehow by the inputStream?No, it can't
    This is related to my previous question (on Pushlets
    and Thread Priorities). I didn't read that one.
    I believe that it's possible
    that multiple threads are trying to write to the
    socket at the same time, and I cannot synchorize the
    input stream to get a lock on it. Do you mean the outputstream? Why can't you synchronize the method that writes to the outputstream?
    I thought this
    might be causing the data to not be sent over the
    socket until all the threads have finished. That doesn't sound correct. But you could call the flush method when an object is written.
    I
    figured if I reduced the size of the socket buffer,
    it would only accept a single object, eliminating
    this problem?I don't think so.
    /Kaj

  • A very simple question..Very Urgent

    HI,
    I have a very simple question.I am able to set up the client authentication as well as server authentication. Now do i need to authenticate (both server as well as client auth.) for every request i send to the server on https...i think it should be like that it should authenticate only for the first time and for the next upcoming requests in same session should not require any server or client authentication.. i think as it happens in browsers..
    what is the fact actually??..can somebody put some light...right now in my case it is authenticating for every requests..
    This is what i have done..
    /****constructor part********/
    // and tm are arrays of keymanagers and trustmanagers for client keystore and truststore
    sslContext.init(km, tm, null);
    HttpsURLConnection.setDefaultSSLSocketFactory(ssf);
    HttpsURLConnection.setDefaultHostnameVerifier(new MYHostNameVerifier());
    /****Method to send the request and response*********/
    urlConn = (HttpsURLConnection)url.openConnection();
    urlConn.setDoInput(true);
    urlConn.setDoOutput(true);
    OutputStream os = urlConn.getOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(someobject);
    oos.flush();
    InputStream is1 = urlConn.getInputStream();
    ObjectInputStream ois = new ObjectInputStream(is1);
    SomeObject retObj = null;
    retObj = (SomeObject)ois.readObject();
    ois.close();
    System.out.println("Get String>>>>> "+retObj.getString());
    I am creating the object of this class..and calling the method again and again for sending requests and response..so i think handshake everytime i call the method...what i want is that handshake should happen for the first time and for the next requests no handshake or certificates should be checked or processed..
    is it possible ..how..what i need to do for that..
    please help me in this..
    Akhil Nagpal

    Hi,
    how could I achieve SSL Session Resumption using HttpsURLConnection.
    Thanks.

  • How to read appended objects from file with ObjectInputStream?

    Hi to everyone. I'm new to Java so my question may look really stupid to most of you but I couldn't fined a solution by myself... I wanted to make an application, something like address book that is storing information about different people. So I decided to make a class that will hold the information for each person (for example: nickname, name, e-mail, web address and so on), then using the ObjectOutputStream the information will be save to a file. If I want to add a new record for a new person I'll simply append it to the already existing file. So far so good but soon I discovered that I can not read the appended objects using ObjectInputStream.
    What I mean is that if I create new file and then in one session save several objects to it using ObjectOutputStream they all will be read with no problem by ObjectInputStream. But after that if in a new session I append new objects they won't be read. The ObjectInputStream will read the objects from the first session after that IOException will be generated and the reading will stop just before the appended objects from the second session.
    The following is just a simple test it's not actual code from the program I was talking about. Instead of objects containing different kind of information I'm using only strings here. To use the program use as arguments in the console "w" to create new file followed by the file name and the strings you want save to the file (as objects). Example: "+w TestFile.obj Thats Just A Test+". Then to read it use "r" (for reading), followed by the file name. Example "+r TestFile.obj+". As a result you'll see that all the strings that are saved in the file can be successfully read back. Then do the same: "+w TestFile.obj Thats Second Test+" and then read again "+r TestFile.obj+". What will happen is that the strings only from the first sessions will be read and the ones from the second session will not.
    I am sorry for making this that long but I couldn't explain it more simple. If someone can give me a solution I'll be happy to hear it! ^.^ I'll also be glad if someone propose different approach of the problem! Here is the code:
    import java.io.*;
    class Fio
         public static void main(String[] args)
              try
                   if (args[0].equals("w"))
                        FileOutputStream fos = new FileOutputStream(args[1], true);
                        ObjectOutputStream oos = new ObjectOutputStream(fos);
                        for (int i = 2; i < args.length ; i++)
                             oos.writeObject(args);
                        fos.close();
                   else if (args[0].equals("r"))
                        FileInputStream fis = new FileInputStream(args[1]);
                        ObjectInputStream ois = new ObjectInputStream(fis);
                        for (int i = 0; i < fis.available(); i++)
                             System.out.println((String)ois.readObject());
                        fis.close();
                   else
                        System.out.println("Wrong args!");
              catch (IndexOutOfBoundsException exc)
                   System.out.println("You must use \"w\" or \"r\" followed by the file name as args!");
              catch (IOException exc)
                   System.out.println("I/O exception appeard!");
              catch (ClassNotFoundException exc)
                   System.out.println("Can not find the needed class");

    How to read appended objects from file with ObjectInputStream? The short answer is you can't.
    The long answer is you can if you put some work into it. The general outline would be to create a file with a format that will allow the storage of multiple streams within it. If you use a RandomAccessFile, you can create a header containing the length. If you use streams, you'll have to use a block protocol. The reason for this is that I don't think ObjectInputStream is guaranteed to read the same number of bytes ObjectOutputStream writes to it (e.g., it could skip ending padding or such).
    Next, you'll need to create an object that can return more InputStream objects, one per stream written to the file.
    Not trivial, but that's how you'd do it.

  • Trying to run code from this weeks question of the  week

    i've copied the code from this weeks question of the week "sending an http req from a normal class." when i compile it everything looks fine. i've installed tomcat and it works. so i guess i am confused as to where i put the servlet class file??? and do i need to change a web.xml file?
    any help would be appreciated,
    erik

    for simplicity i just put Hello.class and HelloServlet.class in C:\tomcat\webapps\ROOT\WEB-INF\classes. i still cannot get this to work. here are my source files:
    Hello.java:
    import java.net.*;
    import java.util.*;
    import java.io.*;
    public class Hello {
    public static void main(String args[]) {
    ObjectInputStream is;
    URL url;
    String uri =
    "http://localhost:8080/HelloServlet";
    HashMap hash = new HashMap();
    try {
    //calling the servlet by passing params
    url = new URL(uri + "?&name=MyName&age=25");
    // open input stream and read the hashmap
    // returned by the servlet
    is = new ObjectInputStream(url.openStream());
    hash = (HashMap) is.readObject();
    // print it out
    System.out.println(hash);
    } catch (Exception e) {
    e.printStackTrace(System.err);
    HelloServlet.java:
    import java.util.HashMap;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class HelloServlet extends HttpServlet {
    public void service(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
         // getting the parameters
    String name = request.getParameter("name");
    String age = request.getParameter("age");
         //putting them in a hashmap
    HashMap hm = new HashMap();
    hm.put("name", name);
    hm.put("age", age);
         //returning them
    try {
    ObjectOutputStream p = new                                    
         ObjectOutputStream(response.getOutputStream());
    p.writeObject(hm);
    p.flush();
    p.close();
    }catch (Exception e) {
    e.printStackTrace();
    can anyone see a problem. this code is supposed to be run from the command line. and i am doing that.
    thanks for the help,
    erik

  • Tuning the performance of ObjectInputStream.readObject()

    I'm using JWorks, which roughly corresponds to jdk1.1.8, on my client (VxWorks) and jdk1.4.2 on the server side (Windows, Tomcat).
    I'm serializing a big vector and compressing it using GZipOutputStream on the server side and doing the reverse on the client side to recreate the objects.
    Server side:
    Vector v = new Vector(50000);//also filled with 50k different MyObject instances
    ObjectOutputStream oos = new ObjectOutputStream(new GZipOutputStream(socket.getOutputStream()));
    oos.writeObject(v);Client side:
    ObjectInputStream ois = new ObjectInputStream(new GZipInputStream(socket.getInputStream()));
    Vector v = (Vector)ois.readObject();ObjectInputStream.readObject() at the client takes a long time (50secs) to complete, which is understandable as the client is a PIII-700MHz and the uncompressed vector is around 10MB. Now the problem is that because my Java thread runs with real time priority (which is the default on Vxworks) and deprive other threads, including non-Java ones, for this whole 50 sec period. This causes a watchdog thread to reset the system. I guess most of this delay is in GZipInputStream, as part of the un-gzipping process.
    My question is, is there a way to make ObjectInputStream.readObject() or any of the other connected streams (gzip and socket) yield the CPU to other threads once in a while? Or is there any other way to deal with the situation?
    Is the following a good solution?
    class MyGZipInputStream extends GZipInputStream {
        public int count = 0;
        public int read(byte b[], int off, int len) throws IOException {
             if(++count %10 == 0) // to avoid too many yields
                  Thread.yield();
              return super.read(b, off,len);
    }Thanks
    --kannan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I'd be inclined to put the yielding input stream as close to the incoming data as possible - thus avoiding any risk that time taken to read in data and buffer it will cause the watchdog to trip.I could do that. But as I'm doing Thread.yield only once every x times, would it help much?
    Also, as I've now found out, Thread.yield() wouldn't give other low priority tasks a chance to run. So I've switched to Thread.sleep(100) now, even though it could mean a performance hit.
    Another relaed question - MyGzipStream.read(byte[], int, int) is called about 3million times during the readObject() of my 10MB vector. This would mean that ObjectInputStream is using very small buffer size. Is there a way to increase it, other than overriding read() to call super.read() with a bigger buffer and then doing a System.arrayCopy()?
    Thanks
    --kannan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Saving files and future Java Virtual Machine updates questions

    So I've made A program that keeps a list of Ingredients and Recipes for my dads small business. This program is currently on 3 computers my dads, the secretaries, and mine. I made it so it saved and loaded from a shared folder in the network where all the computers has access. The secretary and my dads computer saved and loaded the program fine with changes from one to the other, but mine wouldn't. If I save what information I put on my computer the other computers could no longer load the save file. If i saved something on the secretary or dads computer then my computer would not be able to load the file.
    well i solved this problem by re downloading Java virtual machine on my computer.
    this brings me to my question:
    Will future virtual machine updates make it so the program can't read old .dat files (I've been using ObjectInputStreams and ObjectOutputStreams to save and load)
    Sorry for the long story before the question I just wanted to state how I came to the question.

    Yes, absolutely. That is one of the problems with using serialization to save data. Fortunately the serialization tutorial mentions it and explains some strategies for minimizing the problem. So have a look at that tutorial.

  • EJB Question Please help me

    Hi
    I am preparing for certification exam. I don't know the correct answer of these question. Please help me.
    Regards
    Arghya Banerjee
    ========================================================================
    1. While testing a BMP Entity Bean, a developer discovers that a transaction rollback does not cause a rollback of the changes made to the bean as it should. Which of the following should the developer suspect?
    A.     The ejbPassivate() method has a bug.
    B.     The ejbStore() method has a bug.
    C.     The ejbCreate() method has a bug.
    D.     The datastore does not support JTA.
    E.     The transaction does not implement javax.transaction.UserTransaction.
    Select 2 answers.
    2.     A Servlet must perform 3 operations that are independent of one another. They are time consuming with each operation consuming about 10 msec of CPU. The Servlet's response depends on the completion of all three operations. The developer decides to perform each operation on a separate worker thread to run them concurrently. Which of the following describe important parts of this implementation?
    A.     The Servlet should implement MultiThreadModel
    B.     The Servlet should implement SingleThreadModel
    C.     Access to the HttpSession must be synchronized.
    D.     The worker threads must not write to the ServletOutputStream.
    E.     The worker threads must not read from the ServletInputStream.
    Select the best answer.
    3. A client invokes the create() method on an CMP entity bean. Which of the following is a correct sequence in which the operations mentioned below are performed?
    a.     Container creates an EJBObject.
    b.     EJB home object invokes ejbCreate() on Bean instance
    c.     Bean instance is associated with EJBObject.
    d.     Container creates new bean instance.
    e.     Container calls setEntityContext() on bean instance.
    f.     Container creates the bean representation in a database.
    g.     ejbPostCreate() method is invoked on bean instance.
    A.     b -> f -> a -> c -> g
    B.     b -> a -> f -> c -> e -> g
    C.     a -> d -> c -> b -> e -> g -> f
    D.     a -> d -> c -> b -> f -> g -> e
    E.     a -> c -> e -> b -> f -> g
    Select the best answer.
    4.     A Web site is getting a lot of 'hits' and the amount of session data managed by the server is becoming too large for it to handle. Which of the following are appropriate ways to solve the problem?
    A.     Expand the capacity of the server.
    B.     Add additional servers to share the load.
    C.     Store the session data in a Cookie.
    D.     Store all session data in hidden fields on the web pages that are served.
    5. A developer wishes to make a server function available to an applet via a Servlet. The applet passes the Servlet a serialized object as an argument. How should the developer implement the Servlet?
    A.     Sub-class HttpServlet and create an ObjectInputStream from the
    ServletInputStream in the doGet() method.
    B.     Sub-class HttpServlet and create an ObjectInputStream from the
    ServletInputStream in the service() method.
    C.     Sub-class GenericServlet and create an ObjectInputStream from the
    ServletInputStream in the doGet() method.
    D.     Sub-class GenericServlet and create an ObjectInputStream from the ServletInputStream in the service() method.
    Select the best answer.
    6. While testing a CMP Entity bean, a developer discovers that a change to one of the bean's properties is not being reflected in the database that contains the bean data. What are possible causes?
    A.     The ejbStore() method has a bug.
    B.     The ejbCreate() method has a bug.
    C.     The setter for the property has a bug.
    D.     The mapping of container managed fields to database fields has a bug.
    E.     The deployment descriptor has a bug.
    F.     The ejbLoad() method has a bug.
    Select 4 answers.

    Hi Arghya ,
    From where you have taken these quetions , are they from the book.
    1. While testing a BMP Entity Bean, a developer
    discovers that a transaction rollback does not cause a
    rollback of the changes made to the bean as it should.
    Which of the following should the developer suspect?
    A.     The ejbPassivate() method has a bug.
    B.     The ejbStore() method has a bug.
    C.     The ejbCreate() method has a bug.
    D.     The datastore does not support JTA.
    E.     The transaction does not implement
    javax.transaction.UserTransaction.
    Select 2 answers.
    D,B If the Transaction is rolled back there are the possibility that either the datasource doesnot support it or the bean is updating the inconsistent data, so mostly problem in ejbStore() where there is a database update.
    2.     A Servlet must perform 3 operations that are
    independent of one another. They are time consuming
    with each operation consuming about 10 msec of CPU.
    The Servlet's response depends on the completion of
    all three operations. The developer decides to perform
    each operation on a separate worker thread to run them
    concurrently. Which of the following describe
    important parts of this implementation?
    A.     The Servlet should implement MultiThreadModel
    B.     The Servlet should implement SingleThreadModel
    C.     Access to the HttpSession must be synchronized.
    D.     The worker threads must not write to the
    ServletOutputStream.
    E.     The worker threads must not read from the
    ServletInputStream.
    Select the best answer.
    Now here what is the worker Thread should not write to output stream as if it does then there will be wrong formatting of the data, we are bothered about to improve the throughput so we have spawned three worker thread.Also there is no dependency so D is proper one
    3. A client invokes the create() method on an CMP
    entity bean. Which of the following is a correct
    sequence in which the operations mentioned below are
    performed?
    a.     Container creates an EJBObject.
    b.     EJB home object invokes ejbCreate() on Bean
    instance
    c.     Bean instance is associated with EJBObject.
    d.     Container creates new bean instance.
    e.     Container calls setEntityContext() on bean
    instance.
    f.     Container creates the bean representation in a
    database.
    g.     ejbPostCreate() method is invoked on bean
    instance.
    A.     b -> f -> a -> c -> g
    B.     b -> a -> f -> c -> e -> g
    C.     a -> d -> c -> b -> e -> g -> f
    D.     a -> d -> c -> b -> f -> g -> e
    E.     a -> c -> e -> b -> f -> g
    Select the best answer.
    Client invokes the create method on the home which inturn prepares the EJBObject and attaches the bean instance to the EJBObject and returned the reference to the client.So the option E.
    >
    4.     A Web site is getting a lot of 'hits' and the
    amount of session data managed by the server is
    becoming too large for it to handle. Which of the
    following are appropriate ways to solve the problem?
    A.     Expand the capacity of the server.
    B.     Add additional servers to share the load.
    C.     Store the session data in a Cookie.
    D.     Store all session data in hidden fields on the web
    pages that are served.
    You have to use the Load balancing tech , go for distributed technology B , the processing speed is now the criteria so you distribute the work.
    5. A developer wishes to make a server function
    available to an applet via a Servlet. The applet
    passes the Servlet a serialized object as an argument.
    How should the developer implement the Servlet?
    A.     Sub-class HttpServlet and create an
    ObjectInputStream from the
    ServletInputStream in the doGet() method.
    B.     Sub-class HttpServlet and create an
    ObjectInputStream from the
    ServletInputStream in the service() method.
    C.     Sub-class GenericServlet and create an
    ObjectInputStream from the
    ServletInputStream in the doGet() method.
    D.     Sub-class GenericServlet and create an
    ObjectInputStream from the ServletInputStream in the
    service() method.
    Select the best answer.
    I have to refer some docs for this
    6. While testing a CMP Entity bean, a developer
    discovers that a change to one of the bean's
    properties is not being reflected in the database that
    contains the bean data. What are possible causes?
    A.     The ejbStore() method has a bug.
    B.     The ejbCreate() method has a bug.
    C.     The setter for the property has a bug.
    D.     The mapping of container managed fields to database
    fields has a bug.
    E.     The deployment descriptor has a bug.
    F.     The ejbLoad() method has a bug.
    Select 4 answers.
    If there is the problem in the deployment descriptor then there ejb will not deploy at all .As the problem comes in updating I can make so no problem in the ejbCreate() also , but then many other consideration has to be taken .So I have my answer as
    A,C,D,F
    That is all I can say.
    Regard
    Vicky

  • Strange StreamCorruptedException while using ObjectInputStream

    I have a strange problem:
    I am producing a java client which communication behaviour should be identical to a java applet (running in a web browser). I have the source code for the applet and I experience no problems running the applet.
    However when writing a stand alone communication class the code works fine for smaller Objects that are serialised but larger objects will not work!
    I have tried several objects in order to test the bevaiour and there is nothing in my code that would explain why certain objects (large ones) should fail. Due to licensing I am unfortunately unable to provide you with the source code (sorry)
    My client uses raw socket communication (basically objectinputstream connected to the inputstream delivered by the socket (all web reply removed so that the OIS is opened where it should be)) compared to the inputstream retrieved form an URLConnection in the applet.
    In both cases the communication is over HTTPS.
    So my question is:
    Is there a fundamental difference (on the byte streams) received
    1) From an URLConnection provided by the browser envirionment to the applet
    2) Directly from a socket class.
    How else would you explain the difference?
    Many thanks
    /Chris

    Here is my guess. The browser VM has some subtle interractions with the browser. An SSL connection usually starts with the server sending a certificate and the client 'accepting it'. The acceptance or rejection is based on the root certificates configured in the client. The browser has such a 'database' of root certificates. I bet the browser VM is using the same database as the browser.
    When you run the application stand-alone, the database is somewhere in the JRE. Somehow the root certificate of your server certificate is not there.

  • Drag and Drop questions and Serialization in the 1Z0-852 Upgrade exam?

    Hi,
    Does anyone know if the drag and drop items and serialization have been removed from the 1Z0-852 Java SE 6 Programmer Certified Professional UPGRADE exam?
    I know that they have been removed from the 1Z0-851, but not sure about the upgrade exam.
    Thanks in advance,
    Alvaro

    Alvaro wrote:
    Hi,
    Does anyone know if the drag and drop items and serialization have been removed from the 1Z0-852 Java SE 6 Programmer Certified Professional UPGRADE exam?
    I know that they have been removed from the 1Z0-851, but not sure about the upgrade exam.
    Thanks in advance,
    Alvaro(1) Drag and Drop
    .... this question format will have been removed:
    Ref: http://blogs.oracle.com/certification/entry/0596
    (2) Serialization:
    It is best to compare the topics from your notes to the current topics, however according to my reading of the current topics it is in scope at least to some extent:
    http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=41&p_exam_id=1Z0_852 (Section 3 API Contents):
    Develop code that serializes and/or de-serializes objects using the following APIs from java.io: DataInputStream, DataOutputStream, FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream and Serializable.

  • Stack overflow resolution and question

    on Oct 8th, I posted the stack overflow at the end of this message. I
    figured out the problem, but would like some insight into why it manifested
    itself as a stack overflow. Why isn't it a heap overflow? I care which
    overflows because a problem could still exist.
    PROBLEM
    Our server transmits an event object to our client. The event object has
    references to 2 member objects which describe the context of the event.
    About 200 of each type of member object is created. They are kept in a
    HashMap so we can reuse them.
    However, in one case, a new member object is created every time an event is
    transmitted. That's the bug - about a thousand events a second are created
    so one thousand of each member object is created, then transmitted. When we
    changed the member object creation to a member HashMap lookup, the stack
    trace stopped.
    PROFILING
    To isolate the problem, we profiled the client with OptimizeIt. This
    showed about 150,000 member objects and about 148,000
    java.io.ObjectInputStream$HandleTable$HandleList instances. In some runs,
    Garbage collection reduced the number to about 60,000. In other runs,
    Garbage Collection did not run before the stack error occurred.
    If we create lots of member objects in the heap, then the heap should
    overflow. Why does the stack overflow?
    ERROR MESSAGE
    The declaration is
    Socket sock = new Socket( hostname, port );
    ObjectInputStream is = new ObjectInputStream( sock.getInputStream() );
    ObjectOutputStream os = new ObjectOutputStream( sock.getOutputStream() );
    java.lang.StackOverflowError
    at COM.jrockit.io.NativeIOInputStream.read([BII)I(Optimized Method)
    at java.io.ObjectInputStream$PeekInputStream.read([BII)I(Optimized Metho
    d)
    at java.io.ObjectInputStream$BlockDataInputStream.read([BIIZ)I(Unknown S
    ource)
    at java.io.ObjectInputStream$BlockDataInputStream.readFully([BIIZ)V(Unkn
    own Source)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    Jeff
    Jeff
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Well, the HandleList entries mark a dependency from a parent object to a
    child (i.e referer and referee), and my guess is that you at some point
    simply manage to serialize a very long object chain:
    Obj1 -[ ref to]-> Obj2 -[ref to]-> Obj3 and so on.
    This will cause a recursive deserialization (actually, it causes a
    recursive serialization also, so sender should SOE as well). The amount
    of memeory used is probably high, but not OOM high. Note, that for this
    to happen, all objects sent must be unique, which you state that they
    are. Question is how you've managed to create an object chain like this.
    Another explanation might be that there is actually a bug somewhere in
    the sender that causes a circular reference between two (or more)
    objects to be sent not as reference handles, but unique objects. I
    cannot see what would cause this though. I assume that you don't have
    concurrency issues (i.e only one thread uses the ObjectOutput/Input
    streams at one time)?
    Do you have an exact count of the transmitted object? It might help me
    figure out exactly what happend.
    /C
    Jeff wrote:
    on Oct 8th, I posted the stack overflow at the end of this message. I
    figured out the problem, but would like some insight into why it manifested
    itself as a stack overflow. Why isn't it a heap overflow? I care which
    overflows because a problem could still exist.
    PROBLEM
    Our server transmits an event object to our client. The event object has
    references to 2 member objects which describe the context of the event.
    About 200 of each type of member object is created. They are kept in a
    HashMap so we can reuse them.
    However, in one case, a new member object is created every time an event is
    transmitted. That's the bug - about a thousand events a second are created
    so one thousand of each member object is created, then transmitted. When we
    changed the member object creation to a member HashMap lookup, the stack
    trace stopped.
    PROFILING
    To isolate the problem, we profiled the client with OptimizeIt. This
    showed about 150,000 member objects and about 148,000
    java.io.ObjectInputStream$HandleTable$HandleList instances. In some runs,
    Garbage collection reduced the number to about 60,000. In other runs,
    Garbage Collection did not run before the stack error occurred.
    If we create lots of member objects in the heap, then the heap should
    overflow. Why does the stack overflow?
    ERROR MESSAGE
    The declaration is
    Socket sock = new Socket( hostname, port );
    ObjectInputStream is = new ObjectInputStream( sock.getInputStream() );
    ObjectOutputStream os = new ObjectOutputStream( sock.getOutputStream() );
    java.lang.StackOverflowError
    at COM.jrockit.io.NativeIOInputStream.read([BII)I(Optimized Method)
    at java.io.ObjectInputStream$PeekInputStream.read([BII)I(Optimized Metho
    d)
    at java.io.ObjectInputStream$BlockDataInputStream.read([BIIZ)I(Unknown S
    ource)
    at java.io.ObjectInputStream$BlockDataInputStream.readFully([BIIZ)V(Unkn
    own Source)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)

  • Java Socket Question

    Bonjour all,
    I have a bit of a weird question about Socket output and input streams, when I use the following code everything works fine.
    Socket soc = new Socket("123.456.789.1", 1234);
    +//     Send data request+
    +DataOutputStream dos = new DataOutputStream(soc.getOutputStream());
    dos.writeInt(INT);
    dos.flush();
    +//     Wait for reply+
    ObjectInputStream ois = new ObjectInputStream(soc.getInputStream());
    ArrayList<String> files = (ArrayList<String>) ois.readObject();
    How ever if I declare my Output and Input Stream readers together, my program justs hangs.
    Socket soc = new Socket("123.456.789.1", 1234);
    +//     Define streams+
    DataOutputStream dos = new DataOutputStream(soc.getOutputStream());
    ObjectInputStream ois = new ObjectInputStream(soc.getInputStream());
    +//     Send data request+
    dos.writeInt(INT);
    dos.flush();
    +//     Wait for reply+
    ArrayList<String> files = (ArrayList<String>) ois.readObject();
    Anyone got any ideas why this is??
    Edited by: 836869 on 15-Feb-2011 04:02

    You have to flush your ObjectOputStream first, it is worth noting that you are not, 1) using an ObjectOutputStream, 2) flushing it before opening the ObjectInputStream.
    Try this.
    ObjectOutputStream oos = new ObjectOutputStream(soc.getOutputStream());
    oos.flush();
    ObjectInputStream ois = new ObjectInputStream(soc.getInputStream());If you want to swap an integer as part of the header, you can do the following.
    ObjectOutputStream oos = new ObjectOutputStream(soc.getOutputStream());
    oos.writeObject(INT);
    oos.flush();
    ObjectInputStream ois = new ObjectInputStream(soc.getInputStream());
    Integer intValue = (integer) ois.readObject();

  • Some question on ETL

    Hi,
    I have created an ETL script as below
    CREATE TABLE ext_tbl_cust
    ID NVARCHAR2(50),
    NUMX NVARCHAR2(20),
    CUST_TYP_CD NVARCHAR2(20),
    CUST_CAT_CD NVARCHAR2(20),
    CUST_STS_CD NVARCHAR2(20)
    ORGANIZATION EXTERNAL
    TYPE ORACLE_LOADER
    DEFAULT DIRECTORY dataFile_dir
    ACCESS PARAMETERS
    RECORDS DELIMITED BY NEWLINE
    BADFILE badFile_dir:'badFile.bad'
    LOGFILE logFile_dir:'logFile.log'
    SKIP 1
    FIELDS
    ID position (1:10) integer external,
    NUMX position (11:30) integer external,
    CUST_TYP_CD position (31:40) integer external,
    CUST_CAT_CD position (41:50) integer external,
    CUST_STS_CD position (51:70) char
    LOCATION('TESTFIXWIDTH.TXT')
    PARALLEL 2
    REJECT LIMIT UNLIMITED;
    My questions is for the LOCATION clause, how could I specify it with dynamic value ? Could do something where the LOCATION clause to read all the files in the specify directory ?
    Please help if you know ? I have try few method and it's doesn't work.
    Thanks in advance.
    p/s: I not using the Tools to build the script.

    try this:
    public class test{
         Socket socket;
         ObjectOutputStream oos;
         ObjectInputStream ooi;
         public test(){
              socket = new Socket("123.123.123.123", 1111);
              oos = new ObjectOutputStream(socket.getOutputStream());
              ooi = new ObjectInputStream(socket.getInputStream());
         public void write(Object object){
              oos.writeObject(object);
         public Object read(){
              Object object = ois.readObject();
              return object;
         public void close(){
              socket.close();
    }

Maybe you are looking for

  • T430 cannot install Windows 8.1

    I cannot install Windows 8.1. I have a T430. I go into the app store, start installing 8.1, it downloads, starts installing, and fails just after that point -- at 54% -- with the error message 0x80070002. That apparently means "File not found", but t

  • Update for Microsoft Visual C++ 2012 Update on Windows 7

    I received the Update for Microsoft Visual C++ 2012 Update 4 Redistributable Package (KB3032622).  The installation failed. Here are the details Installation date: ‎2/‎10/‎2015 8:35 PM Installation status: Failed Error details: Code FF Update type: I

  • Not able to connect through Application user name in Discoverer Admin

    Hi, I created an EUL with all privileges it needed. I created a business area from that EUL and shared it to Application User name through giving access privileges (from Security and Privileges). When I am trying to login through the Application User

  • Use daq across multiple Labview applicatio​ns

    Is it possible to have daq handoff data to multiple Labview applications running at the same time?  Each application is specific to a certain test setup, but each test setup has its channels run into a couple of scxi cards in one computer/daq card. 

  • My passcode lock is missing under settings-general tab

    Under my settings tab, then general tab I do not have a passcode Lock button? I have installed the 5.1.1 update and it's still not showing up....what do I do....any help is greatly appreciated.