Search in sources :

Example 11 with Configuration

use of com.xrtb.common.Configuration in project XRTB by benmfaul.

the class TestAdx method testSetup.

@BeforeClass
public static void testSetup() {
    try {
        DbTools tools = new DbTools("localhost:3000");
        tools.clear();
        tools.loadDatabase("database.json");
        if (server == null) {
            server = new RTBServer("./Campaigns/payday.json");
            int wait = 0;
            while (!server.isReady() && wait < 10) {
                Thread.sleep(1000);
                wait++;
            }
            if (wait == 10) {
                fail("Server never started");
            }
            Thread.sleep(1000);
        } else {
            Configuration c = Configuration.getInstance();
            c.campaignsList.clear();
            User u = DataBaseObject.getInstance().get("ben");
            for (Campaign camp : u.campaigns) {
                c.addCampaign("ben", camp.adId);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : RTBServer(com.xrtb.bidder.RTBServer) User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) DbTools(com.xrtb.tools.DbTools) BeforeClass(org.junit.BeforeClass)

Example 12 with Configuration

use of com.xrtb.common.Configuration in project XRTB by benmfaul.

the class TestCampaignProcessor method testJavascriptCreative.

@Test
public void testJavascriptCreative() throws Exception {
    Configuration cf = Configuration.getInstance();
    cf.clear();
    cf.initialize("Campaigns/payday.json");
    for (Campaign c : cf.campaignsList) {
        for (Creative cc : c.creatives) {
            if (cc.impid.equals("iamrichmedia")) {
                System.out.println(cc.forwardurl);
                assertTrue((cc.forwardurl.contains("\\")));
                return;
            }
        }
    }
}
Also used : Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) Creative(com.xrtb.common.Creative) SelectedCreative(com.xrtb.bidder.SelectedCreative) Test(org.junit.Test)

Example 13 with Configuration

use of com.xrtb.common.Configuration in project XRTB by benmfaul.

the class MyReader method testCleanup.

@AfterClass
public static void testCleanup() {
    Configuration c = Configuration.getInstance();
    c.campaignsList.clear();
}
Also used : Configuration(com.xrtb.common.Configuration) AfterClass(org.junit.AfterClass)

Example 14 with Configuration

use of com.xrtb.common.Configuration in project XRTB by benmfaul.

the class MacroProcessing method replace.

public static void replace(List<String> list, BidRequest br, Creative creat, Impression imp, String adid, StringBuilder sb, StringBuilder snurl, String dealid) throws Exception {
    String value = null;
    Object o = null;
    Configuration config = Configuration.getInstance();
    boolean isEncoded = false;
    if (sb.indexOf("%7B") != -1)
        isEncoded = true;
    for (int i = 0; i < list.size(); i++) {
        value = null;
        String item = list.get(i);
        switch(item) {
            case "{cachebuster}":
            case "%7Bcachebuster%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bcachebuster%7D", Integer.toString(random.nextInt(Integer.SIZE - 1)));
                else
                    replaceAll(sb, item, Integer.toString(random.nextInt(Integer.SIZE - 1)));
                break;
            case "{redirect_url}":
            case "%7Bredirect_url%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bredirect_url%7D", config.redirectUrl);
                else
                    replaceAll(sb, item, config.redirectUrl);
                break;
            case "{pixel_url}":
            case "%7Bpixel_url%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bpixel_url%7D", config.pixelTrackingUrl);
                else
                    replaceAll(sb, item, config.pixelTrackingUrl);
                break;
            case "{nurl}":
            case "%7Bnurl%7D":
                if (snurl == null)
                    value = "";
                else
                    value = snurl.toString();
                if (isEncoded)
                    replaceAll(sb, "%7Bnurl%7D", value);
                else
                    replaceAll(sb, item, value);
                break;
            case "{win_url}":
            case "%7Bwin_url%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bwin_url%7D", config.winUrl);
                else
                    replaceAll(sb, item, config.winUrl);
                break;
            case "{creative_forward_url}":
            case "%7Bcreative_forward_url%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bcreative_forward_url%7D", creat.forwardurl);
                else
                    replaceAll(sb, item, creat.forwardurl);
                break;
            case "{creative_ad_price}":
            case "%7Bcreative_ad_price%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bcreative_ad_price%7D", creat.strPrice);
                else
                    replaceAll(sb, item, creat.strPrice);
                break;
            case "{creative_ad_width}":
            case "%7Bcreative_ad_width%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bcreative_ad_width%7D", creat.strW);
                else
                    replaceAll(sb, item, creat.strW);
                break;
            case "{deal_id}":
            case "%7Bdeal_id%7D":
                if (isEncoded)
                    replaceAll(sb, "%7deal_id%7D", dealid);
                else
                    replaceAll(sb, item, dealid);
                break;
            case "{impression_width}":
            case "%7Bimpression_width%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bimpression_width%7D", Integer.toString(imp.w));
                else
                    replaceAll(sb, item, Integer.toString(imp.w));
                break;
            case "{impression_height}":
            case "7Bimpression_height7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bimpression_height%7D", Integer.toString(imp.h));
                else
                    replaceAll(sb, item, Integer.toString(imp.h));
                break;
            case "{creative_ad_height}":
            case "%7Bcreative_ad_height%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bcreative_ad_height%7D", creat.strH);
                else
                    replaceAll(sb, item, creat.strH);
                break;
            case "{creative_id}":
            case "%7Bcreative_id%7D":
            case "{imp}":
            case "%7Bimp%7D":
                if (isEncoded) {
                    replaceAll(sb, "%7Bcreative_id%7D", creat.impid);
                    replaceAll(sb, "%7Bimp%7D", creat.impid);
                } else {
                    replaceAll(sb, "{creative_id}", creat.impid);
                    replaceAll(sb, "{imp}", creat.impid);
                }
                break;
            case "{creative_image_url}":
            case "%7Bcreative_image_url%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bcreative_image_url%7D", creat.imageurl);
                else
                    replaceAll(sb, item, creat.imageurl);
                break;
            case "{site_name}":
            case "%7Bsite_name%7D":
            case "{app_name}":
            case "%7app_name%7D":
                if (isEncoded) {
                    replaceAll(sb, "%7Bsite_name%7D", br.siteName);
                    replaceAll(sb, "%7Bapp_name%7D", br.siteName);
                } else {
                    replaceAll(sb, "{site_name}", br.siteName);
                    replaceAll(sb, "{app_name}", br.siteName);
                }
                break;
            case "{site_id}":
            case "%7Bsite_id%7D":
            case "{app_id}":
            case "%7Bapp_id%7D":
                if (isEncoded) {
                    replaceAll(sb, "%7Bsite_id%7D", br.siteId);
                    replaceAll(sb, "%7Bapp_id%7D", br.siteId);
                } else {
                    replaceAll(sb, "{site_id}", br.siteId);
                    replaceAll(sb, "{app_id}", br.siteId);
                }
                break;
            case "{page_url}":
            case "%7Bpage_url%7D":
                if (br.pageurl != null)
                    value = br.pageurl;
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bpageurl%7D", br.pageurl);
                else
                    replaceAll(sb, item, br.pageurl);
                break;
            case "{lat}":
            case "%7Blat%7D":
                if (br.lat == null)
                    break;
                else {
                    if (isEncoded)
                        replaceAll(sb, "%7Blat%7D", br.lat.toString());
                    else
                        replaceAll(sb, item, br.lat.toString());
                }
                break;
            case "{lon}":
            case "%7Blon%7D":
                if (br.lon == null)
                    break;
                else {
                    if (isEncoded)
                        replaceAll(sb, "%7Blon%7D", br.lon.toString());
                    else
                        replaceAll(sb, item, br.lon.toString());
                }
                break;
            case "{site_domain}":
            case "%7Bsite_domain%7D":
            case "{app_domain}":
            case "%7Bapp_domain%7D":
                if (isEncoded) {
                    replaceAll(sb, "%7Bsite_domain%7D", br.siteDomain);
                    replaceAll(sb, "%7Bapp_domain%7D", br.siteDomain);
                } else {
                    replaceAll(sb, "{site_domain}", br.siteDomain);
                    replaceAll(sb, "{app_domain}", br.siteDomain);
                }
                break;
            case "{pub}":
            case "%7Bpub%7D":
            case "{exchange}":
            case "%7Bexchange%7D":
                if (isEncoded) {
                    replaceAll(sb, "%7Bpub%7D", br.getExchange());
                    replaceAll(sb, "%7Bexchange%7D", br.getExchange());
                } else {
                    replaceAll(sb, "{pub}", br.getExchange());
                    replaceAll(sb, "{exchange}", br.getExchange());
                }
                break;
            case "{bid_id}":
            case "%7Bbid_id%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bbid_id%7D", br.id);
                else
                    replaceAll(sb, item, br.id);
                break;
            case "{ad_id}":
            case "%7Bad_id%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Bad_id%7D", adid);
                else
                    replaceAll(sb, "{ad_id}", adid);
                break;
            case "{isp}":
            case "%7Bisp%7D":
                o = br.interrogate("device.carrier");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bisp%7D", value);
                else
                    replaceAll(sb, item, value);
                break;
            case "{bidder_ip}":
            case "%7Bbidder_ip%7D}":
                if (isEncoded)
                    replaceAll(sb, "%7Bbidder_ip%7D}", Configuration.ipAddress);
                else
                    replaceAll(sb, item, Configuration.ipAddress);
                break;
            case "{make}":
            case "%7Bmake%7D":
            case "{brand}":
            case "%7Bbrand%7D":
                o = br.interrogate("device.make");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded) {
                    replaceAll(sb, "%7Bmake%7D", value);
                    replaceAll(sb, "%7Bbrand%7D", value);
                } else {
                    replaceAll(sb, "{make}", value);
                    replaceAll(sb, "{brand}", value);
                }
                break;
            case "{model}":
            case "%7Bmodel%7D":
                o = br.interrogate("device.model");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded) {
                    replaceAll(sb, "%7Bmodel%7D", value);
                } else {
                    replaceAll(sb, "{model}", value);
                }
                break;
            case "{os}":
            case "%7Bos%7D":
                o = br.interrogate("device.os");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bos%7D", value);
                else
                    replaceAll(sb, "{os}", value);
                break;
            case "{osv}":
            case "%7Bosv%7D":
                o = br.interrogate("device.osv");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bosv%7D", value);
                else
                    replaceAll(sb, "{osv}", value);
                break;
            case "{timestamp}":
            case "%7Btimestamp%7D":
                if (isEncoded)
                    replaceAll(sb, "%7Btimestamp%7D", "" + System.currentTimeMillis());
                else
                    replaceAll(sb, "{timestamp}", "" + System.currentTimeMillis());
                break;
            case "{ip}":
            case "%7Bip%7D":
                o = br.interrogate("device.ip");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bip%7D", value);
                else
                    replaceAll(sb, "{ip}", value);
                break;
            case "{gps}":
            case "%7Bgps%7D":
                if (br.lat == null)
                    break;
                else {
                    if (isEncoded)
                        replaceAll(sb, "%7Bgps%7D", (br.lat.toString() + "x" + br.lon.toString()));
                    else
                        replaceAll(sb, "{gps}", (br.lat.toString() + "x" + br.lon.toString()));
                }
                break;
            case "{ua}":
            case "%7Bua%7D":
                o = br.interrogate("device.ua");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bua%7D", URIEncoder.myUri(value));
                else
                    replaceAll(sb, "{ua}", URIEncoder.myUri(value));
                break;
            case "{publisher}":
            case "%7Bpublisher%7D":
                o = br.interrogate("site.name");
                if (o == null)
                    o = br.interrogate("app.name");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bpublisher%7D", value);
                else
                    replaceAll(sb, "{publisher}", value);
                break;
            case "{adsize}":
            case "%7Badsize%7D":
                value = creat.strW + "x" + creat.strH;
                if (isEncoded)
                    replaceAll(sb, "%7Badsize%7D", value);
                else
                    replaceAll(sb, "{adsize}", value);
                break;
            case "{ifa}":
            case "%7Bifa%7D":
                o = br.interrogate("device.ifa");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bifa%7D", value);
                else
                    replaceAll(sb, "{ifa}", value);
                break;
            case "{dnt}":
            case "%7Bdnt%7D":
                o = br.interrogate("device.dnt");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bdnt%7D", value);
                else
                    replaceAll(sb, "{dnt}", value);
                break;
            case "{app_bundle}":
            case "%7Bapp_bundle%7D":
                o = br.interrogate("app_bundle");
                if (o != null)
                    value = BidRequest.getStringFrom(o);
                else
                    value = "";
                if (isEncoded)
                    replaceAll(sb, "%7Bapp_bundle%7D", value);
                else
                    replaceAll(sb, "{app_bundle}", value);
                break;
        }
    }
}
Also used : Configuration(com.xrtb.common.Configuration)

