use of com.xrtb.pojo.BidResponse 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;
}
use of com.xrtb.pojo.BidResponse in project XRTB by benmfaul.
the class AddShutdownHook method smaatoCompliance.
private void smaatoCompliance(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response, InputStream body) throws Exception {
String tester = null;
String json = null;
BidRequest br = null;
Enumeration<String> params = request.getParameterNames();
if (params.hasMoreElements()) {
String[] dobid = request.getParameterValues(params.nextElement());
tester = dobid[0];
System.out.println("=================> SMAATO TEST ====================");
}
if (tester == null) {
System.out.println(" Nothing to Test");
return;
}
if (tester.equals("nobid")) {
RTBServer.nobid++;
baseRequest.setHandled(true);
response.setStatus(RTBServer.NOBID_CODE);
response.getWriter().println("");
Controller.getInstance().sendLog(1, "Handler:handle", "SMAATO NO BID TEST ENDPOINT REACHED");
Controller.getInstance().sendNobid(new NobidResponse(br.id, br.getExchange()));
return;
} else {
BidRequest x = RTBServer.exchanges.get(target);
x.setExchange("nexage");
br = x.copy(body);
Controller.getInstance().sendRequest(br, false);
Controller.getInstance().sendLog(1, "Handler:handle", "SMAATO MANDATORY BID TEST ENDPOINT REACHED");
BidResponse bresp = null;
// if (RTBServer.strategy == Configuration.STRATEGY_HEURISTIC)
// bresp = CampaignSelector.getInstance().getHeuristic(br); // 93%
// time
// here
// else
bresp = CampaignSelector.getInstance().getMaxConnections(br);
// log.add("select");
if (bresp == null) {
baseRequest.setHandled(true);
response.setStatus(RTBServer.NOBID_CODE);
response.getWriter().println("");
Controller.getInstance().sendLog(1, "Handler:handle", "SMAATO FORCED BID TEST ENDPOINT FAILED");
Controller.getInstance().sendNobid(new NobidResponse(br.id, br.getExchange()));
return;
}
json = bresp.toString();
baseRequest.setHandled(true);
Controller.getInstance().sendBid(br, bresp);
Controller.getInstance().recordBid(bresp);
RTBServer.bid++;
response.setStatus(RTBServer.BID_CODE);
response.getWriter().println(json);
System.out.println("+++++++++++++++++++++ SMAATO REQUEST ++++++++++++++++++++++\n\n" + br.toString() + "\n\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("===================== SMAATO BID ==========================\n\n" + json + "\n\n==========================================================");
Controller.getInstance().sendLog(1, "Handler:handle", "SMAATO FORCED BID TEST ENDPOINT REACHED OK");
return;
}
/************************************************************************************/
}
use of com.xrtb.pojo.BidResponse in project XRTB by benmfaul.
the class Spark method initialize.
/**
* Get the message handlers lashed up to handle all the accounting
* information.
*/
public void initialize() throws Exception {
// Instantiate your own logger if you
logger = new FileLogger(INTERVAL);
// don't want to log to files.
/**
* Win Notifications HERE
*/
String address = getAddress(zeromq, WINCHANNEL);
RTopic winners = new RTopic(address);
winners.addListener(new MessageListener<WinObject>() {
@Override
public void onMessage(String channel, WinObject msg) {
try {
processWin(msg);
} catch (Exception error) {
error.printStackTrace();
}
}
});
System.out.println("Ok Spark is running!");
address = getAddress(zeromq, BIDCHANNEL);
RTopic bidresponse = new RTopic(address);
bidresponse.addListener(new MessageListener<BidResponse>() {
@Override
public void onMessage(String channel, BidResponse msg) {
try {
processBid(msg);
} catch (Exception error) {
error.printStackTrace();
}
}
});
address = getAddress(zeromq, CLICKCHANNEL);
RTopic pixelandclicks = new RTopic(address);
pixelandclicks.addListener(new MessageListener<Object>() {
@Override
public void onMessage(String channel, Object msg) {
try {
processClickAndPixel(msg);
} catch (Exception error) {
error.printStackTrace();
}
}
});
}
use of com.xrtb.pojo.BidResponse in project XRTB by benmfaul.
the class TestWinProcessing method testNegative.
@Test
public void testNegative() throws Exception {
HttpPostGet http = new HttpPostGet();
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch wlatch = new CountDownLatch(1);
final List<Double> price = new ArrayList();
String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/negative.txt")))).toString();
com.xrtb.jmq.RTopic channel = new com.xrtb.jmq.RTopic("tcp://*:5571&bids");
channel.subscribe("bids");
channel.addListener(new com.xrtb.jmq.MessageListener<BidResponse>() {
@Override
public void onMessage(String channel, BidResponse bid) {
price.add(bid.cost);
System.out.println("BID COST: " + bid.cost);
latch.countDown();
}
});
com.xrtb.jmq.RTopic wchannel = new com.xrtb.jmq.RTopic("tcp://*:5572&wins");
wchannel.subscribe("wins");
wchannel.addListener(new com.xrtb.jmq.MessageListener<WinObject>() {
@Override
public void onMessage(String channel, WinObject win) {
;
price.add(new Double(win.price));
price.add(new Double(win.cost));
wlatch.countDown();
}
});
/**
* Send the bid request
*/
try {
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s, 3000000, 3000000);
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
int code = http.getResponseCode();
assertTrue(code == 200);
Bid bid = null;
System.out.println(s);
try {
bid = new Bid(s);
} catch (Exception error) {
error.printStackTrace();
fail();
}
assertEquals(bid.price, 1.1, .001);
/**
* Send the win notification
*/
try {
price.clear();
String repl = bid.nurl.replaceAll("\\$", "");
bid.nurl = repl.replace("{AUCTION_PRICE}", Double.toString(bid.price));
s = http.sendPost(bid.nurl, "", 300000, 300000);
} catch (Exception error) {
error.printStackTrace();
fail();
}
long time = 5;
assertTrue(s.length() > 10);
wlatch.await(time, TimeUnit.SECONDS);
assertTrue(price.get(0) == 1.1);
System.out.println("xxxxxx: " + price.get(1));
assertTrue(price.get(1) == 1.1);
}
use of com.xrtb.pojo.BidResponse in project XRTB by benmfaul.
the class TestSpark method transmit.
public void transmit() throws Exception {
String crid = "111";
WinObject obj = new WinObject();
obj.cost = ".001";
obj.price = ".001";
obj.adId = "123";
obj.cridId = crid;
BidResponse br = new BidResponse();
br.adid = "123";
br.crid = crid;
br.cost = .001;
PixelClickConvertLog cmd = new PixelClickConvertLog();
cmd.ad_id = "123";
cmd.creative_id = crid;
ZPublisher wins = new ZPublisher("tcp://*:5572", "wins");
ZPublisher bids = new ZPublisher("tcp://*:5571", "bids");
ZPublisher clicks = new ZPublisher("tcp://*:5573", "clicks");
for (int j = 0; j < 1000; j++) {
wins.add(obj);
bids.add(br);
cmd.type = PixelClickConvertLog.CLICK;
clicks.add(cmd);
cmd.type = PixelClickConvertLog.PIXEL;
clicks.add(cmd);
}
}
Aggregations