Bonjours à tous.

J'ai un problème lié au déploiement d'une petite application sur jboss application server. Je travaille avec eclipse 3.5 comme IDE et la version 5.1.0 de jboss application server où j'ai choisi la configuration "all". Il s'agit d'une application qui convertie les devises.

Le problème est que l'application marche parfaitement lorsque le client est exécuté localement c'est-à-dire sur la même machine sur laquelle est installée le serveur. Mais lorsque j'exécute le client sur une autre machine elle ne marche plus. Le server ne répond pas, même étant bien démarré.

Je doit préciser que les deux machines (serveur et client) sont les machines d'un réseau local, donc sont interconnectés.

La partie EJB3.0 comporte l'interface et la classe suivant:

Interface remote:
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
 
package converter.ejb;
 
import java.math.BigDecimal;
 
import javax.ejb.Remote;
 
/**
 * @author Arnaud
 *
 */
 
@Remote()
public interface Converter {
 
    public BigDecimal dollarToYen(BigDecimal dollars);
    public BigDecimal yenToEuro(BigDecimal yen);
    public BigDecimal euroToFrancCfa(BigDecimal euro);
}
Classe inmplémentant l'interface:
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
 
package converter.ejb;
 
import java.math.BigDecimal;
 
import javax.ejb.Stateless;
 
/**
 * @author Arnaud
 *
 */
 
@Stateless()
public class ConverterBean implements Converter {
 
    private BigDecimal yenRate = new BigDecimal("112.58");
    private BigDecimal euroRate = new BigDecimal("0.0070");
    private BigDecimal francCfaRate = new BigDecimal("655.00");
 
    public void ConverterBean() {
 
    }
 
    /* (non-Javadoc)
     * @see converter.ejb.Converter#dollarToYen(java.math.BigDecimal)
     */
    @Override
    public BigDecimal dollarToYen(BigDecimal dollars) {
        // TODO Auto-generated method stub
        BigDecimal result = dollars.multiply(yenRate);
        return result.setScale(2, BigDecimal.ROUND_UP);
    }
 
    /* (non-Javadoc)
     * @see converter.ejb.Converter#euroToFrancCfa(java.math.BigDecimal)
     */
    @Override
    public BigDecimal euroToFrancCfa(BigDecimal euro) {
        // TODO Auto-generated method stub
        BigDecimal result = euro.multiply(francCfaRate);
        return result.setScale(2, BigDecimal.ROUND_UP);
    }
 
    /* (non-Javadoc)
     * @see converter.ejb.Converter#yenToEuro(java.math.BigDecimal)
     */
    @Override
    public BigDecimal yenToEuro(BigDecimal yen) {
        // TODO Auto-generated method stub
        BigDecimal result = yen.multiply(euroRate);
        return result.setScale(2, BigDecimal.ROUND_UP);
    }
}
Cette partie a été déployée avec succès dans le server jboss.

Ensuite l'application cliente comporte les 3 classes suivantes:

classe ConverterClient.java :
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 
package converter.client;
 
import converter.ejb.*;
 
import javax.ejb.EJB;
 
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
 
 
import java.math.BigDecimal;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
 
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
 
/**
 * @author Arnaud
 *
 */
public class ConverterClient extends JFrame implements ActionListener {
 
    @EJB
    static final long serialVersionUID = 1L;
 
    private JLabel lblAmount = new JLabel("Amount : ");
    private JLabel lblFrom = new JLabel("From : ");
    private JLabel lblTo = new JLabel("To : ");
    private JLabel lblResult = new JLabel(" ???????  ");
 
    private JButton cmdResult = new JButton("Result");
    private JButton cmdReset = new JButton("Reset");
    private JButton cmdClose = new JButton("Close");
 
    private JTextField txtAmount = new JTextField();
 
    private JComboBox cmbFrom = new JComboBox();
    private JComboBox cmbTo = new JComboBox();
 
    public ConverterClient() {      // Constructeur
        super(); // Appel constructeur de la superclasse
 
        build(); // Initialisation de la fenêtre
    }
 
    private void build() {
        setTitle("Currency Converter");  // Titre de le fenêtre
        setSize(350, 260);
        setLocationRelativeTo(null); // Centre la fenêtre au milieu de l'écran
        setResizable(false); // La fenêtre sera non redimmensionable
 
        setContentPane(buildContentPane());
    }
 
