Q:

SMSlib with webservice

I'm using SMSlib for sending messages using serial gsm modem.I need to send SMSs multiple times using the same application. I ran the SMSlib example without issues and it worked fine.But when I tried to use the same code under a webservice it can only used for one time. And when trying to use for second time it gave the following error. I used a python client.
C:\Users\k4n\Desktop\web>python SendSMS.py
No handlers could be found for logger "suds.client"
Traceback (most recent call last):
File "SendSMS.py", line 16, in <module>
result = client.doIt()
File "SendSMS.py", line 8, in doIt
return self.client.service.doIt("Testing")
File "build\bdist.win32\egg\suds\client.py", line 542, in __call__

File "build\bdist.win32\egg\suds\client.py", line 602, in invoke

File "build\bdist.win32\egg\suds\client.py", line 649, in send

File "build\bdist.win32\egg\suds\client.py", line 702, in failed
File "build\bdist.win32\egg\suds\bindings\binding.py", line 265, in get_fault
suds.WebFault: Server raised fault: 'Comm library exception: java.lang.RuntimeException:
javax.comm.PortInUseException: Port currently owned by org.smslib'

This is webservice (interface)
 package com.k4n.webservice;

 import javax.jws.WebMethod;
 import javax.jws.WebService;
 import javax.jws.soap.SOAPBinding;
 import javax.jws.soap.SOAPBinding.Style;

 @WebService
 @SOAPBinding(style = Style.RPC)
 public interface GetURL{

 @WebMethod void doIt(String url) throws Exception;
}

webservice (Implement)
   package com.k4n.webservice;

   import java.io.IOException;

   import javax.jws.WebService;

   import org.smslib.AGateway;
   import org.smslib.GatewayException;
   import org.smslib.IOutboundMessageNotification;
   import org.smslib.Library;
   import org.smslib.OutboundMessage;
   import org.smslib.SMSLibException;
   import org.smslib.Service;
   import org.smslib.TimeoutException;
   import org.smslib.modem.SerialModemGateway;

   import examples.modem.SendMessage;

   @WebService(endpointInterface = "com.k4n.webservice.GetURL")
   public class GetURLImpl implements GetURL {
    public void doIt(String url) throws Exception {

    OutboundNotification outboundNotification = new OutboundNotification();
    System.out.println("Example: Send message from a serial gsm modem.");
    System.out.println(Library.getLibraryDescription());
    System.out.println("Version: " + Library.getLibraryVersion());
    SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM12", 115200, "Huawei",        "E303");
    gateway.setInbound(true);
    gateway.setOutbound(true);
    gateway.setSimPin("0000");
    gateway.setSmscNumber("+9477000003");
    Service.getInstance().setOutboundMessageNotification(outboundNotification);
    Service.getInstance().addGateway(gateway);
    Service.getInstance().startService();
    System.out.println();
    System.out.println("Modem Information:");
    System.out.println("  Manufacturer: " + gateway.getManufacturer());
    System.out.println("  Model: " + gateway.getModel());
    System.out.println("  Serial No: " + gateway.getSerialNo());
    System.out.println("  SIM IMSI: " + gateway.getImsi());
    System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
    System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
    System.out.println();
    Service.getInstance().createGroup("mygroup");
    Service.getInstance().addToGroup("mygroup", "xxxxxxxxxx");
    Service.getInstance().addToGroup("mygroup", "xxxxxxxxxx");

    String message1 = url;
    OutboundMessage msg = new OutboundMessage("mygroup", message1);
    Service.getInstance().sendMessage(msg);
    System.out.println(msg);
    Service.getInstance().stopService();
  }

public class OutboundNotification implements IOutboundMessageNotification {
    public void process(AGateway gateway, OutboundMessage msg) {
        System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
        System.out.println(msg);

     }
  }

}

End point publisher
package com.k4n.webservice;

import javax.xml.ws.Endpoint;
import com.k4n.webservice.GetURLImpl;

 //Endpoint publisher
public class GetURLPublisher{

public static void main(String[] args) {
   Endpoint.publish("http://localhost:9999/ws/hello", new GetURLImpl());
   System.out.println("Now the web service is up...");
  }

}

And this is the SMSlib out put when trying to send SMS for second time.
    Example: Send message from a serial gsm modem.
   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
    Version: 3.5.0
    [pool-1-thread-1] INFO smslib - Queue directory not defined. Queued messages will not be saved to         filesystem.
    [Thread-16] INFO smslib - GTW: modem.com1: Starting gateway, using Huawei (Generic) AT Handler.
    [Thread-16] INFO smslib - GTW: modem.com1: Opening: COM12 @115200
    [Thread-15] INFO smslib - GTW: modem.com1: Starting gateway, using Huawei (Generic) AT Handler.
    [Thread-15] INFO smslib - GTW: modem.com1: Opening: COM12 @115200
    [Thread-15] INFO smslib - GTW: modem.com1: Closing: COM12 @115200
    SEND :(27)
    [pool-1-thread-1] INFO smslib - GTW: modem.com1: Stopping gateway...
    [pool-1-thread-1] INFO smslib - GTW: modem.com1: Closing: COM12 @115200
    [pool-1-thread-1] INFO smslib - GTW: modem.com1: Gateway stopped.
    [pool-1-thread-1] INFO smslib - GTW: modem.com1: Stopping gateway...
    SEND :+++
    [pool-1-thread-1] INFO smslib - GTW: modem.com1: Closing: COM12 @115200
    [Thread-16] INFO smslib - GTW: modem.com1: Closing: COM12 @115200
    [pool-1-thread-1] INFO smslib - GTW: modem.com1: Gateway stopped.

Why I'm getting this error? how can I solve this?

A:

Got the Answer 
Remove the gateway after stopping the service
String message1 = url;
OutboundMessage msg = new OutboundMessage("mygroup", message1);
Service.getInstance().sendMessage(msg);
System.out.println(msg);
Service.getInstance().stopService(); 
Service.getInstance().removeGateway(gateway);//remove the gateway

This is worked for me.

