title: Howto call method from OSGI bundle?
body: <p>I have written this OSGI bundle:</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package CryptoLib;
  
  import java.security.MessageDigest;
  import java.security.NoSuchAlgorithmException;
  
  public class cryptoSha {
  
      public cryptoSha() {
      }
  
      /** method for converting simple string into SHA-256 hash */
         public String stringHash(String hash) throws NoSuchAlgorithmException{
  
              MessageDigest md = MessageDigest.getInstance("SHA-256");
              md.update(hash.getBytes());
  
              byte byteData[] = md.digest();
  
              /** convert the byte to hex format */
              StringBuilder sb = new StringBuilder();
                  for (int i = 0; i &lt; byteData.length; i++) {
              sb.append(Integer.toString((byteData[i] &amp; 0xff) + 0x100, 16).substring(1));
              }              
             return sb.toString();
         }
  
  
  }
  </code></pre>
  
  <p>And this is the Acticator class:</p>
  
  <pre><code>        package com.CL_67;
  
  import CryptoLib.cryptoSha;
  import org.osgi.framework.BundleActivator;
  import org.osgi.framework.BundleContext;
  
  public class Activator implements BundleActivator {
      private static BundleContext context;   
  
      public void start(BundleContext context) throws Exception {
          Activator.context = context;
          context.registerService(cryptoSha.class.getName(), new cryptoSha(), null);
          System.out.println("Module CL-67 is Loaded ...");              
      }
  
      public void stop(BundleContext context) throws Exception {
          context.ungetService(context.getServiceReference(cryptoSha.class.getName()));
          Activator.context = null;
          System.out.println("Module CL-67 is Unloaded ...");      
      }
  
  }
  </code></pre>
  
  <p>This is the EAR package which calls the bundle:</p>
  
  <pre><code>import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import org.osgi.framework.BundleContext;
  
  @Named("loginController")
  @SessionScoped
  public class userCheck extends HttpServlet implements Serializable {
  
         public userCheck(){
         }
  
         @WebServlet(name = "CL_67", urlPatterns = {"/CL_67"})
      public class cryptoSha extends HttpServlet {
  
      @Inject
      cryptoSha stringHash;
  }
  
  
     @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
          PrintWriter out = response.getWriter();
          out.println(cryptoSha.stringHash("test"));
      }
  
     }
  }       
  </code></pre>
  
  <p>I successfully compile and deploy then on JBoss 7.1.0 but when I start the EAR package nothing happens. Can you help me to find where I'm wrong in the code?</p>
  
  <p>kind regards,
  Peter </p>
  
  <p>EDIT:
  Unfortunately I'm new to java programming and some of the code in the examples I don't understand how they work. Would you be so kind to help me with the example. I need to see how this code must be written in proper way in order to use it in future time? Would someone repair the code?</p>
  
  <p>Thank you in advance.
  Peter</p>