Introduction
This tutorial shows how to use the playground web service interface to receive a MMS from a subscriber using a java client. The tutorial is based on the receive Message Parlay X web service, and illustrates how to create a java client invoking a web service. This tutorial is using a poll mechanism to check if MMS messages are waiting to be processed. Alternatively, notifications can be used to alert an application when a MMS arrive. 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 Receive Message 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 "Receive Message from handset". 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, 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 "MyReceiveMMSDemo" and check for automatically generating the main method. Click "Finish" and the java class is generated.
- Finally, cut & paste from the source code below into your java class file
import java.net.URL;
import org.apache.axis.client.Stub;
import com.telenor.playground.toolbox.receive_mms.MessagePriority;
import com.telenor.playground.toolbox.receive_mms.MessageReference;
import com.telenor.playground.toolbox.receive_mms.ParlayXReceiveMessage_0_1V0_WS;
import com.telenor.playground.toolbox.receive_mms.ParlayXReceiveMessage_0_1V0_WSLocator;
import com.telenor.playground.toolbox.receive_mms.ReceiveMessage;
public class MyReceiveMMSDemo {
public MyReceiveMMSDemo(String _username, String _pwd, String _correlator)
{
try{
/**
* Get the receive Message Web service
*/
ParlayXReceiveMessage_0_1V0_WS receiveMessageService =
new ParlayXReceiveMessage_0_1V0_WSLocator();
String receiveMessageServiceEndpoint =
receiveMessageService.getReceiveMessagePortAddress();
ReceiveMessage receiveMessage =
receiveMessageService.getReceiveMessagePort(
new URL(receiveMessageServiceEndpoint));
/**
* Add the necessary authentication data
*/
Stub stub = (Stub)receiveMessage;
stub.setUsername(_username);
stub.setPassword(_pwd);
/**
* Get received messages.
*/
MessageReference[] messages =
receiveMessage.getReceivedMessages(_correlator
,MessagePriority.Normal);
/**
* Run through the array of received messages and print some information
* regarding each message
*/
if(messages != null){
for(int x = 0; x < messages.length; x++){
System.out.println("Message received[" + x + "] : "
+ " from:"
+ messages[x].getSenderAddress().getSchemeSpecificPart()
+ " at:" + messages[x].getDateTime().getTime()
+ " " + messages[x].getMessage() );
}
}else{
System.out.println("No messages received.");
}
}
/**
* Catch
* - Add appropriate exception handling
*/
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Use your main method to initiate an instance of the class
* and perform the logic placed in the constructor.
*
* Constructor arguments (username, password and Message correlator)
* are received in your welcome to the lab email
*/
public static void main(String[] args)
{
new MyReceiveMMSDemo("username","password","mms correlator");
}
}
|