    private JPanel buildContentPane() {
        JPanel fenPanel = new JPanel();
        fenPanel.setLayout(null);  // Je positionne moi même les composants
        fenPanel.setBackground(Color.white);
 
        lblAmount.setBounds(20, 50, 100, 20);
        lblFrom.setBounds(20, 90, 75, 20);
        lblTo.setBounds(175, 90, 75, 20);
        lblResult.setBounds(110, 160, 200, 20);
        lblResult.setForeground(Color.blue);
        txtAmount.setBounds(75, 50, 150, 20);
        txtAmount.setBackground(Color.cyan);
        cmdClose.setBounds(265, 206, 75, 20);
        cmdClose.setToolTipText("Close the Currency Converter Windows.");
        cmdReset.setBounds(185, 206, 75, 20);
        cmdReset.setToolTipText("Reset all fields");
        cmdResult.setBounds(20, 160, 80, 20);
        cmdResult.setToolTipText("Result");
        cmbFrom.setBounds(75, 90, 75, 20);
        cmbFrom.addItem("Euro");
        cmbFrom.addItem("Dollar");
        cmbFrom.addItem("Yen");
        cmbFrom.addItem("fr cfa");
        cmbTo.setBounds(210, 90, 75, 20);
        cmbTo.addItem("Euro");
        cmbTo.addItem("Dollar");
        cmbTo.addItem("Yen");
        cmbTo.addItem("fr cfa");
 
 
        cmdClose.addActionListener(this);
        cmdReset.addActionListener(this);
        cmdResult.addActionListener(this);
 
        fenPanel.add(lblAmount);
        fenPanel.add(lblFrom);
        fenPanel.add(lblTo);
        fenPanel.add(lblResult);
        fenPanel.add(txtAmount);
        fenPanel.add(cmdClose);
        fenPanel.add(cmdReset);
        fenPanel.add(cmdResult);
        fenPanel.add(cmbFrom);
        fenPanel.add(cmbTo);
 
        return fenPanel;
    }
 
    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
 
        if (source == cmdClose) {
            int choix = JOptionPane.showConfirmDialog(null, "Are you sure you want to close this window ?", "Currency Converter", JOptionPane.YES_NO_OPTION);
            if (choix == 0) {
                dispose();
            }
        }
        if (source == cmdResult) {
            String enterinValue = txtAmount.getText().toString();
            String selectedValue1 = cmbFrom.getSelectedItem().toString();
            String selectedValue2 = cmbTo.getSelectedItem().toString();
 
            if (enterinValue.length() == 0) {
                JOptionPane.showMessageDialog(null, "missing value to convert", "Error", JOptionPane.ERROR_MESSAGE);
            }
            else {
                BigDecimal param = new BigDecimal(enterinValue);
                try {
                    Context ctx = JBossContext.getInitialContext();
                    Converter myConverter = (Converter) ctx.lookup("ConverterBean/remote");
                    if ((selectedValue1.equals("Dollar")) & (selectedValue2.equals("Yen"))) {
                        BigDecimal amount = myConverter.dollarToYen(param);
                        lblResult.setText("$" + param + " is : " + amount + " yen.");
                    }
                    if ((selectedValue1.equals("Euro")) & (selectedValue2.equals("fr cfa"))) {
                        BigDecimal amount = myConverter.euroToFrancCfa(param);
                        lblResult.setText(param + " euro is : " + amount + " franc CFA.");
                    }
                } catch (NamingException ne) {
                    ne.printStackTrace();
                }
            }
        }
 
    }
}
classe JBossContext.java
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
 
package converter.client;
 
import java.util.Properties;
import javax.naming.*;
 
/**
 * @author Arnaud
 *
 */
public class JBossContext {
 
    public static Context getInitialContext() throws NamingException {
 
        Properties prop = new Properties();
 
        prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        prop.put(Context.PROVIDER_URL, "jnp://localhost:1099");
 
        return new InitialContext(prop);
    }
}
Et enfin la classe startClient.java :
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
 
package converter.client;
 
import javax.swing.*;
 
/**
 * @author Arnaud
 *
 */
public class startClient {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ConverterClient fen = new ConverterClient();
                fen.setVisible(true);
            }
        });
    }
}
Aidez moi SVP.

merci