Search in sources :

Example 6 with Creative

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

the class BidRequest method compile.

/**
	 * Take the union of all campaign attributes and place them into the static
	 * mapp. This way the JSON is queried once and the query becomes the key,
	 * and the JSON value becomes the map value. With multiple campaigns it is
	 * important to not be traversing the JSON tree for each campaign.
	 * 
	 * The compiled attributes are stored in mapp. In setup, the compiled list
	 * of key/values is then put in the 'database' object for the bidrequest.
	 */
public static synchronized void compile() throws Exception {
    RTB4FREE = false;
    /**
		 * Stop the bidder, if it is running
		 */
    stopBidder();
    keys.clear();
    mapp.clear();
    List<Campaign> list = Configuration.getInstance().campaignsList;
    for (int i = 0; i < list.size(); i++) {
        Campaign c = list.get(i);
        Controller.getInstance().sendLog(5, "BidRequest:compile", ("Compiling for domain: : " + c.adomain));
        for (int j = 0; j < c.attributes.size(); j++) {
            Node node = c.attributes.get(j);
            if (mapp.containsKey(keys) == false) {
                Controller.getInstance().sendLog(5, "BidRequest:compile", ("Compile unit: " + c.adomain + ":" + node.hierarchy) + ", values: " + node.bidRequestValues);
                if (node.hierarchy.equals("") == false) {
                    keys.add(node.hierarchy);
                    mapp.put(node.hierarchy, node.bidRequestValues);
                } else {
                    if (node.operator != Node.OR) {
                        startBidder();
                        throw new Exception("Malformed OR processing in campaign " + c.adId);
                    }
                    List<Node> nodes = (List<Node>) node.value;
                    for (int nc = 0; nc < nodes.size(); nc++) {
                        Object x = nodes.get(nc);
                        Node n = null;
                        if (x instanceof LinkedHashMap) {
                            Map map = (Map) x;
                            n = new Node(map);
                        } else
                            n = (Node) x;
                        n.setValues();
                        if (mapp.get(n.hierarchy) == null) {
                            keys.add(n.hierarchy);
                            mapp.put(n.hierarchy, n.bidRequestValues);
                        }
                    }
                }
            }
        }
        for (Creative creative : c.creatives) {
            // Handle creative specific
            // attributes
            Controller.getInstance().sendLog(5, "BidRequest:compile", "Compiling creatives for: " + c.adomain + ":" + creative.impid);
            for (Node node : creative.attributes) {
                if (mapp.containsKey(keys) == false) {
                    Controller.getInstance().sendLog(5, "BidRequest:compile", ("Compile unit: " + c.adomain + ":" + creative.impid + ":" + node.hierarchy) + ", values: " + node.bidRequestValues);
                    if (mapp.get(node.hierarchy) == null) {
                        keys.add(node.hierarchy);
                        mapp.put(node.hierarchy, node.bidRequestValues);
                    }
                }
            }
            // Now frequency caps */
            if (creative.capSpecification != null) {
                String spec = creative.capSpecification;
                if (mapp.containsKey(spec) == false) {
                    addMap(spec);
                }
            }
        }
    }
    compileBuiltIns();
    /**
		 * Restart the bidder
		 */
    startBidder();
}
Also used : Campaign(com.xrtb.common.Campaign) Creative(com.xrtb.common.Creative) SelectedCreative(com.xrtb.bidder.SelectedCreative) IntNode(com.fasterxml.jackson.databind.node.IntNode) Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with Creative

use of com.xrtb.common.Creative 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 8 with Creative

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

the class Appnexus method buildNewBidResponse.

@Override
public BidResponse buildNewBidResponse(Impression imp, List<SelectedCreative> multi, int xtime) throws Exception {
    for (int i = 0; i < multi.size(); i++) {
        SelectedCreative x = multi.get(i);
        Creative c = x.getCreative();
        if (c.extensions == null || c.extensions.size() == 0)
            throw new Exception(x.getCampaign().adId + "/" + c.impid + " is missing required extensions for Appnexus SSP");
        String adid = c.extensions.get("appnexus_crid");
        if (adid == null)
            adid = "invalid:unassigned";
        c.alternateAdId = adid;
    }
    BidResponse response = new BidResponse(this, imp, multi, xtime);
    StringBuilder sb = response.getResponseBuffer();
    return response;
}
Also used : Creative(com.xrtb.common.Creative) SelectedCreative(com.xrtb.bidder.SelectedCreative) SelectedCreative(com.xrtb.bidder.SelectedCreative) BidResponse(com.xrtb.pojo.BidResponse)

Example 9 with Creative

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

the class TestWinProcessing method testCappingTimes3.

/**
	   * Test a valid bid response with no bid, the campaign doesn't match width or height of the bid request
	   * @throws Exception on network errors.
	   */
@Test
public void testCappingTimes3() throws Exception {
    redisson.del("capped_blocker166.137.138.18");
    for (Campaign c : Configuration.getInstance().campaignsList) {
        if (c.adId.equals("ben:payday")) {
            for (Creative cc : c.creatives) {
                if (cc.impid.equals("blocker")) {
                    cc.capFrequency = 3;
                    break;
                }
            }
        }
    }
    HttpPostGet http = new HttpPostGet();
    String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage50x50.txt")))).toString();
    // Get 3 times is ok, but 4th is a no bid
    String s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    assertNotNull(s);
    int rc = http.getResponseCode();
    assertTrue(rc == 200);
    String value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value == null);
    Bid win = new Bid(s);
    String repl = win.nurl.replaceAll("\\$", "");
    win.nurl = repl.replace("{AUCTION_PRICE}", ".05");
    s = http.sendPost(win.nurl, "");
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("1"));
    s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    assertNotNull(s);
    rc = http.getResponseCode();
    assertTrue(rc == 200);
    s = http.sendPost(win.nurl, "");
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("2"));
    s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    assertNotNull(s);
    rc = http.getResponseCode();
    assertTrue(rc == 200);
    s = http.sendPost(win.nurl, "");
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("3"));
    // better no bid.
    s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    rc = http.getResponseCode();
    assertTrue(rc == 204);
    assertNull(s);
    rc = http.getResponseCode();
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("3"));
    System.out.println("DONE!");
}
Also used : Campaign(com.xrtb.common.Campaign) Creative(com.xrtb.common.Creative) HttpPostGet(com.xrtb.common.HttpPostGet) Bid(com.xrtb.pojo.Bid) Test(org.junit.Test)

Aggregations

Creative (com.xrtb.common.Creative)9 Campaign (com.xrtb.common.Campaign)6 SelectedCreative (com.xrtb.bidder.SelectedCreative)4 Node (com.xrtb.common.Node)3 BidResponse (com.xrtb.pojo.BidResponse)3 Test (org.junit.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)2 HttpPostGet (com.xrtb.common.HttpPostGet)2 Bid (com.xrtb.pojo.Bid)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)1 IntNode (com.fasterxml.jackson.databind.node.IntNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 AddCampaign (com.xrtb.commands.AddCampaign)1 DeleteCampaign (com.xrtb.commands.DeleteCampaign)1 Configuration (com.xrtb.common.Configuration)1