// Path: gsm-modem-client-api/src/main/java/fr/romainmoreau/gsmmodem/client/api/GsmModemException.java
// public class GsmModemException extends Exception {
// 	private static final long serialVersionUID = 1L;
// 
// 	public GsmModemException() {
// 		super();
// 	}
// 
// 	public GsmModemException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public GsmModemException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public GsmModemException(String message) {
// 		super(message);
// 	}
// 
// 	public GsmModemException(Throwable cause) {
// 		super(cause);
// 	}
// }
// 
// Path: gsm-modem-client-common/src/main/java/fr/romainmoreau/gsmmodem/client/common/AbstractGsmModemClient.java
// public abstract class AbstractGsmModemClient implements GsmModemClient {
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/Command.java
// public interface Command {
// 	void execute(GsmModemClient gsmModemClient) throws IOException, GsmModemException;
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/Commands.java
// @XmlRootElement
// public class Commands {
// 	private List<Command> commands;
// 
// 	@XmlElements({ @XmlElement(name = "sendSms", type = SendSms.class),
// 			@XmlElement(name = "sendCommand", type = SendCommand.class),
// 			@XmlElement(name = "setSMSTextMode", type = SetSMSTextMode.class) })
// 	public List<Command> getCommands() {
// 		return commands;
// 	}
// 
// 	public void setCommands(List<Command> commands) {
// 		this.commands = commands;
// 	}
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/SendCommand.java
// public class SendCommand implements Command {
// 	private String command;
// 
// 	@Override
// 	public void execute(GsmModemClient gsmModemClient) throws IOException, GsmModemException {
// 		gsmModemClient.sendCommand(command);
// 	}
// 
// 	@XmlValue
// 	public String getCommand() {
// 		return command;
// 	}
// 
// 	public void setCommand(String command) {
// 		this.command = command;
// 	}
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/SendSms.java
// public class SendSms implements Command {
// 	private String gsmNumber;
// 
// 	private String sms;
// 
// 	@Override
// 	public void execute(GsmModemClient gsmModemClient) throws IOException, GsmModemException {
// 		gsmModemClient.sendSms(gsmNumber, sms);
// 	}
// 
// 	@XmlAttribute(required = true)
// 	public String getGsmNumber() {
// 		return gsmNumber;
// 	}
// 
// 	public void setGsmNumber(String gsmNumber) {
// 		this.gsmNumber = gsmNumber;
// 	}
// 
// 	@XmlValue
// 	public String getSms() {
// 		return sms;
// 	}
// 
// 	public void setSms(String sms) {
// 		this.sms = sms;
// 	}
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/SetSMSTextMode.java
// public class SetSMSTextMode implements Command {
// 	@Override
// 	public void execute(GsmModemClient gsmModemClient) throws IOException, GsmModemException {
// 		gsmModemClient.setSMSTextMode();
// 	}
// }


import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import org.springframework.web.client.RestTemplate;
import fr.romainmoreau.gsmmodem.client.api.GsmModemException;
import fr.romainmoreau.gsmmodem.client.common.AbstractGsmModemClient;
import fr.romainmoreau.gsmmodem.jaxb.api.Command;
import fr.romainmoreau.gsmmodem.jaxb.api.Commands;
import fr.romainmoreau.gsmmodem.jaxb.api.SendCommand;
import fr.romainmoreau.gsmmodem.jaxb.api.SendSms;
import fr.romainmoreau.gsmmodem.jaxb.api.SetSMSTextMode;
package fr.romainmoreau.gsmmodem.client.web;




public class WebGsmModemClient extends AbstractGsmModemClient {
	private final RestTemplate restTemplate;

	private final URI uri;

	public WebGsmModemClient(String protocol, String host, int port) throws MalformedURLException, URISyntaxException {
		restTemplate = new RestTemplate();
		uri = new URL(protocol, host, port, "/commands").toURI();
	}

	@Override
	public synchronized void setSMSTextMode() throws IOException, GsmModemException {
		sendCommand(new SetSMSTextMode());
	}

	@Override
	public synchronized void sendSms(String gsmNumber, String sms) throws IOException, GsmModemException {
		SendSms sendSms = new SendSms();
		sendSms.setGsmNumber(gsmNumber);
		sendSms.setSms(sms);
		sendCommand(sendSms);
	}

	@Override
	public void sendCommand(String command) throws IOException, GsmModemException {
		SendCommand sendCommand = new SendCommand();
		sendCommand.setCommand(command);
		sendCommand(sendCommand);
	}

