Hi, Dark Cloud

Wish You Happy New Year
&
Sorry for late replying your thanks, actually I am busy in my engineering exam.

I have tried the singleton pattern given by you, but still i am
getting some problems and errors.
======================================================================
MyServiceWrapper.java file looks like:
======================================================================

package misc;
import java.io.IOException;
import org.smslib.GatewayException;
import org.smslib.SMSLibException;
import org.smslib.Service;
import org.smslib.TimeoutException;
import org.smslib.AGateway.Protocols;
import org.smslib.modem.SerialModemGateway;
public class MyServiceWrapper
{
        private Service service;
        private  static MyServiceWrapper instance;
        @SuppressWarnings("unchecked")
        private MyServiceWrapper()  throws TimeoutException,
GatewayException, SMSLibException, IOException, InterruptedException
    {
                super();
                Service service = new Service();
                SerialModemGateway gateway = new 
SerialModemGateway("modem.com1",
"COM23", 57600, "Samsung", "Guru E1410");
                //SerialModemGateway gateway = new 
SerialModemGateway("modem.com1",
"COM9", 57600, "Nokia", "3220");
                gateway.setProtocol(Protocols.PDU);
                gateway.setInbound(true);
                gateway.setOutbound(true);
                gateway.setSimPin("0000");
                service.addGateway(gateway);
                service.startService();
                System.out.println("SMSLib Gateway ID: "+gateway.toString());
                Enum e=service.getServiceStatus();
                System.out.println("SMSLib Service Status: "+e.toString());
        }
        public Service getService()
    {
         System.out.println("Service ID : "+this.service);
        return this.service;
    }
    public static MyServiceWrapper getInstance() throws Exception
        {
                if (instance == null) {
                        synchronized(MyServiceWrapper.class){
                                instance = new MyServiceWrapper();
                                System.out.print("Instance : "+instance);
                    System.out.println();               
                        }
        }
                else
                {
                          System.out.println();
                          System.out.print("Instance : "+instance);
                }
                return instance;
         }
    public static void main(String args[]) throws Exception
    {
        MyServiceWrapper sw = MyServiceWrapper.getInstance();
                Service service = sw.getService();
                System.out.println("Service Wrapper : "+sw);    
                System.out.println("Service ID : "+service);
    }
}

======================================================================
======================================================================
SendMessage.jsp file looks like:
======================================================================
<%...@page
        language="java"
        contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"
        import="misc.MyServiceWrapper,
                                   org.smslib.OutboundMessage,
                                   org.smslib.Service"
%>
<%
        MyServiceWrapper sw1 = MyServiceWrapper.getInstance();
        Service service = sw1.getService();
        OutboundMessage msg = new OutboundMessage("12345", "HELP");
        try{
        service.sendMessage(msg);
        }
        catch(Exception e)
        {
                out.print(e.getMessage())       ;
        }
        out.print(msg);
%>
======================================================================

Now when i run MyServiceWrapper.java file explicitely
the getService() method is returning null and the console is
displaying the following output:

======================================================================

og4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
SMSLib Gateway ID: org.smslib.modem.serialmodemgate...@1d0c1d0c
SMSLib Service Status: STARTED
Instance : misc.myservicewrap...@4d574d57
Service ID : null
Service Wrapper : misc.myservicewrap...@4d574d57
Service ID : null

======================================================================
as the service is started an instance of wrapper is created but ,
Because of these error i am getting  NullPointerException and
NoSuchPortException while publishing SendMessage.jsp file on the
server

I am using IBM WebSphere Application Server 7.0 and Rational
Application Developer tool on Windows 7.

Please help me...