Example 15 with Configuration

use of com.xrtb.common.Configuration in project XRTB by benmfaul.

the class Config method setup.

public static void setup(String configFile) throws Exception {
    try {
        DbTools tools = new DbTools("localhost:3000");
        tools.clear();
        tools.loadDatabase("database.json");
        if (server == null) {
            server = new RTBServer(configFile);
            int wait = 0;
            while (!server.isReady() && wait < 10) {
                Thread.sleep(1000);
                wait++;
            }
            if (wait == 10) {
                fail("Server never started");
            }
            Thread.sleep(1000);
        } else {
            Configuration c = Configuration.getInstance();
            c.campaignsList.clear();
            User u = DataBaseObject.getInstance().get("ben");
            for (Campaign camp : u.campaigns) {
                c.addCampaign("ben", camp.adId);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : RTBServer(com.xrtb.bidder.RTBServer) User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) DbTools(com.xrtb.tools.DbTools)

Aggregations

Configuration (com.xrtb.common.Configuration)15 Campaign (com.xrtb.common.Campaign)7 RTBServer (com.xrtb.bidder.RTBServer)5 User (com.xrtb.db.User)5 DbTools (com.xrtb.tools.DbTools)5 SelectedCreative (com.xrtb.bidder.SelectedCreative)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 AbortableCountDownLatch (com.xrtb.bidder.AbortableCountDownLatch)1 CampaignProcessor (com.xrtb.bidder.CampaignProcessor)1 Creative (com.xrtb.common.Creative)1 BidRequest (com.xrtb.pojo.BidRequest)1 InputStream (java.io.InputStream)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1