Introduction
This tutorial shows how to use the playground web service interface to obtain customer data from a java client. The tutorial is based on a proprietory web service following the same principles as parlayX Web services. The tutorial illustrates how to create a java client invoking this 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
- Geographical data / Coordinates
Follow the steps below to create a client which invokes the Subscriber Profile 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 "Get Subscriber Data". 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, we will create the stubs necessary to handle the Send SMS functionality in our client. Select your project, click the right mouse button and select "New -> Other" on the toolbar, to start the "New" wizard.
- Select "Web Service Client" from the "New" menu, and click the "Next" button. The "Web Service Client" wizard starts.
- Next, specify the location of the web service in the service definition field as illustrated below. The wizard will validate the WSDL file after the address is fully entered. Make sure Java Proxy is selected as client type.
- Slide the slider down to only create a client and click the "Finish" button. The wizard will then create the stubs required to later invoke the Subscriber Profile web service.
- 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 "MyGetSubscriberData" 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.unipier.broker.flows.GetSubscriberProfileOutput;
import com.unipier.broker.flows.SubscriberProfileServiceHttpBindingStub;
import com.unipier.broker.flows.SubscriberProfile_0_1V0_WS;
import com.unipier.broker.flows.SubscriberProfile_0_1V0_WSLocator;
import com.unipier.broker.flows.beans.CrmReturnedAttribute;
public class MyGetSubscriberData {
public MyGetSubscriberData(String _username,String _pwd,String _subscriberid)
{
try
{
/**
* Get the subscriber Web service
*/
SubscriberProfile_0_1V0_WS subscriberService =
new SubscriberProfile_0_1V0_WSLocator();
String subscriberServiceEndpoint =
"http://playgroundlab.telenor.com:9032/SubscriberProfile_0_1v0_WS/"
+ "SubscriberProfileServiceHttpBinding";
SubscriberProfileServiceHttpBindingStub subscriber =
(SubscriberProfileServiceHttpBindingStub)
subscriberService.getSubscriberProfileServicePortTypePort(
new URL(subscriberServiceEndpoint));
/**
* Add the necessary authentication data
*/
Stub stub = (Stub)subscriber;
stub.setUsername(_username);
stub.setPassword(_pwd);
/**
* Prepare the parameters
* An array of attributes must be passed to the method in order to
* state which attributes should be returned
*/
String [] attribList =
new String[]{"MSISDN","GENDER","DATE_OF_BIRTH","POSTCODE",};
/**
* Get the subscriber data
*/
GetSubscriberProfileOutput mySubscriber =
subscriber.getSubscriberProfile(_subscriberid, attribList);
/**
* Display some output
*/
CrmReturnedAttribute[] subsAttributes =
(CrmReturnedAttribute[]) mySubscriber.getAttributes();
if(subsAttributes!=null){
if(subsAttributes.length>0){
CrmReturnedAttribute attr1 = (CrmReturnedAttribute) subsAttributes[1];
if (attr1 !=null)
{
System.out.println(
"Gender: " + attr1.getValue().getStringValue());
}
}
else
{
System.out.println(
"Subscriber with id: " + _subscriberid + " not found");
}
}
else
{
System.out.println(
"Subscriber with id: " + _subscriberid + " not found");
}
}
/**
* Catch
* - Add appropriate exception handling
*/
catch(Throwable e){
e.printStackTrace();
}
}
/**
* Use your main method to initiate an instance of the class
* and perform the logic placed in the constructor.
*
* username and password are received in your welcome
* to the lab email
*
* subscriberid is the primary key of the subscriber for
* which you request data (get for instance from Wap request)
*/
public static void main(String[] args) {
new MyGetSubscriberData("username","password","CCNNNNNNNN");
}
}
|


