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 3342176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:48:28+00:00 2026-05-18T00:48:28+00:00

In my application I have an EntryServlet which loads default data and sets up

  • 0

In my application I have an EntryServlet which loads default data and sets up the security based on the logged in user id. This servlet is using EJB’s through dependency injection. It works fine when I execute it as a normal web application but when I try to test the application using JSFUnit the ejb reference in the servlet is not injected and is null.

I need to invoke the EntryServlet before setting up the JSF session since it loads the data required in the jsf pages.
I am calling it as follows

JSFUnit test code

public class VisitingScholarNewRequestTest extends org.apache.cactus.ServletTestCase {

public static Test suite() {
   return new TestSuite( VisitingScholarNewRequestTest.class );
}



public void testSaveAsDraft() throws ServletException,IOException {
    //Calling EntryServlet
    JSFUnitEntryServlet entryServlet = new JSFUnitEntryServlet();
    request.setAttribute("netid","KS2316");
    entryServlet.doPost(request,response); -- this is giving an error.
    // Send an HTTP request for the initial page
    JSFSession jsfSession = new JSFSession("/faces/cardrequestcreate.xhtml");

    // A JSFClientSession emulates the browser and lets you test HTML
    JSFClientSession client = jsfSession.getJSFClientSession();

    // A JSFServerSession gives you access to JSF state      
    JSFServerSession server = jsfSession.getJSFServerSession();

    System.out.println("current view id :"+server.getCurrentViewID());

    // Test navigation to initial viewID
    assertEquals("/cardrequestcreate.xhtml", server.getCurrentViewID());

}

EntryServlet code

public class JSFUnitEntryServlet extends HttpServlet {
@EJB
private MasterDataLocal masterDataFacade;

public void doGet(HttpServletRequest request,
                  HttpServletResponse response) throws ServletException,
                                                       IOException {
    doPost(request,response);
}

public void doPost(HttpServletRequest request,
                   HttpServletResponse response) throws ServletException,
                                                        IOException {
    String netId = "";
    try {
        netId = (String)request.getAttribute("netid");
        //Establish the portal connection for this user
        masterDataFacade.reinstateUser(netId); -- The test is failing with a null pointer exception here.

As I mentioned earlier When I execute the application in the browser it works fine and the EJB is injected in the EntryServlet, but it is not getting injected when I run the JSFUnit test suite. For some reason the servlet is not getting executed in the container. Please help in this regard.Any help will be greatly appreciated

Regards
Kiran

  • 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-18T00:48:29+00:00Added an answer on May 18, 2026 at 12:48 am

    You’re using a new to create your servlet:

    //Calling EntryServlet
    JSFUnitEntryServlet entryServlet = new JSFUnitEntryServlet();
    

    I don’t see how injection could occur since the servlet is not managed (i.e. created by a container) here.

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

Sidebar

Related Questions

I have created a WCF Data Service and using it in a web application
In my application I have a DataGridView control that displays data for the selected
In my application I have a window which I popup with small messages on
In my current application I have a form that requires the user to enter
In my iPhone application I have a table view. When user taps any row,
We have application have been written in Silverlight using MVVM pattern. We need to
My RealEstate PHP Application have following user groups, Admins, Moderators Agents i want to
I have an game application I have written for Windows Mobile and I want
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
In my application I have TextBox in a FormView bound to a LinqDataSource like

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.