Help me to run this simple RMI example

When i m running this example in standalone pc it works but while running on to different pc it gives error though I m giving the IP address from client of server.. If anyone can help me out plz help.
Code:
ReceiveMessageInterface
import java.rmi.*;
public interface ReceiveMessageInterface extends Remote
void receiveMessage(String x) throws RemoteException;
Server code:
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.net.*;
public class RmiServer extends java.rmi.server.UnicastRemoteObject
implements ReceiveMessageInterface
int thisPort;
String thisAddress;
Registry registry; // rmi registry for lookup the remote objects.
// This method is called from the remote client by the RMI.
// This is the implementation of the �ReceiveMessageInterface�.
public void receiveMessage(String x) throws RemoteException
System.out.println(x);
public RmiServer() throws RemoteException
try{
// get the address of this host.
thisAddress= (InetAddress.getLocalHost()).toString();
catch(Exception e){
throw new RemoteException("can't get inet address.");
thisPort=3232; // this port(registry�s port)
System.out.println("this address="+thisAddress+",port="+thisPort);
try{
// create the registry and bind the name and object.
registry = LocateRegistry.createRegistry( thisPort );
registry.rebind("rmiServer", this);
catch(RemoteException e){
throw e;
static public void main(String args[])
try{
RmiServer s=new RmiServer();
catch (Exception e) {
e.printStackTrace();
System.exit(1);
Client code:
import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;
public class RmiClient
static public void main(String args[])
ReceiveMessageInterface rmiServer;
Registry registry;
String serverAddress=args[0];
String serverPort=args[1];
String text=args[2];
System.out.println("sending "+text+" to "+serverAddress+":"+serverPort);
try{
// get the �registry�
registry=LocateRegistry.getRegistry(
serverAddress,
(new Integer(serverPort)).intValue()
// look up the remote object
rmiServer=
(ReceiveMessageInterface)(registry.lookup("rmiServer"));
// call the remote method
rmiServer.receiveMessage(text);
catch(RemoteException e){
e.printStackTrace();
catch(NotBoundException e){
e.printStackTrace();
}

When we compile with rmic skeleton and stub get created then we hav to place stub at each client ???Your remote client applcation need only _Stub.class fiels.
Is there way by which we can know how many clients are connected to the
server and there IP address, can anyone give the code... I guess that you should use a RMI login/logout method to register/unregister your client connection information into a databse or a simple static Hashtable(Vector) object.

Similar Messages

  • Error running A Simple MDB example with oc4j

    Hi All,
    I am new to OC4J, I am trying the example for MDB from OTN's site, A Simple MDB example with OC4J. When I start my OC4J on the command line > java -jar oc4j.jar
    I get the following exception:
    Error deploying file:/C:/unzipped/mdb_hello_world/build/mdb/mdb.jar homes: No lo
    cation set for Topic resource MessageDrivenBean MDB
    Error in application mdb: Error loading package at file:/C:/unzipped/mdb_hello_w
    orld/build/mdb/mdb.jar, Error deploying file:/C:/unzipped/mdb_hello_world/build/
    mdb/mdb.jar homes: No location set for Topic resource MessageDrivenBean MDB
    04/07/09 15:21:40 Error instantiating application 'mdb' at file:/C:/unzipped/mdb
    helloworld/build/mdb.ear: Error initializing ejb-module; Exception Error in ap
    plication mdb: Error loading package at file:/C:/unzipped/mdb_hello_world/build/
    mdb/mdb.jar, Error deploying file:/C:/unzipped/mdb_hello_world/build/mdb/mdb.jar
    homes: No location set for Topic resource MessageDrivenBean MDB
    04/07/09 15:21:41 Error starting HTTP-Server: Address already in use: JVM_Bind
    04/07/09 15:21:41 Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)
    initialized
    I have just followed all the steps provided to run the example exactly as given.
    I did add my Topic and TopicConnectionFatory entries in my jms.xml -
    <topic name="The Topic" location="jms/theTopic">
    <description>A MDB topic</description>
    </topic>
    <topic-connection-factory location="jms/theTopicConnectionFactory" />
    Here is the ejb-jar.xml given in the example:
    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar>
    <ejb-jar>
    <enterprise-beans>
    <message-driven>
    <description>My message driven bean</description>
    <ejb-name>MDB</ejb-name>
    <ejb-class>MDB</ejb-class>
    <transaction-type>Container</transaction-type>
    <message-driven-destination>
    <destination-type>javax.jms.Topic</destination-type>
    <subscription-durability>NonDurable</subscription-durability>
    </message-driven-destination>
    <resource-ref>
    <description>The log topic where log events are broadcasted...</description>
    <res-ref-name>jms/theTopic</res-ref-name>
    <res-type>javax.jms.Topic</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    <resource-ref>
    <description>The Factory used to produce connections to the log topic...</description>
    <res-ref-name>jms/theTopicConnectionFactory</res-ref-name>
    <res-type>javax.jms.TopicConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </message-driven>
    </enterprise-beans>
    <assembly-descriptor>
    <container-transaction>
    <method>
    <ejb-name>MDB</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>Supports</trans-attribute>
    </container-transaction>
    </assembly-descriptor>
    </ejb-jar>
    Here is my orion-ejb-jar.xml:
    <?xml version="1.0"?>
    <!DOCTYPE orion-ejb-jar PUBLIC "-//Evermind//DTD Enterprise JavaBeans 1.1 runtime//EN" "http://xmlns.oracle.com/ias/dtds/orion-ejb-jar.dtd">
    <orion-ejb-jar deployment-version="1.0.2.2" deployment-time="e7f5a3f42d">
    <enterprise-beans>
    <message-driven-deployment name="MDB" destination-location="jms/theTopic" connection-factory-location="jms/theTopicConnectionFactory">
    <resource-ref-mapping name="jms/theTopic" />
    <resource-ref-mapping name="jms/theTopicConnectionFactory" />
    </message-driven-deployment>
    </enterprise-beans>
    <assembly-descriptor>
    <default-method-access>
    <security-role-mapping name="&lt;default-ejb-caller-role&gt;" impliesAll="true" />
    </default-method-access>
    </assembly-descriptor>
    </orion-ejb-jar>
    I don't know what is wrong. Please help me.
    Rohini

    Hello,
    I guess that you didn't define the Topic and/or TopicConnectionFactory on your OC4J
    Inside $J2EE_HOME/config (see: subfolders .../j2ee/home/config e.g.)folder are several xml files appropriate for OC4J configuration. There's also jms.xml. Please, verify this one, it should have some entries for your settings.
    Just like in an example below:
    <topic-connection-factory name="TopicConnectionFactory" location="jms/TopicConnectionFactory"/>
    <topic name="theTopic" location="jms/theTopic"/>
    The names should be the same like in your MDB deployment descriptors. It works of course after next OC4J server restart.
    I hope helped you
    Krzysztof

  • Problems running a simple RMI

    Hi there,
    I have had alot of problems running a small RMI program.
    It has now boiled down to a java.lang.NoClassDefFoundError
    when i try to use my policy file.
    The program complies, when i run javac *.java
    It also creates the stub, when i run rmic.
    I have trawled alot of forums and the closest answer i got was "add your classpath".
    As im a student of java, this does not really tell me much.
    The class/java files are in
    C:\Documents and Settings\MONDARIZ\workspace\RmiHello\server
    The policy file is also in the folder.
    I must add, that the program is from an example, so i would not think there is any coding errors.
    Also when i run it en eclipse, i get "Hello server failed: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)"
    So it seems something is running.

    The answer you found is correct. Java needs to know where to find the class files for execution.
    For starters, use the environment variable CLASSPATH. Set the value to:
    C:\Documents and Settings\MONDARIZ\workspace\RmiHello\server
    This way whatever you run (RMI Registry, Server, Client) has the proper class path. When you get everything running ok, then you can look into other methods of specifying where the class files are found.
    Eclipse, as well as command line Java starts, need to find the policy file. Set up this:
    -Djava.security.policy=C:\Documents and Settings\MONDARIZ\workspace\RmiHello\server\your_policy_file.xxx

  • Not able to run a simple RMI server

    I am running an RMI program like follwing
    import java.rmi.* ;
    import java.rmi.registry.* ;
    import java.rmi.server.* ;
    public class CallBeanServer extends UnicastRemoteObject implements ICallBeanServer
         //main
         public static void main(String args[]) throws Exception
              int port = 1000 ;
              Registry reg = null ;
              if( args[0].equals("true"))
                   reg = LocateRegistry.createRegistry(port) ;
                   System.out.println("Successfully created registry") ;
              else
                   reg = LocateRegistry.getRegistry(port) ;
                   System.out.println("Connected to existing registry") ;
              CallBeanServer callBeanServer = new CallBeanServer(reg) ;
         }//main
         //constructor
         public CallBeanServer(Registry reg) throws Exception, RemoteException
              super() ;
              reg.rebind("CallBeanServer",this) ;
              System.out.println("CallBeanServer Object bound") ;
         //my public method
         public String callBeanServer() throws RemoteException
         {          return "Success" ;
    I have run the rmiregistry at port no 1000 like
    rmiregistry 1000
    I have compiled ICallBeanServer also and run rmic also over CallBeanServer like
    rmic CallBeanServer
    when I run this program using
    java CallBeanServer false
    it gives the follwoing errors
    Connected to existing registry
    Exception in thread "main" java.rmi.ServerException: Server RemoteException; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: CallBeanServer_Stub
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: CallBeanServer_Stub
    java.lang.ClassNotFoundException: CallBeanServer_Stub
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at CallBeanServer.<init>(CallBeanServer.java:38)
    at CallBeanServer.main(CallBeanServer.java:30)
    Can you please tell me what is the error?
    Thanks
    Prashant Gupta

    Add the classes (the stubs included) to the classpath when you start the registry.

  • Help: Problem in running a simple EJB client

    Hi All,
    I have just started learning EJB and I am facing an issue in running a client for the EJB I developed (a "Hello World" EJB)
    I have deployed my application in Sun's reference implementation of j2ee server. I have the following client code through which I intend to access EJB methods
    // EJB client code in main()
    Context ctx = new InitialContext();
    Object hwobj = ctx.lookup("HelloWorldApp");
    HelloWorldHome hworldHome = (HelloWorldHome)
    PortableRemoteObject.narrow(hwobj,HelloWorldHome.class); // exception here
    HelloWorld hworld = hworldHome.create();
    String msg = hworld.sayHelloWorld();
    System.out.println(msg);
    When I am running my client I am getting the following exception. Can anyone tell me why ?
    java.lang.ClassCastException
    at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
    at HelloWorldClient.main(HelloWorldClient.java:13)
    Thanks
    Ratheesh

    * I found the solution for this . Add j2ee.jar and Client jar returned by deploytool [ if we check return client jar ] to classpath when running client .
    * Then I got CORBA_NO_PERMISSION error . After searching in forum , I found the solution. Posting
    Forum Home > Enterprise JavaBeans
    Topic: [ J2EE RI Server ] CORBA NO_PERMISSION 0
    Welcome ratheeshpai!
    Search Forum
    Not watching this topic.
    This topic has 4 replies on 1 page (Most recent message: Nov 19, 2002 7:59 AM)
    [ J2EE RI Server ] CORBA NO_PERMISSION 0
    Author: NicholasHsiao Oct 28, 2001 5:51 AM
    Hi,
    I was trying to deploy one simple session bean into J2EE RI Server. It works fine. And I wrote one client to access this session bean, it show me
    java.rmi.AccessException: CORBA NO_PERMISSION 0 No; nested exception is:
    org.omg.CORBA.NO_PERMISSION: minor code: 0 completed: No
    Context ic = null;
    try
    ic = new InitialContext();
    catch(Exception e)
    System.out.println("1: "+e.toString());
    This exception is happend when I try to lookup the jndi name
    This error message is happend only on J2EE 1.3 (1.3_01) . If I downgrade to J2EE 1.3Beta or even 1.2, everything would be okay. Any one know how to solve such problem ??
    Re: [ J2EE RI Server ] CORBA NO_PERMISSION 0
    Author: cdunn5
    In Reply To: [ J2EE RI Server ] CORBA NO_PERMISSION 0 Oct 31, 2001 10:04 PM
    Reply 1 of 4
    hi,
    I don't know the solution but I have the exact same problem. I see your message was posted in October, have you found any solutions yet?
    Re: [ J2EE RI Server ] CORBA NO_PERMISSION 0
    Author: scottiep
    In Reply To: [ J2EE RI Server ] CORBA NO_PERMISSION 0 Nov 22, 2001 11:21 AM
    Reply 2 of 4
    Da:Frederik Hansen ([email protected])
    Message 2 in thread
    Soggetto:Re: J2EE - NO_PERMISSION
    Newsgroups:dk.edb.programmering.java
    View this article only
    Data:2001-11-10 03:32:12 PST
    For at svare p� mit eget sp�rgsm�l: Access and Security Issues Q1: Some applications that ran under J2EE SDK 1.3
    beta 2 stop running under the 1.3 FCS release with the
    following message: java.rmi.AccessException: CORBA
    NO_PERMISSION 0 No. Why does this happen and what
    can be done about it? When your application ran under the 1.3 beta 2
    version of the reference implementation (RI), security permissions may
    not have
    been checked. For example, the beta 2 RI allowed
    calls to enterprise beans that required username-password permission,
    even
    when the client provided no username-password
    information. With 1.3 FCS release, the J2EE SDK became strict
    about checking adherence to the security policies of J2EE components. How can you make your application run under the
    FCS release? 1.If you don't want security checks, do the
    following: Use the deploytool to build a deployment
    descriptor that does not require a strict security policy: Under the Security screen of the EJB wizard
    or the Security tab of the EJB inspector in deploytool, click
    "Deployment
    Settings..". Under the box "Client
    Authentication", make sure "Support Client Choice" is checked instead of
    "Certificate"
    or "Password". 2.To require the application pass security
    checks to run, do the following: When an enterprise bean specifies
    "Certificate" or "Password" as the method of Client Authentication, use
    a J2EE
    application client, instead of a stand-alone
    Java application, to access the bean. You will need to login as a valid
    J2EE
    user.
    By : scottiep
    Thanks
    Ratheesh

  • Please help me to run this CMP BEAN, I need help urgently, I am running out of time :(

    Hi,
    I am facing this problem, Please help me, I am attaching the source files
    also along with the mail. This is a small CMP EJB application, I am using
    IAS SP2 on NT server with Oracle 8. I highly appreciate if someone can send
    me the working copy of the same. I need these urgent. I am porting all my
    beans from bea weblogic to Iplanet. Please help me dudes.
    Err.........
    [06/Sep/2001 13:41:29:7] error: EBFP-marshal_internal: internal exception
    caught
    in kcp skeleton, exception = java.lang.NoSuchMethodError
    [06/Sep/2001 13:41:29:7] error: Exception Stack Trace:
    java.lang.NoSuchMethodError
    at
    com.se.sales.customer.ejb_kcp_skel_CompanyHome.create__com_se_sales_c
    ustomer_Company__java_lang_Integer__indir_wstr__215617959(ejb_kcp_skel_Compa
    nyHo
    me.java:205)
    at com.kivasoft.ebfp.FPRequest.invokenative(Native Method)
    at com.kivasoft.ebfp.FPRequest.invoke(Unknown Source)
    at
    com.se.sales.customer.ejb_kcp_stub_CompanyHome.create(ejb_kcp_stub_Co
    mpanyHome.java:297)
    at
    com.se.sales.customer.ejb_stub_CompanyHome.create(ejb_stub_CompanyHom
    e.java:89)
    at
    com.se.sales.customer.CompanyServlet.doGet(CompanyServlet.java:35)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    at
    com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
    Source)
    at
    com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unkno
    wn Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at java.lang.Thread.run(Thread.java:479)
    Caught an exception.
    java.rmi.RemoteException: SystemException: exid=UNKNOWN
    at com.kivasoft.eb.EBExceptionUtility.idToSystem(Unknown Source)
    at com.kivasoft.ebfp.FPUtility.replyToException(Unknown Source)
    at
    com.se.sales.customer.ejb_kcp_stub_CompanyHome.create(ejb_kcp_stub_Co
    mpanyHome.java:324)
    at
    com.se.sales.customer.ejb_stub_CompanyHome.create(ejb_stub_CompanyHom
    e.java:89)
    at
    com.se.sales.customer.CompanyServlet.doGet(CompanyServlet.java:35)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    at
    com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
    Source)
    at
    com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unkno
    wn Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at java.lang.Thread.run(Thread.java:479)
    Thanks in advance
    Shravan
    [Attachment iplanet_app.jar, see below]
    [Attachment iplanet_src.jar, see below]

    One reason that I sometimes get 'NoSuchMethodError' is when I make a change to a
    java class that is imported into another java class. When I go to run the
    importing class, it will throw a 'NoSuchMethodError' on any methods that I've
    changed in the imported class. The solution is to recompile the importing class
    with the changed classes in the classpath.
    shravan wrote:
    Hi,
    I am facing this problem, Please help me, I am attaching the source files
    also along with the mail. This is a small CMP EJB application, I am using
    IAS SP2 on NT server with Oracle 8. I highly appreciate if someone can send
    me the working copy of the same. I need these urgent. I am porting all my
    beans from bea weblogic to Iplanet. Please help me dudes.
    Err.........
    [06/Sep/2001 13:41:29:7] error: EBFP-marshal_internal: internal exception
    caught
    in kcp skeleton, exception = java.lang.NoSuchMethodError
    [06/Sep/2001 13:41:29:7] error: Exception Stack Trace:
    java.lang.NoSuchMethodError
    at
    com.se.sales.customer.ejb_kcp_skel_CompanyHome.create__com_se_sales_c
    ustomer_Company__java_lang_Integer__indir_wstr__215617959(ejb_kcp_skel_Compa
    nyHo
    me.java:205)
    at com.kivasoft.ebfp.FPRequest.invokenative(Native Method)
    at com.kivasoft.ebfp.FPRequest.invoke(Unknown Source)
    at
    com.se.sales.customer.ejb_kcp_stub_CompanyHome.create(ejb_kcp_stub_Co
    mpanyHome.java:297)
    at
    com.se.sales.customer.ejb_stub_CompanyHome.create(ejb_stub_CompanyHom
    e.java:89)
    at
    com.se.sales.customer.CompanyServlet.doGet(CompanyServlet.java:35)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    at
    com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
    Source)
    at
    com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unkno
    wn Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at java.lang.Thread.run(Thread.java:479)
    Caught an exception.
    java.rmi.RemoteException: SystemException: exid=UNKNOWN
    at com.kivasoft.eb.EBExceptionUtility.idToSystem(Unknown Source)
    at com.kivasoft.ebfp.FPUtility.replyToException(Unknown Source)
    at
    com.se.sales.customer.ejb_kcp_stub_CompanyHome.create(ejb_kcp_stub_Co
    mpanyHome.java:324)
    at
    com.se.sales.customer.ejb_stub_CompanyHome.create(ejb_stub_CompanyHom
    e.java:89)
    at
    com.se.sales.customer.CompanyServlet.doGet(CompanyServlet.java:35)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    at
    com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
    Source)
    at
    com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unkno
    wn Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at java.lang.Thread.run(Thread.java:479)
    Thanks in advance
    Shravan
    Name: iplanet_app.jar
    iplanet_app.jar Type: Java Archive (application/java-archive)
    Encoding: x-uuencode
    Name: iplanet_src.jar
    iplanet_src.jar Type: Java Archive (application/java-archive)
    Encoding: x-uuencode

  • Need help - how to run this particular method in the main method?

    Hi all,
    I have a problem with methods that involves objects such as:
    public static Animal get(String choice) { ... } How do we return the "Animal" type object? I understand codes that return an int or a String but when it comes to objects, I'm totally lost.
    For example this code:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            TestAnimal ta = new TestAnimal();
            ta.get(); // error
            // doing Animal a = new Animal() is horrible... :(                   
        public static Animal get(String choice) {
            Scanner myScanner = new Scanner(System.in);
            choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }Out of desperation, I tried "Animal a = new Animal() ", and it was disastrous because an interface cannot be instantiated. :-S And I have no idea what else to put in my main method to get the code running. Need some help please.
    Thank you.

    Hi paulcw,
    Thank you. I've modified my code but it still doesn't print "roar" or "trumpet". When it returns a Lion or an Elephant, wouldn't the soundOff() method get printed too?
    refactored:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            Animal a = get();
        public static Animal get() {
            Scanner myScanner = new Scanner(System.in);
            System.out.println("Meat eater or not?");
            String choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }The soundOff() method should override the soundOff(); method in the interface, right? So I'm thinking, it should print either "roar" or "trumpet" but it doesn't. hmm..

  • Help me to run this filter...please

    Hi guys,
    i'm a problem and i don't find a solution from 10 days....please help me.
    I have to give access security to my jsf application because each page shows private information. I have a login page and a visit bean that store the session's information,like current user and current locale.
    I've developed a filter that when a page is loaded try to retrieve user from Visit Object,if it's not found go to login page.
    What's my problem?
    When i try to open from my browser a page different from Login my application shows me the page,without addressing me to Login Page.
    When i go to
    http://localhost:8080/MicroArray/pages/protected/Menu.jsf
    i see the page Menu while i want LOGIN!
    Can you help me?
    I post you the important code.
    This is the important code of mu AuthenticationBean
    User newUser=new User(loginName,password,teamName,tipo);
    Visit visit = new Visit();
    visit.setUser(newUser);
    visit.setAuthenticationBean(this);
    setVisit(visit);
    FacesContext facesContext = getFacesContext();
    getApplication().createValueBinding("#{sessionScope.visit}").setValue(facesContext, visit);this is my Visit Object
    package giu;
    import javax.faces.context.FacesContext;
    import java.util.Locale;
    import javax.faces.model.SelectItem;
    import javax.faces.application.Application;
    import java.util.*;
    import java.io.Serializable;
    public class Visit implements Serializable
    private static final long serialVersionUID = 1L;
    private User user;
    private AuthenticationBean authenticationBean;
    public Visit()
    public User getUser()
    return user;
    public void setUser(User user)
    this.user = user;
    public AuthenticationBean getAuthenticationBean()
    return authenticationBean;
    public void setAuthenticationBean(AuthenticationBean authenticationBean)
    this.authenticationBean = authenticationBean;
    }and this is my filter
    package giu;
    import java.io.IOException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class AuthorizationFilter implements Filter
    FilterConfig config = null;
    ServletContext servletContext = null;
    public AuthorizationFilter()
    public void init(FilterConfig filterConfig) throws ServletException
    config = filterConfig;
    servletContext = config.getServletContext();
    public void doFilter(ServletRequest request, ServletResponse response,
                        FilterChain chain) throws IOException, ServletException
    Utils.log(servletContext, "Inside the filter");
    HttpServletRequest httpRequest = (HttpServletRequest)request;
    HttpServletResponse httpResponse = (HttpServletResponse)response;
    HttpSession session = httpRequest.getSession();
    String requestPath = httpRequest.getPathInfo();
    Visit visit = (Visit)session.getAttribute("visit");
    if (visit == null)
       session.setAttribute("originalTreeId", httpRequest.getPathInfo());
       Utils.log(servletContext, "redirecting to " + httpRequest.getContextPath() +
                 "/faces/index.jsp");
       httpResponse.sendRedirect(httpRequest.getContextPath() +
                 "/faces/index.jsp");
    else
       session.removeAttribute("originalTreeId");
       String role = visit.getUser().getRole();
       if ((role.equals("utente") &&  requestPath.indexOf("protected") > 0))
         String text = Utils.getDisplayString("ptrackResources",
                                              "PathNotFound",
                                              new Object[] { requestPath },
                                              request.getLocale());
         httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND,
                                text);
       else*/
         chain.doFilter(request, response);
    Utils.log(servletContext, "Exiting the filter");
    public void destroy()
    }index.jsp addresses to /pages/protected/Login.jsf...
    with its declaration in web.xml
    <filter>
    <filter-name>AuthorizationFilter</filter-name>
    <filter-class>giu.AuthorizationFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>AuthorizationFilter</filter-name>
    <url-pattern>/faces/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>AuthorizationFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>Please help me.....

    Hi guys,
    i'm a problem and i don't find a solution from 10 days....please help me.
    I have to give access security to my jsf application because each page shows private information. I have a login page and a visit bean that store the session's information,like current user and current locale.
    I've developed a filter that when a page is loaded try to retrieve user from Visit Object,if it's not found go to login page.
    What's my problem?
    When i try to open from my browser a page different from Login my application shows me the page,without addressing me to Login Page.
    When i go to
    http://localhost:8080/MicroArray/pages/protected/Menu.jsf
    i see the page Menu while i want LOGIN!
    Can you help me?
    I post you the important code.
    This is the important code of mu AuthenticationBean
    User newUser=new User(loginName,password,teamName,tipo);
    Visit visit = new Visit();
    visit.setUser(newUser);
    visit.setAuthenticationBean(this);
    setVisit(visit);
    FacesContext facesContext = getFacesContext();
    getApplication().createValueBinding("#{sessionScope.visit}").setValue(facesContext, visit);this is my Visit Object
    package giu;
    import javax.faces.context.FacesContext;
    import java.util.Locale;
    import javax.faces.model.SelectItem;
    import javax.faces.application.Application;
    import java.util.*;
    import java.io.Serializable;
    public class Visit implements Serializable
    private static final long serialVersionUID = 1L;
    private User user;
    private AuthenticationBean authenticationBean;
    public Visit()
    public User getUser()
    return user;
    public void setUser(User user)
    this.user = user;
    public AuthenticationBean getAuthenticationBean()
    return authenticationBean;
    public void setAuthenticationBean(AuthenticationBean authenticationBean)
    this.authenticationBean = authenticationBean;
    }and this is my filter
    package giu;
    import java.io.IOException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class AuthorizationFilter implements Filter
    FilterConfig config = null;
    ServletContext servletContext = null;
    public AuthorizationFilter()
    public void init(FilterConfig filterConfig) throws ServletException
    config = filterConfig;
    servletContext = config.getServletContext();
    public void doFilter(ServletRequest request, ServletResponse response,
                        FilterChain chain) throws IOException, ServletException
    Utils.log(servletContext, "Inside the filter");
    HttpServletRequest httpRequest = (HttpServletRequest)request;
    HttpServletResponse httpResponse = (HttpServletResponse)response;
    HttpSession session = httpRequest.getSession();
    String requestPath = httpRequest.getPathInfo();
    Visit visit = (Visit)session.getAttribute("visit");
    if (visit == null)
       session.setAttribute("originalTreeId", httpRequest.getPathInfo());
       Utils.log(servletContext, "redirecting to " + httpRequest.getContextPath() +
                 "/faces/index.jsp");
       httpResponse.sendRedirect(httpRequest.getContextPath() +
                 "/faces/index.jsp");
    else
       session.removeAttribute("originalTreeId");
       String role = visit.getUser().getRole();
       if ((role.equals("utente") &&  requestPath.indexOf("protected") > 0))
         String text = Utils.getDisplayString("ptrackResources",
                                              "PathNotFound",
                                              new Object[] { requestPath },
                                              request.getLocale());
         httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND,
                                text);
       else*/
         chain.doFilter(request, response);
    Utils.log(servletContext, "Exiting the filter");
    public void destroy()
    }index.jsp addresses to /pages/protected/Login.jsf...
    with its declaration in web.xml
    <filter>
    <filter-name>AuthorizationFilter</filter-name>
    <filter-class>giu.AuthorizationFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>AuthorizationFilter</filter-name>
    <url-pattern>/faces/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>AuthorizationFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>Please help me.....

  • Beginner Question | The use of modulus in this simple code example.

    Hello everyone,
    I am just beginning to learn Java and have started reading "Java Programming for the absolute beginner". It is quite a old book but seems to be doing the trick, mainly.
    There is a code example which I follow mostly but the use of the modulus operator in the switch condition doesn't make sense to me, why is it used? Could someone shed some light on this for me?
    import java.util.Random;
    public class FortuneTeller {
      public static void main(String args[]) {
        Random randini = new Random();
        int fortuneIndex;
        String day;
        String[] fortunes = { "The world is going to end :-(.",
          "You will have a HORRIBLE day!",
          "You will stub your toe.",
          "You will find a shiny new nickel.",
          "You will talk to someone who has bad breath.",
          "You will get a hug from someone you love.",
          "You will remember that day for the rest of your life!",
          "You will get an unexpected phone call.",
          "Nothing significant will happen.",
          "You will bump into someone you haven't seen in a while.",
          "You will be publicly humiliated.",
          "You will find forty dollars.",
          "The stars will appear in the sky.",
          "The proper authorities will discover your secret.",
          "You will be mistaken for a god by a small country.",
          "You will win the lottery!",
          "You will change your name to \"Bob\" and move to Alaska.",
          "You will discover first hand that Bigfoot is real.",
          "You will succeed at everything you do.",
          "You will learn something new.",
          "Your friends will treat you to lunch.",
          "You will meet someone famous.",
          "You will be very bored.",
          "You will hear your new favorite song.",
          "Tomorrow... is too difficult to predict" };
        System.out.println("\nYou have awakened the Great Randini...");
        fortuneIndex = randini.nextInt(fortunes.length);
        switch (randini.nextInt(7) % 7) {   
          case 0:
            day = "Sunday";
            break;
          case 1:
            day = "Monday";
            break;
          case 2:
            day = "Tuesday";
            break;
          case 3:
            day = "Wednesday";
            break;
          case 4:
            day = "Thursday";
            break;
          case 5:
            day = "Friday";
            break;
          case 6:
            day = "Saturday";
            break;
          default:
            day = "Tomorrow";
        System.out.println("I, the Great Randini, know all!");
        System.out.println("I see that on " + day);
        System.out.println("\n" + fortunes[fortuneIndex]);
        System.out.println("\nNow, I must sleep...");
    }

    randini.nextInt(7) % 7randini.nextInt(7) returns a value in the range 0 <= x < 7, right? (Check the API!) And:
    0 % 7 == 0
    1 % 7 == 1
    2 % 7 == 2
    3 % 7 == 3
    4 % 7 == 4
    5 % 7 == 5
    6 % 7 == 6Looks like superfluous code to me. Maybe originally they wrote:
    randini.nextInt() % 7Note this code has problems, because, for example -1 % 7 == -1

  • Help me to understand this simple program..

    Below coding cannot be compiled...please help me
    public class demo{
    private String employeeName;
    public static void main(String args[]) {
    System.out.println("Hello, World");
    employeeName = "Jeremy";
    showMessage("Employee:");
    static void showMessage(String msg) {
    int i;
    System.out.println(msg+ " " +employeeName);
    }

    When posting code, make sure you use the CODE tags to preserve highlighting. Otherwise nobody will read it.
    Also, if you have errors, tell us what they are! Copy the whole error message here, and point out which line numbers are mentioned in the error.
    At first glance though, you should learn exactly what "static" means in a Java program.

  • Simple RMI error

    Hello,
    I'm trying to compile and execute a simple RMI example. The compilation is OK.
    The rmiregistry is running.
    I'm using windows and java 1.5
    I have the files:
    Server <== the Server
    myStudentImpl <== remote object
    myStudent <== interface
    myStudentImpl_Stub <== the Stub of myStudentImpl (generated by rmic)
    When I'm trying to execute the command from the Server file
    Naming.rebind("john",student);
    I'm getting an error.
    Error:RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: myStudentImpl_Stub
    Then I executed
    C:\myrmi2>java -Djava.rmi.server.codebase=c:/myrmic2 Server
    .... and I got the below error
    Error:Error unmarshaling return; nested exception is:
    java.net.MalformedURLException: unknown protocol: c
    Probably, I have a mistake with the environment variables.
    Can anybody help me, please?
    Thanks

    Now I'm getting
    Error(2):error marshalling arguments; nested exception is:
         java.io.NotSerializableException: testprovider.DS.DS_TicketImpl
    This is my interface
    public interface DS_Ticket extends Remote
    public EncryptedTicket RequestTicket(RequestForTicket req) throws RemoteException;
    This is my return object
    public class EncryptedTicket implements java.io.Serializable
    public byte[] cipherToken2;
    public byte[] cipherSignToken2;
    public byte[] cipherSignature;
    public String Description;
    This is the parameter object
    public class RequestForTicket implements java.io.Serializable
    public PublicKey pubKey;
    public byte[] e_s_Token2;
    public byte[] e_Token2;
    public byte[] BeKey;
    public byte[] BeToken;
    public byte[] signature;
    Any idea what I'm doing wrong?
    Thank you very much

  • Simple JSP example problems

    Hello, I am new to JSP and I was wondering if I could get some help from some people that know what they are doing. I'm trying to run a simple JSP example that I got out of a book. But I've modified it a bit to just play around with it. But it doesn't want to run. I'm starting to think it's something wrong with the way I'm building/installing the stuff. I'm running IBM WebSphere 4 and JBuilder 8. I was just wondering if you could look at my code just to make sure I'm doing this right.
    It's a pretty simple example. A JSP calls a class to get a message to print out.
    Here's the code for the class: (HelloWorld.java)
    package helloworld;
    public class HelloWorld
    private String message = "No message specified";
    public String getMessage()
    return(message);
    public void setMessage(String message)
    this.message = message;
    =================================================================
    Here's the code for the JSP: (HelloWorld.jsp)
    <html>
    <head>
    <title>Using JavaBeans with JSP</title>
    </head>
    <body>
    <jsp:useBean id="helloWorld" class = "helloworld.HelloWorld" />
    <ol>
    <li>Initial Value (JSP Expression):
    <%= helloWorld.getMessage() %></li>
    <li><jsp:setProperty name="helloWorld"
    property="message"
    value="Hello World" />
    Value after setting property with setProperty:
    <jsp:getProperty name="helloWorld"
    property="message" /></li>
    </ol>
    </body>
    </html>
    I just wanted to be able to test out a JSP hitting a class file. Does someone have a better/easier way to do this? Or do you see anything wrong with my example? Thanks in advance.

    The 1 thing missing in your example is the import directive for the helloworld.HelloWorld class.
    Add the following line somewhere around the start of your jsp and things should be fine
    <%@ page import="helloworld.HelloWorld" %>
    Cheers

  • Stocks RMI example not working - Security Exception

    Hi,
    I was trying to run the "Stocks" RMI example that comes with
    Weblogic server(see
    http://www.weblogic.com/docs45/classdocs/API_rmi.html#clientside)
    I compiled and configured the appropriate files, and tried to
    load the sample applet (StockApplet.java) loaded on the
    StockApplet.html page (using Microsoft IE browser).
    However, the applet generated the following exception :
    java.lang.ExceptionInInitializerError: com/ms/security/SecurityExceptionEx
         at weblogic/common/internal/TengahClassLoaders.registerURL (TengahClassLoaders.java:51)
         at weblogic/rjvm/RJVMImpl.loadFromCluster (RJVMImpl.java:1106)
         at weblogic/jndi/WLInitialContextFactoryDelegate.newContext (WLInitialContextFactoryDelegate.java:247)
         at weblogic/jndi/WLInitialContextFactoryDelegate.getInitialContext (WLInitialContextFactoryDelegate.java:205)
         at weblogic/jndi/Environment.getContext (Environment.java:122)
         at weblogic/jndi/Environment.getInitialContext (Environment.java:105)
         at weblogic/rmi/Naming.getContext (Naming.java:225)
         at weblogic/rmi/Naming.lookup (Naming.java:67)
         at examples/rmi/stock/StockApplet.init (StockApplet.java:127)
         at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
         at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.run (AppletPanel.java)
         at java/lang/Thread.run (Thread.java)
    As you can see this looks like some sort of security exception. (StockApplet.java:127)
    in the above exception is the line where StockApplet calls Naming.lookup(). So
    I'm guessing it has something to do with it getting the Weblogic's RMI support
    classes to the local VM and deserializing and installing them, which generates
    a security exception.
    What needs to be done to make the example work properly?
    Thanks,
    Leonid Portnoy
    (In addition, two more types of exceptions are generated, which might be related
    to the cause of the above exception. These exceptions are :
    com.ms.security.SecurityExceptionEx[weblogic/rjvm/JVMID.setLocalID]: cannot connect
    to "testserver"
         at com/ms/security/permissions/NetIOPermission.check (NetIOPermission.java)
         at com/ms/security/PolicyEngine.deepCheck (PolicyEngine.java)
         at com/ms/security/PolicyEngine.checkPermission (PolicyEngine.java)
         at com/ms/security/StandardSecurityManager.chk (StandardSecurityManager.java)
         at com/ms/security/StandardSecurityManager.chkex (StandardSecurityManager.java)
         at com/ms/security/StandardSecurityManager.checkConnect (StandardSecurityManager.java)
         at java/net/InetAddress.getLocalHost (InetAddress.java)
         at weblogic/rjvm/JVMID.setLocalID (JVMID.java:59)
         at weblogic/rjvm/JVMID.localID (JVMID.java:43)
         at weblogic/rjvm/LocalRJVM.getID (LocalRJVM.java:143)
         at weblogic/rmi/extensions/BasicServerObjectReference.<init> (BasicServerObjectReference.java:44)
         at weblogic/rmi/extensions/BasicServerObjectAdapter.<init> (BasicServerObjectAdapter.java:43)
         at weblogic/rmi/extensions/BasicRequestHandler.<init> (BasicRequestHandler.java:30)
         at weblogic/rmi/extensions/BasicRequestDispatcher.<init> (BasicRequestDispatcher.java:42)
         at weblogic/rmi/internal/OIDManager.initializeDGCServer (OIDManager.java:267)
         at weblogic/rmi/internal/OIDManager.getReplacement (OIDManager.java:176)
         at weblogic/rmi/internal/OIDManager.replaceObject (OIDManager.java:84)
         at weblogic/rmi/server/UnicastRemoteObject.exportObject (UnicastRemoteObject.java:25)
         at examples/rmi/stock/StockApplet.init (StockApplet.java:110)
         at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
         at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.run (AppletPanel.java)
         at java/lang/Thread.run (Thread.java)
    and
    com.ms.security.SecurityExceptionEx[weblogic/jndi/Environment.getProperty]: Unable
    to access system property: weblogic.jndi.provider.rjvm
         at com/ms/security/permissions/PropertyPermission.check (PropertyPermission.java)
         at com/ms/security/PolicyEngine.shallowCheck (PolicyEngine.java)
         at com/ms/security/PolicyEngine.checkCallersPermission (PolicyEngine.java)
         at com/ms/security/StandardSecurityManager.chk (StandardSecurityManager.java)
         at com/ms/security/StandardSecurityManager.checkPropertyAccess (StandardSecurityManager.java)
         at java/lang/System.getProperty (System.java)
         at weblogic/jndi/Environment.getProperty (Environment.java:598)
         at weblogic/jndi/Environment.getProviderRJVM (Environment.java:691)
         at weblogic/jndi/WLInitialContextFactoryDelegate.getInitialContext (WLInitialContextFactoryDelegate.java:166)
         at weblogic/jndi/Environment.getContext (Environment.java:122)
         at weblogic/jndi/Environment.getInitialContext (Environment.java:105)
         at weblogic/rmi/Naming.getContext (Naming.java:225)
         at weblogic/rmi/Naming.lookup (Naming.java:67)
         at examples/rmi/stock/StockApplet.init (StockApplet.java:127)
         at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
         at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.run (AppletPanel.java)
         at java/lang/Thread.run (Thread.java)

    Can you post the Stock Applet and other source files...
    Jamal
    ([email protected])

  • Help me to run pkg via procedure

    i have a package :  
    create or replace
    PACKAGE SUBS_INS_API_SS
    IS
    PROCEDURE SUBSCRIBER_INS_SS
        (SOURCE_SYS_ID IN VARCHAR2,
        TRACKING_ID   IN VARCHAR2,
        ACCOUNT_NO IN VARCHAR2,
        prepaidActDevDetails_tab IN prepaidActDeviceDetails_tabobj,
        ERROR_CODE OUT VARCHAR2);
    END SUBS_INS_API_SS;
    pprepaidActDevDetails_tab  is a plsql table and  prepaidActDeviceDetails_tabobj is an object it contains few variable's check below procedure.
    If i run the above package by giving input's via the below procedure. Then i got an error:
    Error(35,7): PLS-00306: wrong number or types of arguments in call to 'SUBSCRIBER_INS_SS'
    create or replace
    PROCEDURE SAMPLE_EXC
    IS
    ERRORCOD VARCHAR2 (30):= NULL ;
    SOURCE_SYS_ID1 VARCHAR2 (30):= '5698745';
    TRACKING_ID1   VARCHAR2 (30):= '5874125';
    ACCOUNT_NO1    VARCHAR2 (30):= NULL;
    prepaidAccountDetails1         prepaid_act_dvc_details_obj
                                           := prepaid_act_dvc_details_obj  ('CM00000006184',  '00:1C:15:15:15:42', NULL,  'HSD',  NULL, '1',  NULL,  '12',  NULL, NULL);
    BEGIN
          SUBS_INS_API_SS.SUBSCRIBER_INS_SS(SOURCE_SYS_ID1, TRACKING_ID1, ACCOUNT_NO1, prepaidAccountDetails1, ERRORCOD);
           DBMS_OUTPUT.PUT_LINE( ERRORCOD);                                 
    END;
    please help me to run this package via the procedure.

    Moderator Action:
    Stay with your original "how do I run a package" thread from the previous day:
    https://community.oracle.com/thread/2615939
    You already have responses there.
    Keep all information there instead of fragmenting it among separate posts.
    This new thread is locked.

  • How to Run a simple servlet "HelloWorld.java" in JBoss 3.0 ?

    Dear all,
    I am a beginner and I want to run a simple "HelloWorld.java" servlet .
    I need to use JBoss 3.0 .
    After I run this simple servlet, I need to use EJB-Servlet-JSP to implement MVC .
    I have the servlet code and I am able to compile it.
    But I dont know how to proceed as to where to put the class files , where do I specify an alias for my servlet and what modifications I need in Web.xml,Jboss.xml,Application.xml ?
    I do not anything about tools like Ant or Xdoclet so need to proceed without them.Please alos let me know where I can fond complete info about Ant and Xdoclet .
    Thanx in Advance,
    Sujith

    I am not sure of the JBoss package that you are using. If you are using the JBoss-Tomcat package, here's the solution. Create either a .war file or create a directory with the name <your-webapp>.war under <jboss-root>/server/default/deploy. If you are creating a war file, you have to place that war file in the same directory. JBoss-Tomcat will keep looking at this directory for new files or updates to files and deploys/re-deploys as required.
    The contents of the war file should be something like this.
    WEB-INF - directory
    WEB-INF/classes - your servlet classes
    WEB-INF.web.xml - your configuration. Here you can specify the servlet name, class and URI mapping.
    Now, you can call your servlet using the browser in this way: http://localhost:8080/<your-webapp>/servlet/<servlet-alias>. Here the <your-webapp> is the prefix of the .war file.
    Resources:
    Ant - http://jakarta.apache.org/ant/
    Xdoclet - http://xdoclet.sourceforge.net/

Maybe you are looking for