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

  • Home
  • SEARCH
  • 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 8449845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:49:01+00:00 2026-06-10T10:49:01+00:00

I want to implement a painting service using Java EE and JBoss Application Server.

  • 0

I want to implement a painting service using Java EE and JBoss Application Server.

Imagine a method called via an URL

http://mypaint.com/apply?image=1&action=line&from=10,10&to=100,10

which applies an action to the image with the id 1. The action is “draw a line from point (10,10) to point (100,10)”.

The “apply” method looks like this:

@Inject
private ImageProcessorServer processors

@GET
@Path("/apply")
public Response apply(
    @QueryParam(value = "image") int imageId,
    @QueryParam(value = "action") String action,
    //some parameters more...
) {
     … //check if user is allowed to access the image
     ImageProcessor processor = processors.get(imageId); 
       //get image processor by image id
     processor.apply(action/*, from, to*/);
}

The “ImageProcessorServer” looks like this:

@Singleton
@Startup
public class ImageProcessorServer {
   private Map<Integer, ImageProcessor> processors =
       new HashMap<Integer, ImageProcessor>();  
   @Lock(LockType.WRITE)
   public ImageProcessor get(int imageId) {
       ImageProcessor processor = processors.get(imageId);
       if(processor == null) {
           processor = new ImageProcessor(imageId);
           processors.put(imageId, processor);
       }
       return processor;
   }
}

It’s a singleton to make sure, that only one ImageProcessor per Image is generated (generation under mutual exclusion → Write-Lock).

Now the Problem: How can I inject my Data Access Objects (for manipulating my database) in my ImageProcessor class? DAOs are simple stateless beans. My ImageProcessor should look like this:

public class ImageProcessor {
   @Inject
   private ActionDao actionDao;
   private Image image;

   public ImageProcessor(int imageId) { … }

   public void apply(String action, ...) {
      //change image
      //actionDao.persist(actionObject)
   }
}

But this does not work. The ActionDao is NULL.

My current solution is to pass the DAOs as parameter in every method that is using DAOs, like this:

public ImageProcessor(int imageId, ImageDao dao) { … }

public void apply(String action, …, ActionDao dao, ImageDao dao2, …) {
   //change image
   //dao.persist(actionObject)
}

It is important that the requests with the same image id share the same image processor. A client can have multiple requests with different image ids.

Under this link
Using Dependency Injection in POJO's to inject EJB's
is said that one can use a factory. But I don’t know how to work this out. Can someone provide code for this?

Does someone know an elegant way to solve my problem?

  • 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-06-10T10:49:02+00:00Added an answer on June 10, 2026 at 10:49 am

    In your case you can manually lookup your bean. to do so you can add an static util method to get the bean manager :

     public static BeanManager getBeanManager()
     {
        try{
            InitialContext initialContext = new InitialContext();
            return (BeanManager) initialContext.lookup("java:comp/BeanManager");
        catch (NamingException e) {
            log.error("Couldn't get BeanManager through JNDI");
            return null;
        }
      }
    

    and then you can manually lookup your bean in singleton EJB, then all injections will happen in your bean:

     public ImageProcessor getFacade()
     {
        BeanManager bm = getBeanManager();
        Bean<ImageProcessor> bean = (Bean<ImageProcessor>) bm.getBeans(ImageProcessor.class).iterator().next();
        CreationalContext<ImageProcessor> ctx = bm.createCreationalContext(bean);
        ImageProcessor ip= (ImageProcessor) bm.getReference(bean, ImageProcessor.class, ctx); // this could be inlined, but intentionally left this way
        return ip;
     }
    

    after looking up the bean set the image id using a setter method and then put it in your map.

    Try to make a util class for manually looking for beans, then you can reuse it in whole project.

    Also Seam3, Myface CODI and DeltaSpike have some utilities to do these routine processes.

    Fore more info take a look at this sample.

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

Sidebar

Related Questions

I want to implement login using facebook in my windows phone 7.1 application When
I want to implement facebook login in my iphone application using the latest sdk
I am developing Paint application using OpenGL-ES for iPhone and i want to implement
I want to implement an application which will work as a parser. User will
I want to implement a job scheduler in my windows azure application. My aim
I want to implement the put and get-methods for a multikeymap in Java with
I have a console application that prints on standard output. I want to implement
I want implement in my software solution an VBA editor but in c# 3.0.
i starter in jqgrid, i want implement inline edit in jqgrid i have this
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement

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.