Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import com.amethon.mc.ws.stubs.Message;
import com.amethon.mc.ws.stubs.SMSOption;
import com.amethon.mc.ws.stubs.SMSServiceServiceLocator;
import com.amethon.mc.ws.stubs.SMSServiceSoapBindingStub;

public class SMSReceiveClient {
    	public static void main(String\[\] args) throws Exception {
        		SMSServiceServiceLocator serviceLocator = new SMSServiceServiceLocator();
        		SMSServiceSoapBindingStub smsService = (SMSServiceSoapBindingStub)serviceLocator.getSMSService();
        
        		
		String username = "anh@amethon.com";
        String password = 
		String password = "M355ag3";
        		String documentId;
                
        // 				
		// Stop if there is no arguments supplied
        		if (args.length == 0) {
            			System.out.println("Required option missing: DocumentId");
            			System.exit(1);
        }        
        
        // documentId is passed as first argument to program
        documentId = args\[0\];
        
        // create a documentId option
        SMSOption documentIdOption = new SMSOption();
        documentIdOption.setName("document-id");
        documentIdOption.setValue(args\[0\]);    
        SMSOption\[\] receiveOptions = {documentIdOption};
        
        // poll for messages received passing in the documentId option
        Message\[\] receivedMessages = smsService.receive(username, password, receiveOptions);
                
        // iterate over the received Message array
        for (Message receivedMessage : receivedMessages) {            
            // Gets the source address and message body assuming its ASCII text
            String source = receivedMessage.getDestinations()\[0\].getSourceAddress().getValue();
            String subject = receivedMessage.getSubject();
            
            if (subject \!= null) {
                // The subject usually contains a error code if it is set
                System.out.println("Received message from " + source + " \"" + subject + "\"");
            }
            else {
                // Get the message and print it out
                String message = receivedMessage.getBody().getPayloads()\[0\].getContent();
                System.out.println(source + " : " + message);
            }
        }
        
        System.exit(0);
    		}		
		
		// documentId is passed as first argument to program
		documentId = args[0];
		
		// create a documentId option
		SMSOption documentIdOption = new SMSOption();
		documentIdOption.setName("document-id");
		documentIdOption.setValue(args[0]);	
		SMSOption[] receiveOptions = {documentIdOption};
		
		// poll for messages received passing in the documentId option
		Message[] receivedMessages = smsService.receive(username, password, receiveOptions);
				
		// iterate over the received Message array
		for (Message receivedMessage : receivedMessages) {			
			// Gets the source address and message body assuming its ASCII text
			String source = receivedMessage.getDestinations()[0].getSourceAddress().getValue();
			String subject = receivedMessage.getSubject();
			
			if (subject != null) {
				// The subject usually contains a error code if it is set
				System.out.println("Received message from " + source + " \"" + subject + "\"");
			}
			else {
				// Get the message and print it out
				String message = receivedMessage.getBody().getPayloads()[0].getContent();
				System.out.println(source + " : " + message);
			}
		}
		
		System.exit(0);
	}
}