OfferAPI.java

To compile and run this Java sample, you must include all dependent .jar files in the Java classpath. The CampaignServicesClient30.jar file depends on Apache AXIS2 SOAP engine .jar files and other common Apache .jar files, which can be found in <CAMPAIGN_HOME>/Campaign.war. Extract the .jar files from Campaign.war, and include them in the Java classpath.

import java.net.URL;
import java.util.Locale;
import com.unica.publicapi.campaign.campaignservices.CampaignServicesException;
import com.unica.publicapi.campaign.campaignservices.attribute.metadata.
    IAttribute Metadata;
import com.unica.publicapi.campaign.campaignservices.soap.v30.
    CampaignServices30SoapClient;
import com.unica.publicapi.campaign.campaignservices.soap.v30.WSAttribute;
import com.unica.publicapi.campaign.campaignservices.soap.v30.WSOfferInfo;
import com.unica.publicapi.campaign.campaignservices.utils.WSAttributeUtils;

/**
 * This is the sample java client class that shows the usage of Unica Campaign SOAP 
services API.
 * This sample uses CampaignServices30SoapClient facade to interact with Unica Campaign 
web service.
 * Here the creation of Offer is shown. Please refer to the API guide for 
more details.
 *
 * @author AGijare
 *
 */
public class OfferAPI {

    /**
     * @param args
     */
    protected static CampaignServices30SoapClient CLIENT = null;

    private static void setup(){
        try {
           String protocol = "http"; //http or https
           String host = "localhost"; //Host name of deployed Campaign. 
Use proper host name here.
           int port = 7001; //port number of deployed Campaign
           long timeOut = 2*60*1000; // 2 minutes
           String servicesURI = "/Campaign/services/CampaignServices30Service";
           CLIENT = new CampaignServices30SoapClient(
               new URL(protocol, host, port, servicesURI),
               timeOut);
      } catch (Exception exception) {
          exception.printStackTrace();
          System.exit(-1);
      }
    }

    public static void main(String[] args) {
        //Please change the values of following variables to match your 
environment.
        String userName = "user_name"; //login user name
        String partitionName = "partition1"; //Use proper partition name of 
Campaign
        Locale loc = Locale.US;
        String securityPolicy = "Global"; //Use your security policy of 
Campaign

        String offerName = "Offer1";
        String offerTemplate = "Offer Template"; // Template from which 
Offer will be created.
        long folderID = 1002; //Actual ID of the folder where this offer 
will be created. For folderID <=0, offer will be created at root level.
        //Attributes of Offer
        WSAttribute[] wsAttributes = {
            WSAttributeUtils.getWSTextAttribute(IAttributeMeta
data.AC_OFFER_DESCRIPTION_ATTRIBUTE_NAME, null, new String[]{"description " 
+ System.currentTimeMillis()})
        };

        setup();

        try {
            WSOfferInfo wsOfferInfo = CLIENT.createOffer(userName, 
partitionName, loc, securityPolicy,
                offerName, folderID, offerTemplate, wsAttributes);
            System.out.println("Created offer: " + wsOfferInfo.getName());
        } catch (CampaignServicesException e) {
            e.printStackTrace();
        }
    }
}