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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:44:12+00:00 2026-05-27T19:44:12+00:00

I have written this OSGI bundle: /* * To change this template, choose Tools

  • 0

I have written this OSGI bundle:

/*
 * 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 < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }              
           return sb.toString();
       }


}

And this is the Acticator class:

        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 ...");      
    }

}

This is the EAR package which calls the bundle:

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"));
    }

   }
}       

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?

kind regards,
Peter

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?

Thank you in advance.
Peter

  • 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-27T19:44:12+00:00Added an answer on May 27, 2026 at 7:44 pm

    A couple of points:

    1. From the code you’ve supplied, you haven’t really set up an OSGi service in your bundle.

    2. In your servlet, you’re not actually using any OSGi facilities. Your init method tries to retrieve the bundleContext, but then you don’t ever do anything with it. Typically you’d do something like this:

      ServiceReference serviceRef =
          bundleContext.getServiceReference("myService");
      

      and then invoke against that serviceRef.

    3. Your servlet doGet is just relying on standard Java object creation:

      try {
          cryptoSha dc = new cryptoSha();
          String nhash = dc.stringHash("test");
      } catch (NoSuchAlgorithmException ex) {
          ex.printStackTrace();
      }
      

      So unless cryptoSha is somehow part of your ear or otherwise in the application classpath, I suspect you’re getting a NoClassDefFoundError here.

      But even if you create cryptoSha, you are just trying to assign a value to String nhash, but then you don’t do anything with it, so your servlet is indeed doing nothing.

    There is a knopflerfish tutorial that may help: http://www.knopflerfish.org/osgi_service_tutorial.html

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

Sidebar

Related Questions

I am new to Python and I have written this simple script: #!/usr/bin/python3 import
I have written this simple script in python: import gtk window = gtk.Window() window.set_size_request(800,
I have written this clone method for when the parent of the Employee class
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have written this code to join ArrayList elements: Can it be optimized more?
I have written this code to convert string in such format 0(532) 222 22
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,
I am learning Python for the past few days and I have written this
So I am obviously not a very good programmer. I have written this small
I have written something like this pretty easily in C# ( string GetUrl(new {

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.