Import de package

4 respostas
fscpv

Galera Gostaria de saber como posso importar um package? a vivo no site www.desenvolvedores.vivo.com.br liberou uma api para envio de sms mms wap push mas nao estou entendendo muito bem gostaria de testar mas nao estou conseguindo alguem pode me dar uma ajuda? obrigado!

4 Respostas

dudu_sps

Voce gostaria de importar uma biblioteca eu axo

voce tem que ir na ide que voce usa e adicionar a biblioteca na lib do seu projeto

fscpv

Cara obigado por me ajudar mas nao sei se é isso eui vou colar o cdigo exemplo ok?

package es.tid.unica.rest.sms.examples;


import es.tid.unica.rest.Encoding;
import es.tid.unica.rest.sms.SMSClient;
import es.tid.unica.rest.sms.SMSClientFactory;
import es.tid.unica.rest.sms.SendSMSResult;
import es.tid.unica.types.common.E164Type;
import es.tid.unica.types.common.UserIdType;
import es.tid.unica.types.sms.SMSDeliveryStatusType;
import es.tid.unica.types.sms.SMSTextContentType;
import es.tid.unica.types.sms.SMSTextType;

public class ExampleSMSBrazil {

	public static void main(String args[]) {
		// General configuration data

		String base_uri = "https://sdp.vivo.com.br/osg/UNICA-SMS-REST";
		String proxy_host = null;  // No proxy is used
		int proxy_port = 80;

		// Security configuration data
		String service_id = "[telefone removido]";
		String sp_id = "000037";
		String sp_password = "123456";
		String access_token = "o3H85j7c";
		String requestor_id = "551171107149";

		int requestor_type = 1;

		// Destination
		String receipt_msisdn = "551171107147";
		
		String message_text = "This is a test message";
		
		try {
			// Creating the client
			SMSClient client = SMSClientFactory.getInstance().createSMSClient(base_uri, proxy_host, proxy_port);

			// Initialize the client
			client.setServiceId(service_id);
			client.setSpId(sp_id);
			client.setSpPassword(sp_password);
			client.setAccessToken(access_token);
			client.setRequestorId(requestor_id);
			client.setRequestorType(requestor_type);
			
			// Enable authentication
			client.enableAuthentication(true);

			//-----------------------------------------------
			// Send an SMS
			// 1. Build the message
			SMSTextType sms = new SMSTextType();
			// 1.1 Receipt address
			UserIdType address = new UserIdType();
			address.setPhoneNumber(new E164Type(receipt_msisdn));
			sms.addAddress(address);
			// 1.2 Text content
			SMSTextContentType sms_text_content = new SMSTextContentType(message_text);
			sms.setMessage(sms_text_content);
			// 2. Send the message.
			SendSMSResult result = client.sendSMS(sms, Encoding.APPLICATION_XML);
			System.out.println("The result of the sendSMS opeation is " + result);
			//-----------------------------------------------

			Thread.sleep(3000);
			
			//-----------------------------------------------
			// Retrieve the delivery status of the sent SMS.
			SMSDeliveryStatusType status = client.getSMSDeliveryStatus(result.getLocationHeader().toString(), null);
			System.out.println("The result of the getSMSDeliveryStatus opeation is " + status);
			//-----------------------------------------------
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}

esse é o codigo!

Desde j á agradeço!

:D

fscpv

existe até uma documentação e o nome é “Package es.tid.unica.types.sms”.

fscpv

consegui importar a biblioteca e está ok!

Sem erros de importação mas esta com erro na execução segue o codigo!

package es.tid.unica.rest.sms.examples;


import es.tid.unica.rest.Encoding;
import es.tid.unica.rest.sms.SMSClient;
import es.tid.unica.rest.sms.SMSClientFactory;
import es.tid.unica.rest.sms.SendSMSResult;
import es.tid.unica.types.common.E164Type;
import es.tid.unica.types.common.UserIdType;
import es.tid.unica.types.sms.SMSDeliveryStatusType;
import es.tid.unica.types.sms.SMSTextContentType;
import es.tid.unica.types.sms.SMSTextType;

public class ExampleSMSBrazil {

	public static void main(String args[]) {
		// General configuration data

		String base_uri = "https://sdp.vivo.com.br/osg/UNICA-SMS-REST";
		String proxy_host = null;  // No proxy is used
		int proxy_port = 80;

		// Security configuration data
		String service_id = "[telefone removido]";
		String sp_id = "000037";
		String sp_password = "123456";
		String access_token = "o3H85j7c";
		String requestor_id = "551171107149";

		int requestor_type = 1;

		// Destination
		String receipt_msisdn = "551171107147";

		String message_text = "This is a test message";

		try {
			// Creating the client
			SMSClient client = SMSClientFactory.getInstance().createSMSClient(base_uri, proxy_host, proxy_port);

			// Initialize the client
			client.setServiceId(service_id);
			client.setSpId(sp_id);
			client.setSpPassword(sp_password);
			client.setAccessToken(access_token);
			client.setRequestorId(requestor_id);
			client.setRequestorType(requestor_type);

			// Enable authentication
			client.enableAuthentication(true);

			//-----------------------------------------------
			// Send an SMS
			// 1. Build the message
			SMSTextType sms = new SMSTextType();
			// 1.1 Receipt address
			UserIdType address = new UserIdType();
			address.setPhoneNumber(new E164Type(receipt_msisdn));
			sms.addAddress(address);
			// 1.2 Text content
			SMSTextContentType sms_text_content = new SMSTextContentType(message_text);
			sms.setMessage(sms_text_content);
			// 2. Send the message.
			SendSMSResult result = client.sendSMS(sms, Encoding.APPLICATION_XML);
			System.out.println("The result of the sendSMS opeation is " + result);
			//-----------------------------------------------

			Thread.sleep(3000);

			//-----------------------------------------------
			// Retrieve the delivery status of the sent SMS.
			SMSDeliveryStatusType status = client.getSMSDeliveryStatus(result.getLocationHeader().toString(), null);
			System.out.println("The result of the getSMSDeliveryStatus opeation is " + status);
			//-----------------------------------------------

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Erro:

run:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
        at es.tid.unica.rest.sms.SMSClientFactoryImpl.createSMSClient(SMSClientFactoryImpl.java:17)
        at es.tid.unica.rest.sms.examples.ExampleSMSBrazil.main(ExampleSMSBrazil.java:39)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletInputStream
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        ... 2 more
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 0 segundos)
Criado 1 de março de 2010
Ultima resposta 1 de mar. de 2010
Respostas 4
Participantes 2