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();
}
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;
}
}
}
}
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;
}
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!");
}
Aggregations