带网络服务的 SMSlib

SMSlib with webservice

我正在使用 SMSlib 通过串行 gsm 发送消息 modem.I 需要使用同一个应用程序多次发送 SMS。我毫无问题地运行了 SMSlib 示例,当我尝试在它只能使用一次的 Web 服务下使用相同的代码时,它运行 fine.But。第二次尝试使用时出现以下错误。我使用了 python 客户端。

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'

这是网络服务(界面)

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

网络服务(实施)

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

     }
  }

}

端点发布者

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

}

这是第二次尝试发送短信时输出的 SMSlib。

    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.

为什么会出现此错误?我该如何解决这个问题?

得到答案

停止服务后删除网关

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

这对我有用。