IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java EE Discussion :

Problème simple d'initialisation de java.util.Properties pour recuperer un context (jndi)


Sujet :

Java EE

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    728
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 728
    Points : 250
    Points
    250
    Par défaut Problème simple d'initialisation de java.util.Properties pour recuperer un context (jndi)
    Bonjour,
    j'ai un problème qui semble tout bète qui ne fonctionne pas
    dans le cadre d'utilisation d'EJB, j'ai besoin d'initialiser un objet java.util.Properties pour creer un context (jndi). Voici le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    	java.util.Properties jndiProperties = new Properties();
    	javax.naming.Context ctx = null;
    	public void initializeContextAndConsoleReader() {
    		// Context.URL_PKG_PREFIXES = "java.naming.factory.url.pkgs"
    1		jndiProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
    		// Context.INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial"
    2		jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
    		// Context.PROVIDER_URL = "java.naming.provider.url"
    3		jndiProperties.put(Context.PROVIDER_URL, "remote://localhost:4447");
    4		jndiProperties.put("jboss.naming.client.ejb.context", true);
    		try {
    5			ctx = new InitialContext(jndiProperties);
    		} catch (NamingException ex) {
    			ex.printStackTrace();
    		}
    en mode debug j'obtiens la sortie suivante en mettant un point d'arrêt à la ligne 3. Première remarque : la table de jndiProperties m'indique un 4 ième élément (en fait je parle du 4 entre crochet sans savoir si cela correspond à une ligne) et un 9 ième. Pourquoi ? A part cela tout va bien.

    Nom : Capture d’écran 2014-09-23 à 15.39.01.png
Affichages : 313
Taille : 58,9 Ko

    au point d'arret à la ligne 5 j'obtiens la sortie suivante. Et là je vois Que c'est un 4ième élément qui a été mis à jour avec les données de la ligne 4 et le 9ième élément a été mis à jour avec les données de la ligne 3. Normalement je devrais avoir 4 lignes avec les données des lignes 1,2,3,4. Je n'y comprends rien. Est-ce que qulqu'un peut m'expliquer ?

    Nom : Capture d’écran 2014-09-23 à 15.47.51.png
Affichages : 305
Taille : 57,2 Ko

  2. #2
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    Regarder la structure interne d'un objet, complexe de plus, ne va pas t'aider beaucoup...

    Par contre on voit dans les screenshots que le "count" est "2"... Après, que la structure interne des hashtable décide de le stocker dans l'index 4 ou 9 de son tableau, ça c'est lié au fonctionnement des tables de hashage, et franchement, ne te sert à rien en tant qu'utilisateur de la classe...

    Mais ce que j'ai pas trop compris, c'est "où est le problème"?
    "Le plug gros problème des citations trouvées sur internet, c'est qu'on ne peut jamais garantir leur authenticité"

    Confucius, 448 av. J-C

  3. #3
    Membre actif
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    728
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 728
    Points : 250
    Points
    250
    Par défaut
    Bonjour Pill_S et merci pour ta réponse,

    en effet mon problème est autre part. J'ai un client EJB et j'essaye d'utiliser un remote stateless EJB session à partir d'un context que j'obtiens par un objet Properties (voir le code ci dessous). En mode debug, quand je fais un lookup sur mon context pour recuperer mon remote stateless EJB, (ligne bleue) cela a l'air de fonctionner. Mais quand j'essaye d'utiliser une methode de ce remote bean (ligne rouge), j'obtiens l'erreur suivante

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    EJBCLIENT000025: No EJB receiver available for handling [appName:EJBTutorial, moduleName:EJBTutorialEJB, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@56811df
    Aurais-tu une idée ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.List;
    import java.util.Properties;
    
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    
    import com.tutorialspoint.sessionbean.stateless.LibrarySessionBeanRemote;
    
    public class Main {
    
    	BufferedReader brConsoleReader = null;
    	Properties jndiProperties = new Properties();
    	Context ctx = null;
    	public void initializeContextAndConsoleReader() {
    		// Context.URL_PKG_PREFIXES = "java.naming.factory.url.pkgs"
    		jndiProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
    		// Context.INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial"
    		jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
    		// Context.PROVIDER_URL = "java.naming.provider.url"
    		jndiProperties.put(Context.PROVIDER_URL, "remote://localhost:4447");
    		jndiProperties.put("jboss.naming.client.ejb.context", true);
    		try {
    			ctx = new InitialContext(jndiProperties);
    		} catch (NamingException ex) {
    			ex.printStackTrace();
    		}
    		brConsoleReader = new BufferedReader(new InputStreamReader(System.in));
    	}
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Main ejbTester = new Main();
    		ejbTester.initializeContextAndConsoleReader();
    		ejbTester.testStatelessEjb();
    	}
    
    	public Context getContext() throws NamingException {
    		return new InitialContext(jndiProperties);
    	}
    
    	/*
    	 * (non-Java-doc)
    	 *
    	 * @see java.lang.Object#Object()
    	 */
    	public Main() {
    		super();
    	}
    
    	private void showGUI() {
    		System.out.println("**********************");
    		System.out.println("Welcome to Book Store");
    		System.out.println("**********************");
    		System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice: ");
    	}
    
    	private void testStatelessEjb() {
    		try {
    			int choice = 1;
    			String viewClassName = LibrarySessionBeanRemote.class.getName();
    			LibrarySessionBeanRemote libraryBean = (LibrarySessionBeanRemote) ctx.lookup("ejb:EJBTutorial/EJBTutorialEJB//LibrarySessionBean!"+ viewClassName);
    			while (choice != 2) {
    				String bookName;
    				showGUI();
    				String strChoice = brConsoleReader.readLine();
    				choice = Integer.parseInt(strChoice);
    				if (choice == 1) {
    					System.out.print("Enter book name: ");
    					bookName = brConsoleReader.readLine();
    					libraryBean.addBook(bookName);
    				} else if (choice == 2) {
    					break;
    				}
    			}
    			List<String> booksList = libraryBean.getBooks();
    			System.out.println("Book(s) entered so far: " + booksList.size());
    			for (int i = 0; i < booksList.size(); ++i) {
    				System.out.println((i + 1) + ". " + booksList.get(i));
    			}
    
    			LibrarySessionBeanRemote libraryBean1 = (LibrarySessionBeanRemote) ctx
    					.lookup("ejb:EJBTutorial/EJBTutorialEJB//LibrarySessionBean!"
    							+ viewClassName);
    			List<String> booksList1 = libraryBean1.getBooks();
    			System.out.println("***Using second lookup to get library stateless object***");
    			System.out.println("Book(s) entered so far: " + booksList1.size());
    			for (int i = 0; i < booksList1.size(); ++i) {
    				System.out.println((i + 1) + ". " + booksList1.get(i));
    			}
    		} catch (Exception e) {
    			System.out.println(e.getMessage());
    			e.printStackTrace();
    		} finally {
    			try {
    				if (brConsoleReader != null) {
    					brConsoleReader.close();
    				}
    				ctx.close();
    			} catch (IOException | NamingException ex) {
    				System.out.println(ex.getMessage());
    			}
    		}
    
    	}
    
    }

  4. #4
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    Euh nan là désolé... Pas trop de connaissances jboss...

    Google?
    Débuggeur aussi, pour voir un peu pas où ça passe dans le source... des fois, on voit des choses qui peuvent aider...
    "Le plug gros problème des citations trouvées sur internet, c'est qu'on ne peut jamais garantir leur authenticité"

    Confucius, 448 av. J-C

  5. #5
    Membre actif
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    728
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 728
    Points : 250
    Points
    250
    Par défaut
    Re-bonjour Pill_S,

    comment puis-je déplacer ce message dans le forum jboss ?

Discussions similaires

  1. Réponses: 6
    Dernier message: 05/11/2014, 11h23
  2. java.utils.Properties avec Expression Language
    Par pilate dans le forum Collection et Stream
    Réponses: 16
    Dernier message: 24/01/2010, 21h48
  3. [C#] #ziplib ou J# (java.util.zip) pour ZIPper?
    Par SErhio dans le forum Windows Forms
    Réponses: 10
    Dernier message: 11/02/2005, 15h46
  4. [PROPERTIES] Bug dans java.util.Properties ?
    Par mathieu dans le forum Collection et Stream
    Réponses: 6
    Dernier message: 28/04/2004, 15h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo