How to use local interface in my easy code ?

hi everybody
I work on an ejb project. My code is like that to test remote interface (and it works) :
public class TestStudent {
   Properties properties;
   public TestStudent() {
      properties = new Properties();
      properties.put("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      properties.put("java.naming.factory.url.pkgs",
      "org.jboss.naming:org.jnp.interfaces");
      properties.put("java.naming.provider.url", "jnp://localhost:1099");
      properties.put("jnp.disableDiscovery", "true");
   public static void main(String[] args) {
      TestStudent beanStudent = new TestStudent();
      beanStudent.createBean();
   public void createBean() throws EJBException {
      try {
         InitialContext context = new InitialContext(properties);
         Object object = context.lookup(StudentHome.JNDI_NAME);
         StudentHome studentHome = (StudentHome) PortableRemoteObject.narrow(object,StudentHome.class);
         Student student = studentHome.create();
         student.setName("pirlouit");
         System.out.println(student.getId());
         System.out.println(student.getName());
      } catch (NamingException e) {
         throw new EJBException(e);
      } catch (RemoteException e) {
         throw new EJBException(e);
      } catch (CreateException e) {
         throw new EJBException(e);
}Then I do quite the same thing to test local interface like in the following code but it doen't work :
public class TestStudent {
   Properties properties;
   public TestStudent() {
      properties = new Properties();
      properties.put("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      properties.put("java.naming.factory.url.pkgs",
      "org.jboss.naming:org.jnp.interfaces");
      properties.put("java.naming.provider.url", "jnp://localhost:1099");
      properties.put("jnp.disableDiscovery", "true");
   public static void main(String[] args) {
      TestStudent beanStudent = new TestStudent();
      beanStudent.createBean();
   public void createBean() throws EJBException {
      try {
         InitialContext context = new InitialContext(properties);
         Object object = context.lookup(StudentLocalHome.JNDI_NAME);
         StudentLocalHome studentLocalHome = (StudentLocalHome)object;
         System.out.println("studentLocalHome is null ? "+studentHome.equals(null));
         StudentLocal student = studentLocalHome.create();
         student.setName("pirlouit");
         System.out.println(student.getId());
         System.out.println(student.getName());
      } catch (NamingException e) {
         throw new EJBException(e);
      } /*catch (RemoteException e) {
         throw new EJBException(e);
      }*/ catch (CreateException e) {
         throw new EJBException(e);
}The print of "student local home is null ?" give me 'true' which is not the answer I want ... so here is the problem. How can I get my entity bean using local interface ?
For the moment 've got the exception (which appears on instruction "StudentLocal student = studentLocalHome.create();") :
Exception in thread "main" java.lang.NullPointerException
     at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:118)
     at $Proxy0.create(Unknown Source)Please help !! Thank you very much !

Write a JSP to test Local Interface. You cannot call Local Interface from a remote JVM.
Jay
http://www.javarss.com - Java News from around the world.
Visit JavaRSS.com and add above signature to your messages. Thanks!

Similar Messages

  • ClassCastException by using Local Interface of EJB in other, but local EAR

    Hi,
    I get a ClassCastException if I try to cast the EJSWrapper-Class returned from local EJB Lookup to the interface it implements.
    The environment I use is WSADIE 5.1.1 with integrated Testenvironment.
    I have defined two EARs. One with a Web-Application and one wich contains the EJB to call from the WebApp. Both run in the same appserver instance wich means both run in the same JVM and i should be able to use Local Interface of the EJB.
    The EJB should use Libraries from the Server Environment while the WebApp uses newer Libs than the Server Environment offers(eg axis-rpc,wsdl4j,saaj). The Classloader-Policy of the EAR with the WebApp is set to PARENT_LAST while the Classloader-Policy of the EAR with the EJB is set to PARENT_FIRST.
    I do a Lookup by using an EJB-Local-Reference. The returned object is an EJSLocalStatelessHome-Object, wich implements my LocalEJBInterface. But if i try to cast to Object to this interface a ClassCastException occurs.
    The Classes of the EJB are packaged as follows:
    EJBName.jar contains the EJB-Impl class, the Serverside Implementations for RMI/IIOP interaction an EJSWrapper classes. This jar is packaged with the EJB-EAR.
    EJBClient.jar contains the Local- and Remote-Interface classes and the Stub-classes for EJBHome and EJB-Implementation. This jar is packaged wich both EARs, because of the interfaces, wich are needed in both projects.
    The Classloader of the EAR with the WebApp has no access the jar with the EJB-Impl, the generated Ties- and EJSWrapperclasses because it is located in only the EJB-EAR. But the interface-class is contained in the WebApp-EAR as described above.
    The exact Exception is as follows:
    java.lang.ClassCastException: com/ibm/wsrf/EJSLocalStatelessBPEAdapterHome_c2546ef5 incompatible with com/ibm/wsrf/BPEAdapterLocalHome
    java.lang.Throwable.<init>(Throwable.java)
    java.lang.Throwable.<init>(Throwable.java)
    java.lang.ClassCastException.<init>(ClassCastException.java:53)
    org.tempuri.ResourceDiscoveryService.DiscoverySoapHttpBindingImpl.getResourceEPR(DiscoverySoapHttpBindingImpl.java)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
    ... The EJSLocalStatelessBPEAdapterHome_c2546ef5 implements the BPEAdapterLocalHome interface.
    Please, can anyone give me a hint how to solve this problem?
    Thanks in advance, Michael

    Problem solved!
    The different EAR contained each an own copy of the jar with the local and remote interfaces of the EJB. The Problem is caused by the separate classloaders of the EARs in an application server. Each EAR Classloader loads his own version of the interface classes. Is the same class loaded by different classloaders, the JVM handles this classes as different classes. An example if you create an instance of a class in one classloader and try to reference the created instance by the same class from another classloader, the association will fail, because of different classloaders in the same JVM.
    The solution in an application server where you have deployed two projects and want to use local interfaces is, store the interfaces(and only the interfaces) in an directory, where it is found by the parent classloader of the EAR classloaders. Remove the Jar with the interface from the EARs. The EAR Classloaders will then search in the their parent classloader for the interfaces. The interfaces will be loaded by the parent classloader and will recognized as compatible by the JVM.
    Greetings, hope this helps help others!
    Michael

  • Using local interfaces for EJB (session bean)

    Hi,
    I�ve a question regarding when to use the Local interfaces(EJBLocal and EJBLocalHome) of a enterprise bean. I understand that calls to enterprise bean can be made locally if the client which is invoking is in the same JVM as that of EJB. I�ve written a web client (servlet) which is packaged in a EAR and this servlet is trying to invoke a session bean which is in a �different� EAR using local interfaces. Both the EARs have been deployed in a single server (websphere 6.0 server). It didn�t work for me this way�..If I package the servlet in the same EAR of session bean then it works fine.
    So is this to say that both EARs are not running on the same JVM? Or should it work even if the client and the session bean are in different EARs but in same server?
    Can anyone explain me the fundamentals behind this.
    Thanks in advance

    Local access is only portable within the same .ear. For example, the Java EE SDK and SUN's
    application servers have never supported local EJB access from a web/EJB component in a different
    .ear. One issue is that local access requires that both the caller and target EJB have the same
    classloader. By definition, different Java EE applications have distinct classloaders. In addition,
    in Java EE 5 persistence context propagation does not span applications, so it wouldn't work in the
    local case.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to use ITextmodel interface in VC++

    hai,
    i want to know how to use ITextModel interface in VC++, that is how to give the story to ITextModel interface, if any one knows please tell him ASAP
    regards,
    ram

    Hi,
    I am not sure what you mean by "give the story to ITextModel", but if what you're looking is to insert some text into a text model, check out SnpManipulateTextModel::InsertText in the SDK, it does exactly that.
    Thanks!
    lee

  • How to use temporary interface in another interface as derived table in 10g

    Hi ,
    Can somebody please tell me how to use temporary interface in another interface as derived table in 10g.
    I have an option in odi 11g to this task.But i am working on odi 10g for my project.So that please help me to do this task.
    I can able to create temporary interface in 10g ,but i dont know how to use that temporary interface in another inerface as derived table.
    Thanks in Advance
    Thanks,
    Srikanth A

    A temp interface CANNOT be used as a derived table in ODI 10g.
    All you can do is to drag and drop the temp interface as the source in the mapping.
    PS. Please remember to assign correct/helpful points to the people who help you in the forum.

  • How to use IKinectPressingUpdatedEventArgs Interface??

    I don't Know how to use IKinectPressingUpdatedEventArgs Interface(c++)
    I need to delta data
    how to get data??

    What specifically are you trying to do? Depending on the scenario, this might not be something you need. Are you using Win32 or store based apis? What is your UI framework? Have you created a thread and waiting for the interaction events to fire?
    Carmine Sirignano - MSFT

  • CMP Entity beans using local interfaces

    Why CMP entity beans with CMR relation ship using local interfaces only?
    Why we should not use remote interface to get the CMR field relationship?
    Pls give me the solutions

    "Local interfaces provide the foundation for container-managed relationships among entity beans and session beans. The bean uses the local interface to maintain its references to other beans. For example, an entity bean uses its local interfaces to maintain relationships to other entity beans. Using local interfaces, beans can also expose their state and use pass-by-reference to pass their state between related bean instances. "
    http://java.sun.com/developer/technicalArticles/ebeans/EJB20CMP/

  • How to use an if statement in javascript code

    Hello,
    I have a batch processing script to search for text "employee signature" on each page in a multiple page file and to then list in the console any pages that do not have the "Employee Signature" text included.
    The script is not yet functional as an if statement needs to be included.
    Can anyone please advise how to use an if statement in javascript code?
    var numpages = this.numPages;
    for (var i=0; i < numpages; i++)
    search.query("Employee Signature", "ActiveDoc");
    console.println('Pages that do not include an employee signature: ' + this.pageNum +' ');
    Any assistance will be most appreciated.

    Thank you very much for your assistance try.
    I have modified the code as suggested and the page numbers are now listing correctly, thank you, but....................,
    The console  lists every page as having an "employee signature" when there are pages in the document that do not have an employee signature.
    The code (revised as follows) is not processing the "getPageNthWord part of the statement" in the console report?
    Can you please advise where the code needs reworking?
    var ckWords; // word pair to test
    var bFound = false; // logical status of found words
    // loop through pages
    for (var i = 0; i < this.numPages; i++ ) {
       bFound = false; // set found flag to false
       numWords = this.getPageNumWords(i); // number of words on page
       // loop through the words on page
       for (var j = 0; j < numWords; j++) {
          // get word pair to test
          ckWords = this.getPageNthWord(i, j) + ' ' + this.getPageNthWord(i, j + 1); // test words
          // check to see if word pair is 'Employee' string is present
          if ( ckWord == "Employee") {
             bFound = true; // indicate found logical value
             console.println('Pages that includes an employee signature: ' + (i + 1) +' ');
             break; // no need to further test for this page
          } // end Employee Signature
       } // end word loop
       // test to see if words not found
       if(bFound == false) {
             console.println('Pages that do include an employee signature: ' + (i + 1) +' ');
        } // end not found on page  
    } // end page loop
    Thank you

  • No performance gain when using local interfaces

    Hello,
    I'm doing some tests to compare performances between remote ejb interfaces and local ejb interfaces.
    I have two stateless session beans EJB1 and EJB2, EJB1 calls a method on EJB2, this method receives one object as the only parameter and returns it immediately. The parameter is a big object (~700ko). My test consists simply of making 1000 calls from EJB1 to EJB2, one time with remote interfaces, one time with local interface. For both tests, the EJBs run in the same container, same VM.
    The results show absolutely no differences between the remote and the local interface !
    As I found these results a bit surprising, I changed the serialization method of my parameter object this way:
    private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    System.out.println("writeObject(MyBigObject)");
    out.defaultWriteObject();
    just to check if my object is serialized when using remote interface. And the response is no.
    So question is: is there an "undocumented optimization" of the stub/skel generated by weblogic which make local calls when calling a remote method inside the same VM ?
    Some precisions:
    - I'am using weblogic 8.1sp2
    - When calling remotely my EJB2 from an external batch (running in a separate VM), I see the message "writeObject(MyBigObject)" so the serialization is done in this case.

    <Fr?d?ric Chopard> wrote in message news:[email protected]..
    So question is: is there an "undocumented optimization" of the stub/skel generated by weblogic which make local calls when callinga remote method inside the same VM ?
    >
    Some precisions:
    - I'am using weblogic 8.1sp2
    - When calling remotely my EJB2 from an external batch (running in a separate VM), I see the message "writeObject(MyBigObject)" sothe serialization is done in this case.
    WebLogic 5.x, 6.x and 7.x do call by reference for co-located EJBs by default. 8.1 has this behavior turned off by default. You may
    experience call-by-reference optimization in 8.1 only if it has been turned on explicitly in the deployment descriptor.
    Hope this helps.
    Regards,
    Slava Imeshev

  • How to create object for a interface (or) how to use ITextModel Interface

    Hi,
    I am new to vc++ and indesign, i am using windows xp as OS and Indesign CS3 as version, now i want to know how to create an object for the ITextModel Interface (or) how to use the ITextModel interface, for getting the selected text and to manipulate the content, for this i tried myself to the best for more than a week,
    but i not get any solution or any idea to do it, so i post this scrap, if any one knows kindly help me immediately, if u want any more details kindly reply me i am ready to give..
    Regards,
    ram

    Hi, Ram,
    as Jongware already has explained in a previous thread, this is the scripting forum, the SDK forum is next door.
    Besides, your question has already been answered over there in SDK forum - with a reference to an existing example, including documented source. There is also plenty more documentation (780 pages alone in the programming guide) and other working examples.
    The brief response was a perfect match to the vague, general scope of the question. If you want more details, be more specific yourself. Do not just touch such major topics as selection, text, object architecture in one sentence to expect a silver bullet. Instead, stick to one detail, find and read the relevant examples and documentation (did I mention the programming guide?) yourself e.g. using keyword search. Quote your code where you're stuck.
    Being new to both VC++ and InDesign is an explanation but no excuse. IMO, same goes for "using windows xp as OS". All together are bad starting conditions if you intend to write a plugin. Even a seasoned C++ programmer with some years of experience in publishing quirks will easily require months, so don't become impatient after just a week.
    If you need quick results and have a programming background such as a recent Java101, reconsider scripting (this forum). It can bring you amazingly far and you'll learn InDesign through a simplified object model. Same principles apply - there is plenty documentation and a good choice of examples.
    Regards,
    Dirk

  • How to use local variables to pass an image mask correctly

    I'm kind of new to labview but i'll try to explain the problem as best as i can: I'm trying to pass an image mask (basically an image) to the next iteration of a while loop using local variables. I think the image passes through the loop with the local variable but i can't read from it correctly for some reason. And I don't think the problem has to do with local variables because i've tried using shift registers and that didnt work either. I think the problem is that you need to do something to read the image correctly again, like using IMAQ copy or something (that didnt work tho), but i can't figure out what the problem is. Does anyone know what the problem is? I know this isnt a great explanation and if its too confusing i could send some snapshots of the program or something. Any help would be greatly appreciated though.
    Thanks,
    Will

    So i attached 2 snapshots of the program to give a better idea of the problem. The first snapshot shows an image getting written to the local variable SavedMask. The second snapshot, which is run on the next iteration of a while loop, shows the local variable SavedMask being read to other image operations. When i run the program, the SavedMask image is always displayed correctly on the front panel, but i can't read from it for whatever reason. I think the problem could be like you said, that im only passing an imaq reference, and i think theres a certain way to extract the image data. Do you know the correct way to extract the image data or how to pass the image data and not just a reference to the data.
    Attachments:
    first.jpg ‏81 KB
    second.jpg ‏68 KB

  • How to use multiple Interfaces for the same BS?

    Hi @ ,
    Is it possible to have a scenarion where i am using multiple interfaces in the same BS based upon some conditional field in the message.
    I amnot able to get the solution I know with condition editor I can have multiple receivers but in my scenarion based upon message fiels i have to decide which BAPI to be used and wht mapping and then post it to the same System
    Any help will be highly rewarded
    Regards

    Hi-
    Yes it is possible you can use multimapping for mapping the interfaces.
    To know more about multimapping see
    http://help.sap.com/saphelp_nw04/helpdata/en/21/6faf35c2d74295a3cb97f6f3ccf43c/content.htm
    Some more helpful links
    /people/jin.shin/blog/2006/02/07/multi-mapping-without-bpm--yes-it146s-possible

  • How  can use a variable in the folowing code?

    How  can use a variable 'W_ROWNUM2' in the folowing code?
    MOVE '1' TO CNT.
    LOOP AT L_T_PM2.
                  CONCATENATE '0' CNT INTO W_ROWNUM2.CONDENSE W_ROWNUM2.
                   CONCATENATE 'F110V-VARI'W_ROWNUM2'(01)' INTO FLD2.
        perform  DYNPRO_FIELD       using FLD2
                                     L_T_PM2-vari12_con.
                   CNT = CNT + 1.
                   CONDENSE CNT.                                                              
    ENDLOOP.
    I need to increment the value of W_ROWNUM2.
    Please ,it is urgent!!

    Hello
    CONCATENATE 'F110V-VARI'W_ROWNUM2'(01)' INTO FLD2.
    Try using spaces between parts of the resulting string.
    CONCATENATE 'F110V-VARI'  W_ROWNUM2  '(01)'   INTO FLD2
    Regards
    Greg Kern.

  • How to use .properties files in Webdynpro Java code?

    Hi all,
      I want to use a logon.properties file when I initial a JCO connection pool in my webdynpro DC (JCO.addClientPool()),but  I found when I deployed this DC to the server, it always giv e me an FileNotFoundException. So I donot know how to deploy a .properties file to the server and how to access this file in my Java code?
    Thans and Best regards
    Deyang

    Hi,
    1) put .properties file to your packege under src\packages folder (src\packages\com\sdn\properties\jco.properties)
    2) load property:
         final InputStream is = getClass().getClassLoader().getResourceAsStream("com/sdn/properties/jco.properties");
         final Properties properties = new Properties();
         try
              properties.load(is);
         catch(Exception e)
              wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
    Regatds Maxim R.

  • How to use Action interface?

    Hello,
    I haven't been programming in JAVA for very long, just over a month. I understand that intefaces are just method signatures and variables that can be used by a class wich implements them and redefines the methods and/or variables. I know that much.. I think.
    My Question:
    I want to use the Action interface for multiple buttons, I just don't know exactly how. dubwai, is the one who suggested the concept to me. Does anyone have any implementation or code wich utilizes the Action interface?
    Thanks very much,
    Bruce

    What you need to do is write a class that extends AbstractAction. I did one for a FileAction class. I have included the code for this below as a reference:
         class FileAction extends AbstractAction
              // Handles file actions
              FileAction(String name)
                   //Constructor
                   super(name);
                   String iconFileName = "images/" + name + ".gif";
                   if(new File(iconFileName).exists())
                        putValue(SMALL_ICON, new ImageIcon(iconFileName));
              FileAction(String name, String tooltip)
                   //Constructor
                   this(name);                                             // Call the other constructor
                   if(tooltip != null)                                   // If there is tooltip text...
                        putValue(SHORT_DESCRIPTION, tooltip);     // store it.
              public void actionPerformed(ActionEvent e)
                   String name = (String)getValue(NAME);
                   if(name.equals(saveAction.getValue(NAME)))
                        // code to handle file Save operation
                        saveOperation();
                   else if(name.equals(saveAsAction.getValue(NAME)))
                        // code to handle file Save As operation
                        File file = showDialog(
                             "Save Sketch As",
                             "Save",
                             "Save the Sketch",
                             's',
                             modelFile == null ? new File(files.getCurrentDirectory(), filename) : modelFile);
                        if (file != null)
                             if (file.exists() && ! file.equals(modelFile))
                                  if (JOptionPane.NO_OPTION ==      //Overwrite warning
                                       JOptionPane.showConfirmDialog(
                                       SketchFrame.this,
                                       file.getName() + " exists. Overwrite?",
                                       "Confirm Save As",
                                       JOptionPane.YES_NO_OPTION,
                                       JOptionPane.WARNING_MESSAGE))
                                  return;     // no file selected
                             saveSketch(file);
                        return;
                   else if(name.equals(openAction.getValue(NAME)))
                        // code to handle file Open operation
                        checkForSave();
                        File file = showDialog("Open Sketch File",     // dialog window title
                             "Open",                                             // button lable
                             "Read a sketch from a file",               // button tooltip text
                             'o',                                             // shortcut character
                             null);                                             // no file selected
                        if (file != null)                                   // if a file was selected
                             openSketch(file);                              // then read it
                   else if(name.equals(newAction.getValue(NAME)))
                        // code to handle file New operation
                        checkForSave();
                        theApp.insertModel(new SketchModel());          // insert new empty sketch
                        modelFile = null;                                   // no file for it
                        filename = DEFAULT_FILENAME;                    // default name
                        setTitle(frameTitle
                             + files.getCurrentDirectory()
                             + "\\"
                             + filename);
                        sketchChanged = false;                              // not changed yet
                   else if(name.equals(exitAction.getValue(NAME)))
                        // code to handle file Exit operation
                        checkForSave();
                        System.exit(0);
                   else if(name.equals(printAction.getValue(NAME)))
                        // code to handle file Print operation
                        PrinterJob printJob = PrinterJob.getPrinterJob();     // get a printing object
                        printJob.setPageable(theApp.getView());     // the view is the page source
                        if(printJob.printDialog())     // display print dialog
                             try
                                  printJob.print();     // then print
                             catch(PrinterException pe)
                                  System.out.println(pe);
                                  JOptionPane.showMessageDialog(SketchFrame.this,
                                       "Error printing a sketch.",
                                       "Printer Error",
                                       JOptionPane.ERROR_MESSAGE);
         }The good thing about Actions is that you can put them in a menu or on a toolbar using the same code.
    Garry.

Maybe you are looking for

  • Is there a fast way to wrap unstructured text into [Para] tags?

    I'm trying out my new Frame 12 by trying to produce an ebook in several formats. I'm using the out-of-copyright Agatha Christie's A MYSTERIOUS AFFAIR AT STYLES. Is there a fast way to wrap each paragraph with a [Para] tag? Thanks in advance.

  • New  AV connection kit

    Hi everyone:)i've just bought new Av connection kit it's pretty good deal and everything looks pretty ok (i thought it would be terrible)on my 32" Plasma TV ,but AV cable (3.5 mm jack) was cracked...yes...I don't even know y..so gonna go and exchange

  • Discover deskto 10g  ,Calculation problem

    Dear All in very short,i have one worksheet with 3 columns,shop name,gross sales,and discount i made total field to display sum of gross sale and discount.i also created one calculation to display discount amount in percent % of gross sale.but i dont

  • 802.1x authentication manager ..!

    Dear Team , I have miss understanding on dot1x authentication manager so, if someone can help me to understand those scenarios :- •1- If I have port configured to authenticate through dot1x first and failover to MAB if dot1x is not successfully. I ha

  • Can't play home movies

    What extra software do I need for I Mac to play my home movies in I Photo, Just upgraded to 10.7.5 in hopes it would work...It didn't!! Help