Search in sources :

Example 1 with Creative

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

the class Stroer method buildNewBidResponse.

@Override
public BidResponse buildNewBidResponse(Impression imp, List<SelectedCreative> multi, int xtime) throws Exception {
    String avr = null;
    String avn = null;
    BidResponse response = new BidResponse(this, imp, multi, xtime);
    StringBuilder sb = response.getResponseBuffer();
    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 Stroer SSP");
        avr = c.extensions.get("avr");
        avn = c.extensions.get("avn");
        if (avr == null || avn == null)
            throw new Exception(x.getCampaign().adId + "/" + c.impid + " is missing required avn or avr extension for Stroer SSP");
        String rets = getExtension(avr, avn);
        int index = sb.indexOf("\"crid");
        if (index < 0)
            throw new Exception("Could not insert extension, response missing a crid");
        sb.insert(index, rets);
    }
    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 2 with Creative

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

the class TestWinProcessing method testCappingTimes1.

@Test
public void testCappingTimes1() 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 = 1;
                    break;
                }
            }
        }
    }
    HttpPostGet http = new HttpPostGet();
    String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage50x50.txt")))).toString();
    // Get 1 time is ok, but 2d time 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");
    System.out.println(win.nurl);
    s = http.sendPost(win.nurl, "", 30000, 30000);
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("1"));
    // 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("1"));
    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)

Example 3 with Creative

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

the class CampaignProcessor method run.

