Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6930621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:28:15+00:00 2026-05-27T11:28:15+00:00

I have a large web project in Java EE 6 so far everything is

  • 0

I have a large web project in Java EE 6 so far everything is working great.

Now I’m adding a new class that takes twitter information and returns a string. So far the strings have been extracted from the JSON file from twitter and are ready to be persisted in my database. My problem is I’m not sure how to pass information from the EJB that normally handles all of my database calls. I’m using JPA and have a DAO class that managers all database access. I already have a method there for updateDatabase(String). I’d like to be able to call updateDatabase(String) from the class that has the strings to add but I don’t know if it’s good form to instantiate a stateless bean like that. Normally you inject beans and then call just their class name to access their methods. I could also maybe try and reference the twitter string generating class from inside of the EJB but then I’d have to instantiate it there and mess with main() method calls for execution. I’m not really sure how to do this. Right now my Twitter consuming class is just a POJO with a main method. For some reason some of the library methods did not work outside of main in face IOUtils() API directly says “Instances should NOT be constructed in standard programming”.

So on a higher level bottom line, I’m just asking how POJO’s are normally “mixed” into a Java EE project where most of your classes are EJBs and servlets.

Edit: the above seems confusing to me after rereading so I’ll try to simplify it. basically I have a class with a main method. I’d like to call my EJB class that handles database access and call it’s updateDatabase(String) method and just pass in the string. How should I do this?

Edit: So it looks like a JNDI lookup and subsequence reference is the preferred way to do this rather than instantiating the EJB directly?

Edit: these classes are all in the same web project. In the same package. I could inject one or convert the POJO to an EJB. However the POJO does have a main method and some of the library files do not like to be instantiated so running it in main seems like the best option.

My main code:

public class Driver {

    @EJB
    static RSSbean rssbean;   

    public static void main(String[] args) throws Exception {

        System.setProperty("http.proxyHost", "proxya..com");
        System.setProperty("http.proxyPort", "8080");
        /////////////auth code///////////////auth code/////////////////
        String username = System.getProperty("proxy.authentication.username");
        String password = System.getProperty("proxy.authentication.password");
        if (username == null) {
            Authenticator.setDefault(new ProxyAuthenticator("", ""));
        }
        ///////////////end auth code/////////////////////////////////end

        URL twitterSource = new URL("http://search.twitter.com/search.json?q=google");
        ByteArrayOutputStream urlOutputStream = new ByteArrayOutputStream();

        IOUtils.copy(twitterSource.openStream(), urlOutputStream);
        String urlContents = urlOutputStream.toString();
        JSONObject thisobject = new JSONObject(urlContents);
        JSONArray names = thisobject.names();
        JSONArray asArray = thisobject.toJSONArray(names);
        JSONArray resultsArray = thisobject.getJSONArray("results");
        JSONObject(urlContents.substring(urlContents.indexOf('s')));                
        JSONObject jsonObject = resultsArray.getJSONObject(0);

        String twitterText = jsonObject.getString("text");          
        rssbean.updateDatabase("twitterText"); 
    }
}  

I’m also getting a java.lang.NullPointerException somewhere around rssbean.updateDatabase("twitterText");

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:28:16+00:00Added an answer on May 27, 2026 at 11:28 am

    Use the POJO as a stateless EJB, there’s nothing wrong with that approach.

    From the wikipedia: EJB is a server-side model that encapsulates the business logic of an application.

    Your POJO class consumes a web service, so it performs a business logic for you.

    EDIT > Upon reading your comment, are you trying to access an EJB from outside of the Java EE container? Because if not, then you can inject your EJB into another EJB (they HAVE to be Stateless, both of them)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application project that works with a quite large database (over
I have a large Java Web Application project using Maven and I need to
I'm working on a Java web project that uses Maven to build its artifacts.
I'm working on a large web project based on LAMP stack. I have to
I have a large non-Java EE, JSF-based web app project. Our system is layered
I have a large web project that uses log4j directly, together with many 3rd-party
We have a large scale Java web application project. I am considering integrating some
I have a large vb.net web project that I am trying to updgrade to
I have created a Java Web project with just one class. If I compile
I have a large project in Vb.net which drives a web browser control around.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.