OfferAPI.java

この Java™ サンプルをコンパイルして実行するには、 従属するすべての .jar ファイルを Java クラスパスに含める必要があります。CampaignServicesClient30.jar ファイルは、<CAMPAIGN_HOME>/Campaign.war にある Apache AXIS2 SOAP エンジン .jar ファイルおよび他の共通 Apache .jar ファイルに従属します。.jar ファイルを Campaign.war から抽出して、Java クラスパスに含めます。

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 Campaign SOAP 
services API.
 * This sample uses CampaignServices30SoapClient facade to interact with 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();
        }
    }
}