public void run() {
    boolean printNoBidReason = Configuration.getInstance().printNoBidReason;
    int logLevel = 5;
    StringBuilder err = null;
    if (printNoBidReason || br.id.equals("123") || probe != null) {
        err = new StringBuilder();
        printNoBidReason = true;
        if (br.id.equals("123"))
            logLevel = 1;
    }
    if (flag != null) {
        try {
            flag.await();
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            if (latch != null)
                latch.countNull();
            done = true;
            return;
        }
    }
    /**
		 * See if there is a creative that matches first
		 */
    if (camp == null) {
        if (latch != null)
            latch.countNull();
        done = true;
        return;
    }
    Node n = null;
    try {
        for (int i = 0; i < camp.attributes.size(); i++) {
            n = camp.attributes.get(i);
            if (n.test(br) == false) {
                if (printNoBidReason)
                    if (probe != null) {
                        probe.process(br.getExchange(), camp.adId, "Global", new StringBuilder(n.hierarchy));
                    }
                if (logLevel == 1)
                    Controller.getInstance().sendLog(logLevel, "CampaignProcessor:run:attribute-failed", camp.adId + ": " + n.hierarchy + " doesn't match the bidrequest");
                done = true;
                if (latch != null)
                    latch.countNull();
                selected = null;
                return;
            }
        }
    } catch (Exception error) {
        System.out.println("-----------> Campaign: " + camp.adId + ", ERROR IN NODE: " + n.name + ", Hierarchy = " + n.hierarchy);
        System.out.println(br.toString());
        error.printStackTrace();
        selected = null;
        done = true;
        if (latch != null)
            latch.countNull();
        return;
    }
    // rec.add("nodes");
    ///////////////////////////
    Map<String, String> capSpecs = new ConcurrentHashMap();
    List<Creative> creatives = new ArrayList(camp.creatives);
    Collections.shuffle(creatives);
    StringBuilder xerr = new StringBuilder();
    for (Creative create : creatives) {
        if ((selected = create.process(br, capSpecs, camp.adId, err, probe)) != null) {
            break;
        } else {
            if (probe != null) {
                probe.process(br.getExchange(), camp.adId, create.impid, err);
                if (printNoBidReason) {
                    xerr.append(camp.adId);
                    xerr.append("/");
                    xerr.append(create.impid);
                    xerr.append(" ===> ");
                    xerr.append(err);
                    xerr.append("\n");
                }
                err.setLength(0);
            }
        }
    }
    probe.incrementTotal(br.getExchange(), camp.adId);
    err = xerr;
    if (selected == null) {
        if (latch != null)
            latch.countNull();
        if (printNoBidReason)
            try {
                Controller.getInstance().sendLog(logLevel, "CampaignProcessor:run:campaign:nothing matches", err.toString());
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        done = true;
        if (err != null)
            err.setLength(0);
        return;
    }
    if (printNoBidReason) {
        String str = "";
        str += selected.impid + " ";
        try {
            Controller.getInstance().sendLog(logLevel, "CampaignProcessor:run:campaign:is-candidate", camp.adId + ", creatives = " + str);
        } catch (Exception error) {
            error.printStackTrace();
        }
    }
    selected.capSpec = capSpecs.get(selected.creative.impid);
    try {
        if (printNoBidReason && logLevel == 1) {
            Controller.getInstance().sendLog(logLevel, "CampaignProcessor:run:campaign:no match: ", err.toString());
        }
    } catch (Exception error) {
        error.printStackTrace();
    }
    if (latch != null)
        latch.countDown(selected);
    if (probe != null) {
        probe.process(br.getExchange(), camp.adId, selected.impid);
    }
    selected.campaign = this.camp;
    probe.incrementBid(br.getExchange(), camp.adId);
    done = true;
}
Also used : Creative(com.xrtb.common.Creative) Node(com.xrtb.common.Node) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with Creative

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

the class CampaignSelector method getSpecific.

/**
	 * Creates a forced bid response on the specified bid request. owner,
	 * campaign and creative.
	 * 
	 * @param br
	 *            BidRequest. The request from the exchange.
	 * @param owner
	 *            String. The account owner of the campaign.
	 * @param campaignName
	 *            String. The campaign adid.
	 * @param creativeName
	 *            String. The creative id in the campaign.
	 * @return BidResponse. The response from the
	 */
public BidResponse getSpecific(BidRequest br, String owner, String campaignName, String creativeName) throws Exception {
    long xtime = System.currentTimeMillis();
    Campaign camp = null;
    Creative creative = null;
    for (Campaign c : config.campaignsList) {
        if (c.owner.equals(owner) && c.adId.equals(campaignName)) {
            camp = c;
            break;
        }
    }
    if (camp == null) {
        System.out.println("Can't find specification " + owner + "/" + campaignName);
        return null;
    }
    for (Creative cr : camp.creatives) {
        if (cr.impid.equals(creativeName)) {
            creative = cr;
            break;
        }
    }
    if (creative == null) {
        System.out.println("Can't find creative " + creative + " for " + owner + "/" + campaignName);
        return null;
    }
    String h = creative.strH;
    String w = creative.strW;
    int oldH = creative.h;
    int oldW = creative.w;
    Impression imp = br.getImpression(0);
    creative.strW = "" + imp.w;
    creative.strH = "" + imp.h;
    creative.w = imp.w;
    creative.h = imp.h;
    try {
        for (int i = 0; i < camp.attributes.size(); i++) {
            Node n = camp.attributes.get(i);
            if (n.test(br) == false) {
                if (Configuration.getInstance().printNoBidReason)
                    Controller.getInstance().sendLog(5, "CampaignProcessor:run:attribute-failed", camp.adId + "/" + creative.impid + ": " + n.hierarchy + " doesn't match the bidrequest");
                creative.strH = h;
                creative.strW = w;
                creative.w = oldW;
                creative.h = oldH;
                // don't bid
                return null;
            }
        }
    } catch (Exception error) {
        error.printStackTrace();
    }
    xtime = System.currentTimeMillis() - xtime;
    BidResponse winner = br.buildNewBidResponse(imp, camp, creative, creative.price, null, (int) xtime);
    creative.strH = h;
    creative.strW = w;
    creative.w = oldW;
    creative.h = oldH;
    return winner;
}
Also used : Campaign(com.xrtb.common.Campaign) Creative(com.xrtb.common.Creative) Node(com.xrtb.common.Node) Impression(com.xrtb.pojo.Impression) BidResponse(com.xrtb.pojo.BidResponse)

Example 5 with Creative

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

the class WebCampaign method showCreative.

/**
	 * Creates a sample output from a campaign creative.
	 * 
	 * @param m
	 *            Map. The command parameters.
	 * @return String. The JSON encoded return from the command.
	 * @throws Exception
	 *             on aerorpike/cache2k errors.
	 */
public String showCreative(Map m) throws Exception {
    Map rets = new HashMap();
    rets.put("creative", "YOU ARE HERE");
    String adid = (String) m.get("adid");
    String crid = (String) m.get("impid");
    String user = (String) m.get("name");
    for (Campaign campaign : Configuration.getInstance().campaignsList) {
        if (campaign.owner.equals(user) && campaign.adId.equals(adid)) {
            for (Creative c : campaign.creatives) {
                if (c.impid.equals(crid)) {
                    rets.put("creative", c.createSample(campaign));
                    return getString(rets);
                }
            }
        }
    }
    rets.put("creative", "No such creative");
    return getString(rets);
}
Also used : Campaign(com.xrtb.common.Campaign) AddCampaign(com.xrtb.commands.AddCampaign) DeleteCampaign(com.xrtb.commands.DeleteCampaign) Creative(com.xrtb.common.Creative) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

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