1

I have SMS server, and I want to send and receive SMS from My java web application. How I do this?

Thanks,

reference
  • 51
  • 1
  • 5
  • Give details about your server, and show us code that fails so we can provide you with ideas. – Seyf Nov 30 '14 at 10:17

3 Answers3

0

Normally, you can use SMS servers via HTTP api, e.g. send a request to

http://your-server-name/sendSms?nr=55534563&msg=hello+world

You should look for exact information in your server's documentation.

For general examples on how to send HTTP requests, see for instance this answer (GET) and this answer (POST).

Community
  • 1
  • 1
geert3
  • 7,086
  • 1
  • 33
  • 49
  • First of all, thank you. You have idea if can create a local server for simulation of SMS in eclipse? – reference Nov 30 '14 at 10:43
  • If your SMS server effectively exposes an HTTP API, you could implement a similar API yourself using for instance Java servlets. Should be easy to do. – geert3 Nov 30 '14 at 10:48
0

Depending on your sms gateway API specifications, you'll have to:

  • Call a http url to send a SMS
  • Get your Java app called through http to receive a SMS

Take a look at this example of SMS api specifications, it also includes several examples of codes in different programming languages.

zfou
  • 891
  • 1
  • 10
  • 33
0

There is Ogham library. The code to send SMS is easy to write (it automatically handles character encoding and message splitting). The real SMS is sent either using SMPP protocol (standard SMS protocol) or through a provider API. You can even test your code locally with a SMPP server to check the result of your SMS before paying for real SMS sending. As it uses SMPP standard protocol, many providers can be used.

package fr.sii.ogham.sample.standard.sms;

import java.util.Properties;

import fr.sii.ogham.core.builder.MessagingBuilder;
import fr.sii.ogham.core.exception.MessagingException;
import fr.sii.ogham.core.service.MessagingService;
import fr.sii.ogham.sms.message.Sms;

public class BasicSample {
    public static void main(String[] args) throws MessagingException {
        // [PREPARATION] Just do it once at startup of your application
        
        // configure properties (could be stored in a properties file or defined
        // in System properties)
        Properties properties = new Properties();
        properties.setProperty("ogham.sms.smpp.host", "<server host given by the provider>");                                 // <1>
        properties.setProperty("ogham.sms.smpp.port", "<server port given by the provider>");                                 // <2>
        properties.setProperty("ogham.sms.smpp.system-id", "<system ID given by the provider>");                       // <3>
        properties.setProperty("ogham.sms.smpp.password", "<password given by the provider>");                         // <4>
        properties.setProperty("ogham.sms.from.default-value", "<phone number to display for the sender>");  // <5>
        // Instantiate the messaging service using default behavior and
        // provided properties
        MessagingService service = MessagingBuilder.standard()                                               // <6>
                .environment()
                    .properties(properties)                                                                  // <7>
                    .and()
                .build();                                                                                    // <8>
        // [/PREPARATION]
        
        // [SEND A SMS]
        // send the sms using fluent API
        service.send(new Sms()                                                                               // <9>
                        .message().string("sms content")
                        .to("+33752962193"));
        // [/SEND A SMS]
    }
}

There are many other features and samples / spring samples.

creponutella
  • 173
  • 3
  • 6