Introduction
This tutorial shows how to use the playground web service interface to send a MMS from a java client. The tutorial is based on the send Message Parlay X web service, and illustrates how to create a java client invoking a web service. As a prerequisite we assume that you are familiar with the following technologies:
- HTML
- XML, SOAP and Web Services
- Eclipse - as an environment for Java and web service development
- Java, inclusive basic HTTP/URL handling
- MMS messaging
Follow the steps below to create a client which invokes the SendMessage web service.
Place the cursor over this icon to expand screenshots from Eclipse.
- Download and install the Eclipse IDE (Web Tools Platform).
- Create a new project by selecting File | New | Java Project from the menu bar. This initiates the "New Java Project" wizard.
- Give the project a name, and choose your preferences on Java version and project organization. In this tutorial, we named the project "Send MMS Demo". The default values are used for all other selections.
- Push "Finish" to continue and close the wizard. The project is created, and the next steps describe how to start adding the required content to your project.
- Next, you have to create stubs for accessing the web services APIs. The process of creating stubs is described in a separate tutorial - Web services client tutorial. Alternatively you can download and store locally the file, playground.jar
- Add the library to your project. To do this, use the right mouse button on your project, and select "Properties", then click "Java Build Path" and "Add External JAR's" button, to select the JAR files. Click the OK button, when you are done.
- In addition to playground.jar you should add the following libraries to your project:
- activation.jar
- mail.jar
- axis.jar - the axis binary download also includes the following required libraries:
- commons-discovery-0.2.jar
- commons-logging-1.0.4.jar
- wsdl4j-1.5.1.jar
- jaxrpc.jar
- saaj.jar
- Add a new Java class to the project. Right click your project, and select "New -> Class" from the menu, to start the "New Java Class" wizard. Name the Java class, in this example "MySendMessageDemo" and check for automatically generating the main method. Click "Finish" and the java class is generated.
- The content in the following zip file may be used as content for your first MMS message (Right click and choose save as):
- Finally, cut & paste from the source code below into your java class file
import java.io.BufferedInputStream;
import java.net.URL;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.types.URI;
import org.csapi.www.schema.parlayx.multimedia_messaging.v2_4.MessagePriority;
import org.csapi.www.wsdl.parlayx.multimedia_messaging.send.v2_4._interface.SendMessage;
import org.csapi.www.wsdl.parlayx.multimedia_messaging.send.v2_4.service.ParlayXSendMessage_0_2V1_WS;
import org.csapi.www.wsdl.parlayx.multimedia_messaging.send.v2_4.service.ParlayXSendMessage_0_2V1_WSLocator;
public class MySendMessageDemo {
public MySendMessageDemo(String _username,String _pwd,String _correlator)
{
try{
/**
* get the Send Message service
*/
ParlayXSendMessage_0_2V1_WS sendMessageService =
new ParlayXSendMessage_0_2V1_WSLocator();
String sendMessageServiceEndpoint =
sendMessageService.getSendMessagePortAddress();
System.out.println(sendMessageServiceEndpoint);
SendMessage sendMessage =
sendMessageService.getSendMessagePort(new URL(sendMessageServiceEndpoint));
/**
* Prepare the parameters needed for sending SMS (
* C = Country code
* N = Phone Number
*/
URI[] addr = new URI[1];
addr[0] = new URI("tel:CCNNNNNNNN");
String msg = "Welcome to playground!";
/**
* Add the necessary authentication data
*/
org.apache.axis.client.Stub stub = (org.apache.axis.client.Stub) sendMessage;
stub.setUsername(_username);
stub.setPassword(_pwd);
/**
* Add the contents of the MMS as a SOAP
* attachment in MIME format to the header of the
* object representing the call.
*/
int index = 1;
AttachmentPart ap = new AttachmentPart();
ap = defineAttachmentPart("file:mmscontent/playground_w.jpg"
, "image/jpeg", "playground_w.jpg", index++);
stub.addAttachment(ap);
ap = defineAttachmentPart("file:mmscontent/playground_b.jpg"
, "image/jpeg", "playground_b.jpg", index++);
stub.addAttachment(ap);
ap = defineAttachmentPart("file:mmscontent/pres.smil"
, "application/octet-stream", "pres.smil", index++);
stub.addAttachment(ap);
ap = defineAttachmentPart("file:mmscontent/message.txt"
, "text/plain", "message.txt", index++);
stub.addAttachment(ap);
/**
* Finally, Send your Message
*/
String status = sendMessage.sendMessage(addr, _correlator, msg
, MessagePriority.Normal, null, null);
System.out.println("Status after send:" + status);
}
catch (Exception e)
{
// Handle your error situations here
e.printStackTrace();
}
}
/**
* Helper method for adding content to the MMS Message
*/
private AttachmentPart defineAttachmentPart(String mmsInfo
,String contentType, String contentId, int index) {
AttachmentPart apPart = new AttachmentPart();
try {
URL fileurl = new URL(mmsInfo);
BufferedInputStream bis =
new BufferedInputStream(fileurl.openStream());
apPart.setContent(bis, contentType);
apPart.setMimeHeader("Ordinal", String.valueOf(index));
apPart.setContentId(contentId);
} catch (Exception ex) {
ex.printStackTrace();
}
return apPart;
}
/**
* Use your main method to initiate an instance of the class
* and perform the logic placed in the constructor.
*
* Constructor arguments (username, password and mms correlator)
* are received in your welcome to the lab email
* mms correlator looks like:
* "tel:Mailbox ID\Mailbox Pwd\tel:26016"
*/
public static void main(String[] args) {
new MySendMessageDemo("username","password","mms correlator");
}
}
|