	@Override
	public synchronized void close() throws IOException {
	}

// Path: gsm-modem-client-api/src/main/java/fr/romainmoreau/gsmmodem/client/api/GsmModemException.java
// public class GsmModemException extends Exception {
// 	private static final long serialVersionUID = 1L;
// 
// 	public GsmModemException() {
// 		super();
// 	}
// 
// 	public GsmModemException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public GsmModemException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public GsmModemException(String message) {
// 		super(message);
// 	}
// 
// 	public GsmModemException(Throwable cause) {
// 		super(cause);
// 	}
// }
// 
// Path: gsm-modem-client-common/src/main/java/fr/romainmoreau/gsmmodem/client/common/AbstractGsmModemClient.java
// public abstract class AbstractGsmModemClient implements GsmModemClient {
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/Command.java
// public interface Command {
// 	void execute(GsmModemClient gsmModemClient) throws IOException, GsmModemException;
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/Commands.java
// @XmlRootElement
// public class Commands {
// 	private List<Command> commands;
// 
// 	@XmlElements({ @XmlElement(name = "sendSms", type = SendSms.class),
// 			@XmlElement(name = "sendCommand", type = SendCommand.class),
// 			@XmlElement(name = "setSMSTextMode", type = SetSMSTextMode.class) })
// 	public List<Command> getCommands() {
// 		return commands;
// 	}
// 
// 	public void setCommands(List<Command> commands) {
// 		this.commands = commands;
// 	}
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/SendCommand.java
// public class SendCommand implements Command {
// 	private String command;
// 
// 	@Override
// 	public void execute(GsmModemClient gsmModemClient) throws IOException, GsmModemException {
// 		gsmModemClient.sendCommand(command);
// 	}
// 
// 	@XmlValue
// 	public String getCommand() {
// 		return command;
// 	}
// 
// 	public void setCommand(String command) {
// 		this.command = command;
// 	}
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/SendSms.java
// public class SendSms implements Command {
// 	private String gsmNumber;
// 
// 	private String sms;
// 
// 	@Override
// 	public void execute(GsmModemClient gsmModemClient) throws IOException, GsmModemException {
// 		gsmModemClient.sendSms(gsmNumber, sms);
// 	}
// 
// 	@XmlAttribute(required = true)
// 	public String getGsmNumber() {
// 		return gsmNumber;
// 	}
// 
// 	public void setGsmNumber(String gsmNumber) {
// 		this.gsmNumber = gsmNumber;
// 	}
// 
// 	@XmlValue
// 	public String getSms() {
// 		return sms;
// 	}
// 
// 	public void setSms(String sms) {
// 		this.sms = sms;
// 	}
// }
// 
// Path: gsm-modem-jaxb-api/src/main/java/fr/romainmoreau/gsmmodem/jaxb/api/SetSMSTextMode.java
// public class SetSMSTextMode implements Command {
// 	@Override
// 	public void execute(GsmModemClient gsmModemClient) throws IOException, GsmModemException {
// 		gsmModemClient.setSMSTextMode();
// 	}
// }


// Path: gsm-modem-client-web/src/main/java/fr/romainmoreau/gsmmodem/client/web/WebGsmModemClient.java
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import org.springframework.web.client.RestTemplate;
import fr.romainmoreau.gsmmodem.client.api.GsmModemException;
import fr.romainmoreau.gsmmodem.client.common.AbstractGsmModemClient;
import fr.romainmoreau.gsmmodem.jaxb.api.Command;
import fr.romainmoreau.gsmmodem.jaxb.api.Commands;
import fr.romainmoreau.gsmmodem.jaxb.api.SendCommand;
import fr.romainmoreau.gsmmodem.jaxb.api.SendSms;
import fr.romainmoreau.gsmmodem.jaxb.api.SetSMSTextMode;

package fr.romainmoreau.gsmmodem.client.web;




public class WebGsmModemClient extends AbstractGsmModemClient {
	private final RestTemplate restTemplate;

	private final URI uri;

	public WebGsmModemClient(String protocol, String host, int port) throws MalformedURLException, URISyntaxException {
		restTemplate = new RestTemplate();
		uri = new URL(protocol, host, port, "/commands").toURI();
	}

	@Override
	public synchronized void setSMSTextMode() throws IOException, GsmModemException {
		sendCommand(new SetSMSTextMode());
	}

	@Override
	public synchronized void sendSms(String gsmNumber, String sms) throws IOException, GsmModemException {
		SendSms sendSms = new SendSms();
		sendSms.setGsmNumber(gsmNumber);
		sendSms.setSms(sms);
		sendCommand(sendSms);
	}

	@Override
	public void sendCommand(String command) throws IOException, GsmModemException {
		SendCommand sendCommand = new SendCommand();
		sendCommand.setCommand(command);
		sendCommand(sendCommand);
	}

	@Override
	public synchronized void close() throws IOException {
	}

	private void sendCommand(Command command) {