12 Replies Latest reply on Feb 8, 2008 4:06 PM by Tony Mai

    Legacy code: Integrating with existing servlet

    Tony Mai Apprentice

      Hi all,

      We have a chart library that we use to serve images for our application. To integrate with our Seam app, we wrote a simple servlet that invokes the library and return a URL of the created image. The library requires a datasource and user ID so I use dependency injection. However, during runtime, the injection objects are all null.

      Here is the code for the servlet:

      public class GetChart extends HttpServlet {
      
       @In("quoteDS")
       private ChartDatasource quoteDS;
      
       @In
       private WcLoginSession wcLoginSession;
      
       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       try {
       writeChart(request, response);
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
      
       private void writeChart(HttpServletRequest request, HttpServletResponse response) throws Exception {
       OutputStream out = response.getOutputStream();
       try {
       response.setContentType("img/png");
       ChartCriteria chartCriteria = ChartCriteria.fromRequest(request);
       if (chartCriteria != null) {
       writeChart(out, chartCriteria);
       }
       } finally {
       try {
       out.flush();
       } catch (IOException e) {
       e.printStackTrace();
       }
       out.close();
       }
       }
      
       private void writeChart(OutputStream out, ChartCriteria chartCriteria) {
       Chart chart = new Chart(wcLoginSession.getMyLoginId(), chartCriteria);
       try {
       chart.build(quoteDS, out);
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
      }
      


      Why would my injections not working? Is there a better way to do this?

      I am running Seam 2.0.0CR2 with JBoss 4.2.1GA.

      Thanks in advance for your help.