Open URL in EJB


EJB design: Open URL in EJB

  1. Open URL in EJB (1 messages)

    I have a Stateful Session Bean called MessageManagerBean. This has a method called addMessage which adds a new message to the database.

    What I want to do is each time a new message is added to the database call a URL which physically sends the message via a seperate server. This URL returns a line of text indicating success or error.

    Now in PHP this is quite straightforward:
    $status = file($url);

    What I'm wondering is how to do this in my Stateful Session Bean or is this possible at all?

    Any help greatly appreciated. Ii have tried numerous solutions over the last two days, all of which were complex and didn't work.
  2. Open URL in EJB[ Go to top ]

    One way of doing in Java is to create an URL object and read the content using IO classes. I think this sample might help you.

    String urlString = "";

    try {
       URL url = new URL(urlString);
       BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
       String inputLine;

       while ((inputLine = in.readLine()) != null) {

    } catch (IOException e1) {
        // TODO Auto-generated catch block