シリアル gsm モデムを使用してメッセージを送信するために SMSlib を使用しています。同じアプリケーションを使用して SMS を複数回送信する必要があります。SMSlib の例を問題なく実行したところ、問題なく動作しましたが、Web サービスで同じコードを使用しようとすると、一度しか使用できませんでした。そして、2回目に使用しようとすると、次のエラーが発生しました。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...");
}
}
これは、2 回目に SMS を送信しようとしたときの 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.
なぜこのエラーが発生するのですか? どうすればこれを解決できますか?