/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package gateway.sms; import java.text.SimpleDateFormat; import java.util.Calendar; import javax.xml.parsers.SAXParserFactory; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; /** * * @author Juan Carlos */ public class JaxSms { /** JAX = Java API for XML */ private final String URL_END_POINT; private final String ID_CLIENTE; private final String EMAIL; private final String PASSWORD; private SAXParserFactory factory = SAXParserFactory.newInstance(); private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy/hh/mm"); public JaxSms(){ URL_END_POINT = "https://www.calixtaondemand.com/ws/webServiceV8.php"; ID_CLIENTE = "46657"; EMAIL = "alberto.hernandez@hightek.com.mx"; PASSWORD = "5aa381482c45ecd2abdae944012c6126eb2f3ddf6f061c8176e00629277242c6"; } public String enviar(String telefono, String mensaje) { Calendar fecha = Calendar.getInstance(); fecha.add(Calendar.MINUTE, 1); try { HttpPost httppost = new HttpPost(URL_END_POINT); String xml = String.format(BASE_XML_REQUEST, ID_CLIENTE, EMAIL, PASSWORD, telefono, mensaje,sdf.format(fecha.getTime()), telefono); System.out.println("--------REQUEST------"); System.out.println(xml); httppost.setEntity(new StringEntity(xml)); httppost.setHeader("Content-Type", "text/xml;charset=utf-8"); httppost.setHeader("SOAPAction", URL_END_POINT+"?wsdl#EnviaMensajeOL"); SmsHandler handler = new SmsHandler(); factory.newSAXParser().parse(new DefaultHttpClient().execute(httppost).getEntity().getContent(), handler); System.out.println("--------RESPONSE-----"); System.out.println(handler.getReturn()); return handler.getReturn(); } catch (Exception ex) { ex.printStackTrace(); } return null; } private final String BASE_XML_REQUEST = "\n" + " \n" + " \n" + " %s\n" + " %s7\n" + " %s\n" + " SMS\n" + " %s\n" + " %s\n" + " 0\n" + " %s\n" + " \n" + " \n" + " \n" + " 0\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " TELEFONO\n" + " %s\n" + " \n" + " \n" + ""; }