Skip to main content

Featured

Adobe Experience Manager - Create an OSGI Configuration

 In this article, let's create an OSGi configuration, configure it and use it in AEM code. So now let's get started with the creation of an OSGi configuration. Technical details and Assumptions: All the following details are tested in AEM version 6.5.8, Java version 11.0.2 Creation of OSGi configuration: To create an OSGi configuration we need to create an ObjectClassDefinition. I have included a sample OCD configuration, which can be used as a reference to create one. The next step would be to create an interface and an implementation that can help fetch the OSGi configurations.  Interface: Implementation: Let's try to use the OSGi configuration created so far in Models/Servlets. For demonstration purposes, I used AEM Models here, but the same can be implemented in Servlets too. Now that we have created the OSGi configuration. Once building the code, we should be able to see the OSGi configuration in the web console (http://localhost:4502/system/console/configMgr) C...

Implementation of Transmission Control Protocol (TCP) an Echo Program

This is a java program that echos the text sent from the client using the socket connection established using the TCP.

echos.java:

     import java.io.*;
    import java.net.*;
    class echos {
        public static void main(String args[]) throws Exception
        {
            String echoin;
            ServerSocket svrsoc;
            Socket soc;
            BufferedReader br;
            try
            {
                svrsoc = new ServerSocket(5000);
                soc = svrsoc.accept();
                br = new BufferedReader (new InputStreamReader(soc.getInputStream()));
                PrintStream ps = new PrintStream(soc.getOutputStream());
                System.out.println("Echo Initiated:");
                while((echoin=br.readLine())!=null)
                {
                    if(echoin.equals("end"))
                    {
                        System.out.println("Echoing Terminated");
                        br.close();
                        break;
                    }
                    else
                        ps.println(echoin);
                }
            }
            catch(UnknownHostException e)
            {
                System.out.println(e.toString());
            }
            catch(IOException ioe)
            {
                System.out.println(ioe);
            }
        }  
    }

echoc.java:

    import java.io.*;
    import java.net.*;
    class echoc {
    public static void main(String args[]) throws Exception   
    {
        String sockin;
        try
        {
            Socket csock = new Socket(InetAddress.getLocalHost(),5000);
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            BufferedReader br_sock = new BufferedReader(new InputStreamReader(csock.getInputStream()));
            PrintStream ps = new PrintStream(csock.getOutputStream());
            System.out.println("Start echoing...");
            while((sockin=br.readLine())!=null)
            {
                ps.println(sockin);
                if(sockin.equals("end"))
                    break;
                else
                    System.out.println("server:"+br_sock.readLine());
    
            }
        }
    catch(UnknownHostException e)
    {
        System.out.println(e.toString());
    
    }
    catch(IOException ioe)
    {
        System.out.println(ioe);
    }
    }
    }

Output:

Comments

Popular Posts