Hi,
I'm new to java programming. I need a help about implementing OSGI module and EJB. I wrote this simple OSGI bundle:

package com.cryptoLib;
 
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
public class cryptoSha {
 
    public cryptoSha() {
    }   
 
        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 < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
                }              
               return sb.toString();
           }
 
 
}

This is the Activator class:

package com.CL_24;
 
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.cryptoLib.cryptoSha;
import org.osgi.framework.ServiceRegistration;
 
public class Activator implements BundleActivator {
    private ServiceRegistration reg;
 
    public void start(BundleContext context) throws Exception {
        cryptoSha ois = new cryptoSha();
        reg = context.registerService(cryptoSha.class.getName(), ois, null);
        System.out.println("Module CL_24 is Loaded");       
 
    }
 
    public void stop(BundleContext context) throws Exception {
        reg.unregister();
        System.out.println("Module CL_24 is Unloaded");
    }
 
}


This is the code which calls the OSGI bundle:

package com.SR_57;
import com.CL_24.*;
import com.cryptoLib.*;
........
 
 
@Named("loginController")
@SessionScoped
public class userCheck implements Serializable {
    private String user = null;
    private String password = null;  
 
       public userCheck(){
       }
 
       @Resource
       BundleContext context;
       ClassLoader classLoader = cryptoSha.class.getClassLoader();
       Bundle bundle = ((BundleReference) classLoader).getBundle();
       BundleContext load = bundle.getBundleContext();
 
 
....
}

The idea is to create a login form which calls OSGI bundle and plain password string is passed to the bundle. The bundle takes the string and converts it to SHA-256 encrypted string. Then the encrypted string is returned to the login bean. I know that it's not a good idea to work on something that you don't know but this is a part of a open source project and this part nobody wants to do it. I donate my free time for this project.

I use JBoss 7.1.0 for application server and Netbeans 7.1. This is the error stack:

com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.SR_57.userCheck.
	at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:193)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
	at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
	at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
	at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
	at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
	at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
	at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:151)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
	at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897)
	at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626)
	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2033)
	at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassCastException: org.jboss.modules.ModuleClassLoader cannot be cast to org.osgi.framework.BundleReference
	at com.SR_57.userCheck.<init>(userCheck.java:57)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
	at java.lang.Class.newInstance0(Class.java:372)
	at java.lang.Class.newInstance(Class.java:325)
	at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188)
	... 42 more

I will be glad if someone assist me for the OSGI code.
Write me if you have any questions.

best wishes
Peter