On 12/16/09, dark cloud <[email protected]> wrote:
> You can try Singleton design for ServiceWrapper class,
>
> here is very generic example, and no where near complete solution.
>
> public class ServiceWrapper
> {
>     private Service service;
>     private static ServiceWrapper instance;//holding its own STATIC instance
>
>     //you might need to add synchronized,
>    public static ServiceWrapper getInstance() throws Exception
>     {
>
>         if (instance == null) {
>             instance = new ServiceWrapper ();
>             return instance;
>         } else
>             return instance;
>
>     }
>
>
>    private ServiceWrapper()
>    {
>
>         Service service = new Service();
>
>         //do service set up, adding gateways etc.. or something here
>
>         service.startService();
>
>
>     }
>     public Service getService()
>     {
>              return this.service;
>     }
> }
>
>
> //how to use
>
> ServiceWrapper sw = ServiceWrapper.getInstance();  //first time create and
> start the service
> Service service = sw.getService();//get the service which is already started
>
>
>
> //another time
> ServiceWrapper sw2 = ServiceWrapper.getInstance();  // second time, it wont
> create a new Service again
> Service service2 = sw2.getService()// get the same old service that is
> created previously.
>
>
>
> So, that way the service is only created once for the first time, after that
> the ServiceWrapper will return its old instance everytime you call the
> getInstance() method.
>
>
> Oh yah,, dont forget to ask our master google :P. try searching for java
> Singleton, Thread safe etc..
>
> good luck
>
>
> On Wed, Dec 16, 2009 at 1:57 AM, Vikas Patidar <
> [email protected]> wrote:
>
>> Hi, Dark Cloud
>>
>> first of all thank you very much.
>>
>> Second,
>> Now i have changed my mobile from "Nokia 3220" to "Samsung Guru
>> GT-E1410" and I have tested it on both of my "Windows 7" and "Linux
>> Mint 8 Helena" with the both "Java Comm 3" and "RxTx" Libraries using
>> Bluetooth Interface "/dev/rfcomm0" port in linux and "COM17" on
>> windows
>> and now everything working fine.
>> I have tested both the ReadMessages.java and SendMessage.java files in
>> my java project and everything works fine.
>>
>> Also i have added all the jar's in my "WebContent/web-inf/lib" directory
>> But i don't understand how to create the Service instance using
>> wrapper class and calling it in jsp using factory style (getInstance()
>> ) method.
>>
>> Please explain me more detail, and If you have some code snippets then
>> please post me..
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Thanks and Regards:
>>
>> Vikas Patidar
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Known is Drop & Unknown is Ocean.
>>
>> On 12/14/09, dark cloud <[email protected]> wrote:
>> > Did you check the compatibility with the phone you are using?
>> >
>> > You might need to put the comm libraries jars in your app server
>> classpath
>> > (???) such as wen-inf/lib ??? not sure about that
>> >
>> > jsp and servlets are basically the same they are loaded and run
>> > everytime
>> > the user request.
>> >
>> > In my case, I have separate application running in the background with
>> > embedded custom j2ee web server, very similar to SMSServer example (but
>> not
>> > quite).
>> >
>> >
>> > but here is the easy way,
>> >
>> > you may need to wrapper class to wrap the Service.
>> > let the wrapper run at server start up. (you can use singleton or
>> whatever
>> > to make sure you dont recreate the service instance again and again)
>> > call factory style (getInstance() )  methods from your servlets or jsp.
>> but
>> > do not create the service instance on your jsp or servlet. (i.e no new
>> > Service() ) on the jsp.
>> >
>> > goodluck
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > I have tested COM Port and it is working fine at the "COM27" with my
>> >> "Nokia 3220" handset.
>> >> But the problem is still same.
>> >> It may be occoure because of running service instance again and again.
>> >>
>> >> However I appreciate with you that putting "Service" instance on jsp
>> >> in not good, but  should I use it with java bean  or servlet ?.
>> >>
>> >> And anyway you have run it once thought application, so let me know in
>> >> detail how can i start
>> >> the Service only once in my application, as I am is newbie to j2ee.
>> >> Plz reply soon........
>> >>
>> >> Thanks and Regards
>> >>
>> >> Vikas Patidar
>> >>
>> >>
>> >> On 12/12/09, dark cloud <[email protected]> wrote:
>> >> > First of all, I am no where near smslib expert, but it looks like you
>> >> have
>> >> > the comport problem or comm driver that I had before (misplacing jar
>> >> files)
>> >> > , check the hardware and see what com port it is attached to. If it
>> does
>> >> not
>> >> > work, you will need to reconfigure the comm library for the system.
>> >> >
>> >> > Second, I am also using smslib in my j2ee project. I believe putting
>> >> Service
>> >> > instance on the jsp is not the best option to use smslib, because it
>> >> > will
>> >> > invoke Service,( which takes several seconds to start )  everytime
>> >> > you
>> >> load
>> >> > the servlet/jsp (???) . I think it should run only once throughout
>> >> > the
>> >> > application by design. In my case, it starts only once, when I start
>> the
>> >> > application.  If you have any tips using j2ee and smslib share me
>> >> > please.
>> >> >
>> >> >
>> >> > check http://smslib.org/doc/installation/ for installing comm drivers
>> >> for
>> >> > java including windows and linux.
>> >> >
>> >> > Merry X mass and Good luck.
>> >> >
>> >> >
>> >> > Cheers
>> >> > Nick
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > On Fri, Dec 11, 2009 at 10:48 PM, Vikas Patidar <
>> >> > [email protected]> wrote:
>> >> >
>> >> >> Hi,
>> >> >> I am using smslib in my project and I have properly configured the
>> >> >> whole
>> >> >> project in IBM Rational Application Developer 7.5. Also I am
>> >> >> successfully
>> >> >> able to run ReadMessages.java and SendMessage.java in my JAVA
>> project,
>> >> >> but
>> >> >> I want to Send and Read  SMS in a Dynamic Web Project using JSP or
>> >> >> Servlets. For
>> >> >> this i have written a simple ReadMessage.jsp file like:
>> >> >>
>> >> >> =====================================================================
>> >> >> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
>> >> >>    pageEncoding="ISO-8859-1"
>> >> >>    import = "java.util.*,
>> >> >>                                 org.smslib.*,
>> >> >>                                 org.smslib.AGateway.Protocols,
>> >> >>
>> >> org.smslib.InboundMessage.MessageClasses,
>> >> >>                                 org.smslib.modem.SerialModemGateway"
>> %>
>> >> >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>> >> >> "http://www.w3.org/TR/html4/loose.dtd";>
>> >> >> <html>
>> >> >> <head>
>> >> >> <meta http-equiv="Content-Type" content="text/html;
>> >> >> charset=ISO-8859-1">
>> >> >> <title>Read Messages from phone Using SMSLib !</title>
>> >> >> </head>
>> >> >> <body>
>> >> >> <%
>> >> >>                Service srv = new Service();
>> >> >>                InboundMessage message;
>> >> >>                List<InboundMessage> msgList;
>> >> >>                try
>> >> >>                {
>> >> >>                        SerialModemGateway gateway = new
>> >> >> SerialModemGateway("modem.com27",
>> >> >> "COM27", 57600, "Nokia", "3220");
>> >> >>                        gateway.setProtocol(Protocols.PDU);
>> >> >>                        gateway.setSimPin("0000");
>> >> >>                        srv.addGateway(gateway);
>> >> >>                        srv.startService();
>> >> >>                        msgList = new ArrayList<InboundMessage>();
>> >> >>                        srv.readMessages(msgList,
>> >> >> MessageClasses.ALL);
>> >> >>                        for (int i = 0; i < 1; i++)
>> >> >>                        {
>> >> >>                                        message = msgList.get(i);
>> >> >>                                        String msgTxt =
>> >> message.getText();
>> >> >>                                        out.print(msgTxt);
>> >> >>                        }
>> >> >>                }
>> >> >>                catch (Exception e)
>> >> >>                {
>> >> >>                        e.printStackTrace();
>> >> >>                }
>> >> >>                finally
>> >> >>                {
>> >> >>                        srv.stopService();
>> >> >>                }
>> >> >>  %>
>> >> >> </body>
>> >> >> </html>
>> >> >> =====================================================================
>> >> >> When i  have publish the file ReadMessage.jsp to the server first
>> time
>> >> >> it works fine and reads first message but when i have publish this
>> >> >> file again to the server it is displaying the following error:
>> >> >> =====================================================================
>> >> >>
>> >> >> [12/11/09 23:55:39:732 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo SMSLib: A Java API library for
>> >> >> sending and
>> >> >> receiving SMS via a GSM modem or other supported gateways.
>> >> >> This software is distributed under the terms of the Apache v2.0
>> >> >> License.
>> >> >> Web Site: http://smslib.org
>> >> >> [12/11/09 23:55:39:732 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo Version: 3.4.3
>> >> >> [12/11/09 23:55:39:748 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo JRE Version: 1.6.0
>> >> >> [12/11/09 23:55:39:748 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo JRE Impl Version: 2.4
>> >> >> [12/11/09 23:55:39:748 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo O/S: Windows Vista / x86 / 6.1
>> >> >> build
>> >> >> 7600
>> >> >> [12/11/09 23:55:39:748 IST] 00000107 smslib        I
>> >> >> org.smslib.helper.Logger logInfo GTW: modem.com27: Starting gateway,
>> >> >> using
>> >> >> Generic AT Handler.
>> >> >> [12/11/09 23:55:39:748 IST] 00000107 smslib        I
>> >> >> org.smslib.helper.Logger logInfo GTW: modem.com27: Opening: COM27
>> >> >> @57600
>> >> >> [12/11/09 23:55:40:748 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo GTW: modem.com27: Stopping
>> gateway...
>> >> >> [12/11/09 23:55:40:748 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo GTW: modem.com27: Closing: COM27
>> >> >> @57600
>> >> >> [12/11/09 23:55:40:748 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo GTW: modem.com27: Gateway stopped.
>> >> >> [12/11/09 23:55:41:154 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo GTW: modem.com27: Stopping
>> gateway...
>> >> >> [12/11/09 23:55:41:154 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo GTW: modem.com27: Closing: COM27
>> >> >> @57600
>> >> >> [12/11/09 23:55:41:154 IST] 000000f4 smslib        I
>> >> >> org.smslib.helper.Logger logInfo GTW: modem.com27: Gateway stopped.
>> >> >> [12/11/09 23:55:41:154 IST] 000000f4 SystemErr     R
>> >> >> org.smslib.GatewayException: Comm library exception:
>> >> >> java.lang.RuntimeException: javax.comm.NoSuchPortException
>> >> >> [12/11/09 23:55:41:154 IST] 000000f4 SystemErr     R    at
>> >> >>
>> org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:
>> >> >> 96)
>> >> >> [12/11/09 23:55:41:154 IST] 000000f4 SystemErr     R    at
>> >> >> org.smslib.modem.AModemDriver.connect(AModemDriver.java:111)
>> >> >> [12/11/09 23:55:41:154 IST] 000000f4 SystemErr     R    at
>> >> >> org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:185)
>> >> >> [12/11/09 23:55:41:154 IST] 000000f4 SystemErr     R    at
>> >> >> org.smslib.Service$1Starter.run(Service.java:257)
>> >> >>
>> >> >> ====================================================================
>> >> >> If anyone is working with J2EE then please reply me.
>> >> >> Thanks and regards,
>> >> >> Vikas Patidar
>> >> >>
>> >> >> --
>> >> >>
>> >> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> >> "SMSLib for Java User Group" group.
>> >> >> To post to this group, send email to [email protected].
>> >> >> To unsubscribe from this group, send email to
>> >> >> [email protected]<smslib%[email protected]>
>> <smslib%[email protected]<smslib%[email protected]>
>> >
>> >> <smslib%[email protected]<smslib%[email protected]>
>> <smslib%[email protected]<smslib%[email protected]>
>> >
>> >> >
>> >> >> .
>> >> >> For more options, visit this group at
>> >> >> http://groups.google.com/group/smslib?hl=en.
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> > --
>> >> >
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "SMSLib for Java User Group" group.
>> >> > To post to this group, send email to [email protected].
>> >> > To unsubscribe from this group, send email to
>> >> > [email protected]<smslib%[email protected]>
>> <smslib%[email protected]<smslib%[email protected]>
>> >
>> >> .
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/smslib?hl=en.
>> >> >
>> >> >
>> >> >
>> >>
>> >> --
>> >>
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "SMSLib for Java User Group" group.
>> >> To post to this group, send email to [email protected].
>> >> To unsubscribe from this group, send email to
>> >> [email protected]<smslib%[email protected]>
>> <smslib%[email protected]<smslib%[email protected]>
>> >
>> >> .
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/smslib?hl=en.
>> >>
>> >>
>> >>
>> >
>> > --
>> >
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "SMSLib for Java User Group" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected]<smslib%[email protected]>
>> .
>> > For more options, visit this group at
>> > http://groups.google.com/group/smslib?hl=en.
>> >
>> >
>> >
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "SMSLib for Java User Group" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<smslib%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/smslib?hl=en.
>>
>>
>>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "SMSLib for Java User Group" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/smslib?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"SMSLib for Java User Group" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/smslib?hl=en.


Reply via email to