How to convert old Java Servlets to OSGi "Servlet" Bundles

Hello I'm looking for some help/insight on the best way to convert some of our old Java Servlet code into new OSGi Bundles that can be accessed as servlets.  I'd like to be able to install the new bundles then access them on one of our CQ instance using something like "/servlet/servlet_name".
So far I've been able to create a new bundle, and install it into CQ but I haven't been able to access the bundle at the servlet mapping URL that I would expect.  So far what I've found online has lead me to believe that I need to use the Felix Annotations to describe my servlet.
@Component(immediate = true, metatype = true, label = "Servlet Name")
@Service
@Properties({
    @Property(name = Constants.SERVICE_DESCRIPTION, value = "Servlet Name"),
    @Property(name = "sling.servlet.methods", value={"GET"}),
    @Property(name = "sling.servlet.paths", value = "/servlet/my_servlet_mapping"),
    @Property(name = Constants.SERVICE_VENDOR, value = "VendorName")
public class TellAFriend extends HttpServlet {...
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
Once I have this installed, and running without an error in the logs for CQ I tried to go on my local instance to http://localhost:4502/servlet/my_servlet_mapping but I only get 404 Resource Not Found errors.  I've even gone to the Sling Resource Resolver and it doesn't resolve to anything either.
Is there more than the Servlet Information need into the Annotations to convert "old" code into a new OSGi Servlet Mapped Bundle?

I must be missing something else configuration wise since I created a new Servlet basically using the code you provided above.  I deployed it as part of the bundle that I'm trying to create.
The bundle installs and stars fine but I still can't access the servlet.  Are there CRXDE based configurations that are requried too to configure Servlets. 
Here's my test servlet file.  I tried going to http://localhost:4502/servlet/TestCQServlet and just get the same 404 error I'm getting for the other 2 Servlets Java classes in my Bundle.
import java.io.IOException;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
@SlingServlet(paths = "/servlet/TestCQServlet", methods = "GET")
public class TestCQServlet extends SlingSafeMethodsServlet {
    // @Reference
    // private Repository repository;
    private static final long serialVersionUID = 6239754936223276983L;
    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Content-Type", "application/json");
        response.getWriter().print("whatever");

Similar Messages

  • How to convert from java.lang.Integer to int

    Could you please show me
    how to convert from java.lang.Integer to int?
    and how to convert from java.lang.Integer to String?
    Thanks,
    Minh

    Could you please show me
    how to convert from java.lang.Integer to int?
    and how to convert from java.lang.Integer to String?Tip: always keep a browser open on the API docs; if you've got a
    couple of MBs to spare, download the docs; it's very convenient.
    kind regards,
    Jos

  • How to convert a Java Program into a Service?

    Hello Experts,
    We want to convert a java program into a Service (not WebService).
    then we want to consume this service through SAP PI.
    Can any1 please give details as to how can we convert a java program into a service.
    Thanks in advance,
    ~ Suraj

    Hi Suraj,
    Unfortunately this information is still not enough. Probably I cannot understand right what you are trying to do.
    To work with tables and databases SAP uses several specifications, for example JPA API, Java Dictionary and so on. But I am not sure if this is what you need.
    Best regards,
    Ekaterina

  • How to convert these java codes (for a feedback) to javabean?

    Can anyone please help me to convert these java codes (for feedback) to javabean using the MVC Model-View-Controller pattern design?
    <%
    //instantiate variables
    Connection con = null;
    Statement stmt = null;
    Statement stmt2 = null;
    ResultSet rs = null;
    String queryString;
    int newInBoxMsg = 0;
    int newSentMsg = 0;
    int newSavedMsg = 0;
    int newTrashCanMsg = 0;
    String currentUserID = 1+"";
    String adminID = 1+""; //change this ID to your adminID in the db
    try
    //Load the JDBC driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    //Get the connection getConnection("access driver", "userID", "password")
    con = DriverManager.getConnection("jdbc:odbc:FREN_DB","","");
    stmt = con.createStatement();
    //sql statements: create, update, query
    Calendar cl = Calendar.getInstance();
    %>
    <%
    if(request.getMethod()=="POST"){
                   int y = stmt.executeUpdate("INSERT into Feedback(`whom`, `msg`, `date`)"
                   +" values ('"+currentUserID+"', '"+request.getParameter("date")+"', '"
                   request.getParameter("msg")"')");
                   int x = stmt.executeUpdate("INSERT into MailBox(`whom`, `who`, `mailheader`, `mailbody`, `date`)"
                   +" values ('"+adminID+"', '"+currentUserID+"', 'Feedback', 'We have received your feedback and we will respond to you as soon as possible', '"+request.getParameter("date")+"')");
                   out.println("Feedback Sent!");
    else {
    %>
    <form name="compose" method="POST" action="Feedback.jsp">
    <input name="date" type="hidden" value="<% out.println(cl.get(cl.DAY_OF_MONTH)+"/"+cl.get(cl.MONTH)+"/"+cl.get(cl.YEAR)); %>" maxlength="20">
    <p>Your Feedback</p>
    <p>
    <textarea name="msg" cols="50" rows="10"></textarea>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    <%
    }catch(Exception e) {
    System.out.println(e);
    %>

    Okay, first suggestion is to never create database connections in JSP/Servlet. SInce you mentioned MVC, JSP is the View, and a servlet can be the controller to process requests and redirect accordingly.
    This piece of code should be in a class invoked from the model layer (business logic components) preferably with some abstraction. Maybe you should search around for DAO pattern. That might give you an idea.

  • How to convert old Macwrite files in 10.6.8

    Years ago, users published suggestions on the Apple forums for converting MacWrite, MacWrite II and MacWrite Pro files to RTF or Word formats, but none of these suggestions seem to work anymore.  MacLinkPlus is no longer supported by its developer, and the latest version dropped support for early Mac programs anyway. Other solutions (early ClarisWorks, AppleWords, Word) only run in Classic so don't work on new Macs running 10.6
    I have been able to open these files one at a time through a OS9 emulation program SheepSaver, running the original MacWrite software, but this is very slow and tedious. 
    Does anyone know of a program that will do this conversion in batch, a program which works in OS 10.6?  There must be thousands of people with old files who would want to update them.  I couldn't find anything in the AppStore or anywhere else.

    It seems to me that you can access your files (under SheepShaver), but what you want is a batch conversion from MacWrite to something else. (This an instructive problem. Two decades ago, MacWrite was the de facto WP standard on the Mac, but nowadays we can't find a conversion utility for it. Look around in your Documents folder and ask yourself, how many of my important files will I be able to read twenty years from now.)
    I have two suggestions.
    (1) This is a bit ironic, but MacText, a rather pricy current Windoze app, claims to read and convert MacWrite files.
    (2) Or try a forum of users of 'classic' Macs (eg, Low End Macs). You could ask someone to send you an old copy of MacLink Plus, which you may be able to run under SheepShaver, or Basilisk II, or mini vMac. Alternatively (if the nature and quantity of your MacWrite docs allow), you could ask someone with the right hardware/software to do the conversion for you. Those old files can't be very big, but if they're too much for email, you can always use a service like MediaFire. Remember that, to transfer 'classic' Mac files safely, it's best first to archive them with StuffIt (.sit) and then BinHex them (.hqx).

  • How to compile a java servlet in netbeans

    heyall, just placed the following java code in my src folder in my web app folder in netbeans, anyone tell me how to compile this now? it asks me for a main but not sure exactly what to put
    package org.mypackage.chapter1;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ServletOne extends HttpServlet {
      /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
       * @param request servlet request
       * @param response servlet response
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        /* TODO output your page here */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ServletOne</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ServletOne at " + request.getContextPath () + "</h1>");
            out.println("Date is: "+ new java.util.Date());
            out.println("</body>");
            out.println("</html>");
        out.close();
      // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
      /** Handles the HTTP <code>GET</code> method.
       * @param request servlet request
       * @param response servlet response
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
        processRequest(request, response);
      /** Handles the HTTP <code>POST</code> method.
       * @param request servlet request
       * @param response servlet response
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
        processRequest(request, response);
      /** Returns a short description of the servlet.
      public String getServletInfo() {
        return "Short description";
      // </editor-fold>
    }

    heyall, just placed the following java code in my src folder in my web app folder in netbeans, anyone tell me how to compile this now?F9
    it asks me for a main but not sure exactly what to putCompiling source files never 'asks .. for a main'. You must be trying to execute it. You can't do that outside the servlet container it is intended for
    COMPILER ERROR - package javax.servlet.http does not exist
    BUT can't even get this far yetSo try compiling it as per your tutorial. Do you understand the difference between 'compile' and 'run'?

  • Anyone know how to convert old audio files.

    I have some old audio files going back to OS 7 or OS 9.   There is no file extension.
    Kind:  Unix Executable File
    How can I convert these into something OS X will play.

    That executable file type is just OSX's way of saying it doesn't know what it is.  Unfortunately during the OS7-OS9 days Apple dropped using file extensions. As I transitioned from DOS to Mac in the late 1980s I kept on adding them to all my files because I used several computers and would take a floppy from one to the other and needed to know what kind of files I had on there.  I still have sounds from OS7 days and I know what they are because I added extensions 24 years ago.
    You might see if you can find a resource checking utility.  Resources are hidden file information about creator and type in older files.  I think I have one on this computer but I am running a G4 OSX 10.4.11 and it is Classic capable so I have all kinds of old software here that may not run on a newer computer.
    IT is conceivable VLC might play the file.  It can do all kinds of things but I don't know how good its legacy format support is.

  • How to convert old windows 98 files to pages

    This might be a very far out question that has no answer. I just found some ancient (windows 98) files on a memory stick that I would love to convert to pages. Is there a way to do that? Or a website where I can convert them (I'm probably thinking along the lines of youtube converters) or is it just tough luck - ancient hyroglyphs lost in the sands of time....
    Any help how to do it (step to step instructions required, I'm afraid) or tips of where and how to do it are much appreciated!

    I just opened a 1997 Word .doc file in LibreOffice 3.6.2 with all formatting preserved. Pages gave an import error as unsupported version of Word. Also, OpenOffice may work just as well, due to its inclusion of original StarOffice code. Both applications are free.
    Connected a 1999 external USB floppy disk reader to Mountain Lion, and without drivers, it just worked.

  • How to convert output of servlet into an image????

    hi,
    guys i know how to mail and all that stuff.
    My present situation is to capture the output of a servlet as an image
    so that i can attach it as an attach it as an attachment with the mail application to forward it (also to fix it as a background to the textarea of the compose section).
    thanks in advance.

    The output of a sevrlet can be an image in the first place.
    Do you want to render an HTML output and to capture the visual representation in an image?

  • How to convert old VHS tapes to digital

    I am hoping someone can give me an overview of what kind of equipment/software is necessary to convert VHS tapes into a digital format that could be saved in iMovie. Do I just need the right cables for the VCR or something more complicated? Thanks!

    I recommend that you download the free iMovie HD6 for those with iMovie 08 who do not have a prior version of iMovie HD6. You can get it here: http://www.apple.com/support/downloads/imovieHD6.html
    And, do this tutorial: http://www.apple.com/support/imovie/tutorial/
    It is more capable of creative editing and you have a quite a bit more control over your iMovie with it.
    +So, your method worked using just a VCR, a camcorder, and your computer? No special converters?+
    Yes, I just used the AV connectors that came with my camcorder to hook the camcorder to the VCR....which was in a combo TV/VCR unit so I could see the footage on my tv, just to make it easier. The AV connector cable has a special prong that fits into the camcorder, and those white/red/yellow prongs at the VCR end. The TV/VCR is a few years old, certainly not anything fancy or new.
    I didn't bother with a converter since I just used the camcorder.
    My computer and that VCR are not physically close enough to try to import directly, and since I wanted the digital tapes of the original footage, recording first to the miniDV tapes worked for me. Canopus makes a couple of nice converters...they are around $150-250, I think.
    Then, to connect to the computer with the camcorder you will need a 4-6 pin Firewire cable.
    +I might do it sooner or I might put it off for awhile while I practice messing around with iMovie.+
    The benefit of recording from VHS to miniDV tapes is that the tapes are digital, they store easily and the footage will not degrade before you get around to creating your iMovies and DVDs. iMovies can take up lots of drive space, so don't be thinking that you will just import them all and save them for editing later. You would need a huge amount of space for this. Most of my movies are just under 2 hours, and occupy between 25-40 GB each. A couple of my movies were well over 100-140GB!!!! Yes, that is correct. I have a couple of external drives that I use for my movies while I am creating them. I usually have about two or three that I am working on at the same time.
    +We want to put them in a digital format that will be easier to store and play and safer from eroding over time, so I guess the end format I'm looking for is DVDs.+
    Because DVDs can break/crack/warp/melt/etc, you should consider exporting your finished iMovies back to the camcorder so that you have the miniDV tapes for more permanent storage and as a backup to your DVDs.
    That is one of the big reasons that I don't use iMovie 08---it does not permit exporting back to a camcorder.
    Although I do not save my created iMovies on my computer after I have made the DVD and exported the edited movie back to tape, I do save all my iDVD projects as disk images. A disk image can be up to 4.7 GB--even my large movies were automatically compressed down when put into iDVD. The limitation in iDVD is the total length of the movie in TIME, not SIZE. I use single-layer DVDs, which can hold up to 2 hours of content. Creating disk images allows you to have an exact copy of your iDVD projects, self-contained so that you can delete the original iMovies and the original iDVD projects. You can use the disk image to burn your disks when you first create them, and any time in the future. It is a good backup for the entire DVD.
    Enjoy being creative with your movie projects! Post back with any more questions, and feel free to email me if you want.
    Regards,
    Beverly

  • How to convert old pages to new pages to see on iPhone?

    Aloha all, so does this mean that since iWork and iDisk are gone I have to use iCloud to get my stuff on my iPhone?
    How do I get the older versions of pages documents into my iCloud?
    Isn't there a conversion program to do this? Other wise whats the process to get them into 09?
    do I have to redo all my files?
    Please tell apple atleast solved this problem, its 2012 for christs' sake?

    Just open and resave them.
    Once you set up iCloud in your System Preferences, it is just another palce to save to, not much different from your desktop.
    It will pay to upgrade your system to ML. Lion was a rather bad joke on Apple's part. iCloud was not a transparent process at all in Lion.
    Peter

  • How to convert these java codes (for a mailbox) to javabean?

    Can anyone please help me to convert these codes to javabean?
    //instantiate variables
    Connection con = null;
    Statement stmt = null;
    Statement stmt2 = null;
    ResultSet rs = null;
    String queryString;
    int newInBoxMsg = 0;
    int newSentMsg = 0;
    int newSavedMsg = 0;
    int newTrashCanMsg = 0;
    String currentUserID = 1+"";
    try
    //Load the JDBC driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    //Get the connection getConnection("access driver", "userID", "password")
    con = DriverManager.getConnection("jdbc:odbc:FREN_DB","","");
    stmt = con.createStatement();
    stmt2 = con.createStatement();
    //sql statements: create, update, query
    //new msges in inbox
    rs = stmt.executeQuery("select ID from MailBox where who = \'"+currentUserID+"\' and whoRead = false");
    while (rs.next()) {
    newInBoxMsg+=1;
    //new messages in sent-items
    rs = stmt.executeQuery("select ID from MailBox where whom = \'"+currentUserID+"\' and whomread = false");
    while (rs.next()) {
    newSentMsg+=1;
    //new messages in saved items
    rs = stmt.executeQuery("select ID from MailBox where who = \'"+currentUserID+"\' and whoSave = true");
    while (rs.next()) {
    newSavedMsg+=1;
    rs = stmt.executeQuery("select ID from MailBox where who = \'"+currentUserID+"\' and whoDelete = true and whoRead = false");
    while (rs.next()) {
    newTrashCanMsg+=1;
    %>

         public class MyBean {
              public void doSomething() {
                   //          instantiate variables
                   Connection con = null;
                   Statement stmt = null;
                   Statement stmt2 = null;
                   ResultSet rs = null;
                   String queryString;
                   int newInBoxMsg = 0;
                   int newSentMsg = 0;
                   int newSavedMsg = 0;
                   int newTrashCanMsg = 0;
                   String currentUserID = 1+"";
                   try
                        //          Load the JDBC driver
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                        //          Get the connection getConnection("access driver", "userID", "password")
                        con = DriverManager.getConnection("jdbc:odbc:FREN_DB","","");
                        stmt = con.createStatement();
                        stmt2 = con.createStatement();
                        //          sql statements: create, update, query
                        //          new msges in inbox
                        rs = stmt.executeQuery("select ID from MailBox where who = \'"+currentUserID+"\' and whoRead = false");
                        while (rs.next()) {
                             newInBoxMsg+=1;
                        //          new messages in sent-items
                        rs = stmt.executeQuery("select ID from MailBox where whom = \'"+currentUserID+"\' and whomread = false");
                        while (rs.next()) {
                             newSentMsg+=1;
                        //          new messages in saved items
                        rs = stmt.executeQuery("select ID from MailBox where who = \'"+currentUserID+"\' and whoSave = true");
                        while (rs.next()) {
                             newSavedMsg+=1;
                        rs = stmt.executeQuery("select ID from MailBox where who = \'"+currentUserID+"\' and whoDelete = true and whoRead = false");
                        while (rs.next()) {
                             newTrashCanMsg+=1;
                   catch(SQLException e){
                        e.printStackTrace();
                   finally {
                        // Close resources here
              }Voila, it's a bean!

  • How to convert jar in java

    hi plz help me out ....
    how to convert a java program into an jar file .....
    if u have tools just send it to me its urgent

    c:>jar -cvfm mymanifest MyJavaFiles.class

  • How to Convert From HEX to Java Unicode

    String hexString = "81698a94816a93fa97a790bb8dec8f8a814083478393835e815b83768389834383598354815b836f8e968bc69594814083568358836583808c9f8fd8835a8393835e";
    I have an hex string as shown above. Could please some one tell me how to convert to java unicode.

    Divide it into four-character pieces and for each piece to this:char c = (char)Integer.parseInt(thePiece, 16);That converts the four-character piece (e.g. "8a94") to the corresponding Unicode character (\u8a94). String those chars together into a char array or a String or whatever you need.

  • [b]How to convert a Socket object in a C socket file descriptor[/b]

    Hi all,
    I need to make a getsockopt() call using JNI, but I don't know how to convert a Java Socket object in the integer corresponding to the socket file descriptor.
    Thank you in advance!
    Fernando

    I was wrong in my previous post. FileDescriptor is used for PlainSocketImpl. This means I can give you a solution.
    The solution does involve rebuilding some built-in Java classes to make certain fields accessible.
    You have to modify access to three classes:
    1. You can either use my SocketGetImpl or just rebuild java.net.Socket and change from
    SocketImpl getImpl() throws SocketException {
    to
    public SocketImpl getImpl() throws SocketException {
    2. In java.net.SocketImpl change from
    protected FileDescriptor getFileDescriptor() {
    to
    public FileDescriptor getFileDescriptor() {
    3. In java.io.FileDescriptor I would add the method
    public int getFd(){ return fd; }
    Then my test program becomes:
    package myhack;
    import java.io.*;
    import java.net.*;
    public class DoSock {
            public static void main(String args[]) throws Exception{
                    Socket s= new Socket("mywebserver",80);
                    System.out.println("s="+s);
                    SocketImpl si = SocketGetImpl.getImpl(s);
                    System.out.println("si="+si);
                    FileDescriptor fd = si.getFileDescriptor();
                    System.out.println("fd="+fd);
                    System.out.println("fd int="+fd.getFd());
    }And you still have to invoke as:
    java -Xbootclasspath/p:. myhack.DoSock
    or boot path pointing at jar file, etc.

Maybe you are looking for

  • How to generate a query involving multiple tables(one left join others)

    Hi, all, I want to query a db like these: I need all the demographics information(from table demo) and their acr info(from table acr), and their clinical info(from table clinical), and their lab info(from table lab). The db is like this: demo->acr: o

  • Calendar & File Upload Components - Threadinar6

    Hi All, This is the sixth in the "Threadinar" series , please see Threadinar5 at http://swforum.sun.com/jive/thread.jspa?threadID=99473 for details In this Threadinar we will focus on the "Calendar" and "File Upload" Components Let us begin our discu

  • How do I install AFP on my Mac?

    Seems that I loaded AFP before and had no problem, but trying to update has me stymied. if I close safari, how do I see the instructions/steps to download.  I un-installed all previous versions as instructed, then when I clicked to install it told me

  • New vision 10.9 issues on Finder can not work

    I have one MacBook Air with Finder problem from I update to 10.9 vision, the finder can not be open it, even I ise command+alt+esc to press force reatart Finder, but problem could not finish, The issues same as before at restart system, who can tell

  • How do I make my Flash player default?

    Since Yosemite was installed on my macbook pro my video player which worked perfectly has changed over to AirPlay without my knowledge. It will not play anything, no matter how many times I click the box. I have tried to reset my Flash Player to defa