Search in sources :

Example 1 with HttpPostGet

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

the class AdxStuff method mainx.

public static void mainx(String[] args) throws Exception {
    BufferedReader br = null;
    br = new BufferedReader(new FileReader("SampleBids/adx1.txt"));
    String data = br.readLine();
    byte[] protobytes = DatatypeConverter.parseBase64Binary(data);
    InputStream is = new ByteArrayInputStream(protobytes);
    HttpPostGet hp = new HttpPostGet();
    byte[] rets = hp.sendPost("http://localhost:8080/rtb/bids/adx", protobytes);
    AdxBidResponse r = new AdxBidResponse(rets);
    System.out.println(r.getInternal());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) HttpPostGet(com.xrtb.common.HttpPostGet) FileReader(java.io.FileReader) AdxBidResponse(com.xrtb.exchanges.adx.AdxBidResponse)

Example 2 with HttpPostGet

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

the class WebCampaign method getStatus.

/*
	 * Returns a status of all the members in
	 */
private List getStatus() throws Exception {
    String data = null;
    List core = new ArrayList();
    List<String> members = getMembers();
    // Sort the list
    Collections.sort(members);
    for (String member : members) {
        Map entry = new HashMap();
        HttpPostGet http = new HttpPostGet();
        Map values = new HashMap();
        if (member.equals(Configuration.getInstance().instanceName)) {
            RTBServer.getStatus();
            values.put("total", RTBServer.handled);
            values.put("bid", RTBServer.bid);
            values.put("request", RTBServer.request);
            values.put("nobid", RTBServer.nobid);
            values.put("win", RTBServer.win);
            values.put("clicks", RTBServer.clicks);
            values.put("pixels", RTBServer.pixels);
            values.put("fraud", RTBServer.fraud);
            values.put("errors", RTBServer.error);
            values.put("adspend", RTBServer.adspend);
            values.put("qps", RTBServer.qps);
            values.put("avgx", RTBServer.avgx);
            values.put("exchanges", BidRequest.getExchangeCounts());
            values.put("cperf", CampaignProcessor.probe.getMap());
        } else {
            values = Controller.getInstance().getMemberStatus(member);
        }
        entry.put("name", member);
        entry.put("values", values);
        core.add(entry);
    }
    return core;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HttpPostGet(com.xrtb.common.HttpPostGet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with HttpPostGet

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

the class WebCampaign method getSummary.

/**
	 * Return summary statistics of all the bidders known to the
	 * aerorpike/cache.
	 * 
	 * @return list. A list of maps that hold the summary stats info of all the
	 *         bidders.
	 * @throws Exception
	 *             On cache2k data.
	 */
private List getSummary() throws Exception {
    String data = null;
    List core = new ArrayList();
    List<String> members = getMembers();
    for (String member : members) {
        Map entry = new HashMap();
        HttpPostGet http = new HttpPostGet();
        Map values = new HashMap();
        if (member.equals(Configuration.getInstance().instanceName)) {
            values.put("stopped", RTBServer.stopped);
            values.put("ncampaigns", Configuration.getInstance().campaignsList.size());
            values.put("loglevel", Configuration.getInstance().logLevel);
            values.put("nobidreason", Configuration.getInstance().printNoBidReason);
        } else {
            Map info = Controller.getInstance().getMemberStatus(member);
            values.put("stopped", info.get("stopped"));
            values.put("ncampaigns", info.get("ncampaigns"));
            values.put("loglevel", info.get("loglevel"));
            values.put("nobidreason", info.get("nobidreason"));
        }
        entry.put("name", member);
        entry.put("values", values);
        core.add(entry);
    }
    return core;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HttpPostGet(com.xrtb.common.HttpPostGet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with HttpPostGet

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

the class XGeoStuff method main.

public static void main(String[] args) throws Exception {
    BufferedReader br = null;
    int percentWin = 80;
    int pixelPercent = 90;
    int clickPercent = 3;
    boolean forever = false;
    String fileName = "SampleBids/nexage.txt";
    String HOST = "localhost:8080";
    ObjectMapper mapper = new ObjectMapper();
    int numberOfBids = 1000;
    boolean silent = false;
    int sleepTime = 0;
    String exchange = "nexage";
    loadGeo();
    COUNT_MODE = true;
    int i = 0;
    while (i < args.length) {
        switch(args[i]) {
            case "-h":
                System.out.println("-file <filename>  [Set the file of the bid request(s) for the bidder, default SampleBids/nexage.txt]");
                System.out.println("-host <host:port> [Set the host:port for the bidder, default localhost:8080]");
                System.out.println("-win <n>          [Set the percentage to win, default 80]");
                System.out.println("-pixel <n>        [Set the percentage to pixel fires, default 90]");
                System.out.println("-click <n>        [Set the percentage to clicks, default 3]");
                System.out.println("-silent           [Don't show the transactions, default is to show them.");
                System.out.println("-count <n>        [Number of times to execute, default 1000000]");
                System.out.println("-forever          [loop on end of file on the file]");
            case "-file":
                fileName = args[i + 1];
                i += 2;
                break;
            case "-host":
                HOST = args[i + 1];
                i += 2;
                break;
            case "-exchange":
                exchange = args[i + 1];
                i += 2;
                break;
            case "-count":
                numberOfBids = Integer.parseInt(args[i + 1]);
                i += 2;
                break;
            default:
                System.err.println("HUH: " + args[i]);
                System.exit(1);
        }
    }
    HttpPostGet post = new HttpPostGet();
    String data = null;
    br = new BufferedReader(new FileReader(fileName));
    winnah = winnah.replaceAll("__HOST__", HOST);
    String bidURL = "http://" + HOST + "/rtb/bids/__EXCHANGE__";
    String winURL = "http://" + HOST + "/rtb/win/__EXCHANGE__/";
    String pixelURL = "http://" + HOST + "/" + pixel;
    String redirectURL = "http://" + HOST + ":8080" + redirect;
    redirectURL = redirectURL.replaceAll("__HOST__", HOST);
    bidURL = bidURL.replaceAll("__EXCHANGE__", exchange);
    String thisWinUrl = winURL;
    thisWinUrl = thisWinUrl.replaceAll("__EXCHANGE__", exchange);
    int requests = 0, error = 0, bids = 0, wins = 0, pixels = 0, clicks = 0, nobid = 0;
    BigDecimal bidCost = new BigDecimal(0), winCost = new BigDecimal(0);
    Random r = new Random();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    String bid = new String(Files.readAllBytes(Paths.get(fileName)), StandardCharsets.UTF_8);
    Map theBid = null;
    String hisBid = null;
    Map map = mapper.readValue(bid, Map.class);
    Map rets = randomize(map);
    double x = 0;
    for (i = 0; i < numberOfBids; i++) {
        String uuid = UUID.randomUUID().toString();
        try {
            String newBid = bid.replaceAll("35c22289-06e2-48e9-a0cd-94aeb79fab43", uuid);
            hisBid = post.sendPost(bidURL, newBid, 250, 250);
        } catch (Exception e) {
            error++;
            hisBid = null;
        }
        if (hisBid != null) {
            Map bidmap = mapper.readValue(hisBid, Map.class);
            List list = (List) bidmap.get("seatbid");
            bidmap = (Map) list.get(0);
            list = (List) bidmap.get("bid");
            theBid = (Map) list.get(0);
            x = (Double) theBid.get("price");
            bidCost = bidCost.add(new BigDecimal(x));
            bids++;
        } else
            nobid++;
        if (hisBid != null) {
            wins++;
            // (String)map.get("cost");
            String str = "" + x;
            BigDecimal wc = new BigDecimal(str);
            winCost = winCost.add(wc);
            rets.put("uuid", uuid);
            String theWin = makeWin(map, theBid, rets, wc.doubleValue());
            String rc = post.sendGet(thisWinUrl + theWin, 5000, 5000);
            if (rc == null || rc.length() == 0)
                System.err.println("Bad Win return");
        }
        System.out.println(i);
        requests++;
    }
    System.out.println("Requests = " + requests);
    System.out.println("Bids = " + bids);
    System.out.println("Nobids = " + nobid);
    System.out.println("Wins = " + wins);
    System.out.println("Pixels = " + pixels);
    System.out.println("Clicks = " + clicks);
    System.out.println("BID COST = " + bidCost);
    System.out.println("WIN COST = " + winCost);
    System.out.println("Errors: " + error);
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) BigDecimal(java.math.BigDecimal) Random(java.util.Random) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with HttpPostGet

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

the class TestSmaato method testBannerRespondWithBid.

/**
	 * Test a valid bid response.
	 * 
	 * @throws Exception
	 *             on networking errors.
	 */
//@Test
public void testBannerRespondWithBid() throws Exception {
    HttpPostGet http = new HttpPostGet();
    String xtime = null;
    long time = 0;
    try {
        String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/smaato.json")))).toString();
        try {
            time = System.currentTimeMillis();
            s = http.sendPost("http://" + Config.testHost + "/rtb/bids/smaato?testbid=bid", s);
            time = System.currentTimeMillis() - time;
            xtime = http.getHeader("X-TIME");
        } catch (Exception error) {
            fail("Can't connect to test host: " + Config.testHost);
        }
        Map m = null;
        try {
            m = DbTools.mapper.readValue(s, Map.class);
            System.out.println(DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(m));
        } catch (Exception error) {
            System.out.println("\\n\n\n\n" + s + "\n\n\n\n");
            fail("Bad JSON for bid");
        }
        List list = (List) m.get("seatbid");
        m = (Map) list.get(0);
        assertNotNull(m);
        String test = (String) m.get("seat");
        assertTrue(test.equals("seat1"));
        list = (List) m.get("bid");
        assertEquals(list.size(), 1);
        m = (Map) list.get(0);
        assertNotNull(m);
        test = (String) m.get("impid");
        assertTrue(test.equals("image-test"));
        test = (String) m.get("id");
        assertTrue(test.equals("K6t8sXXYdM"));
        double d = (Double) m.get("price");
        assertTrue(d == 1.0);
        test = (String) m.get("adid");
        assertTrue(test.equals("smaato-test"));
        list = (List) m.get("adomain");
        test = (String) list.get(0);
        assertTrue(test.equals("originator.com"));
        System.out.println("XTIME: " + xtime);
        System.out.println("RTTIME: " + time);
        System.out.println(s);
        assertFalse(s.contains("pub"));
        assertFalse(s.contains("ad_id"));
        assertFalse(s.contains("bid_id"));
        assertFalse(s.contains("site_id"));
        String adm = (String) m.get("adm");
        System.out.println(URLDecoder.decode(adm));
        System.out.println("\n\n\n" + SmaatoTemplate.IMAGEAD_TEMPLATE);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) List(java.util.List) Map(java.util.Map)

Aggregations

HttpPostGet (com.xrtb.common.HttpPostGet)57 Test (org.junit.Test)40 Map (java.util.Map)24 List (java.util.List)13 Bid (com.xrtb.pojo.Bid)9 BufferedReader (java.io.BufferedReader)7 FileReader (java.io.FileReader)7 HashMap (java.util.HashMap)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 StringReader (java.io.StringReader)5 ArrayList (java.util.ArrayList)5 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 InputSource (org.xml.sax.InputSource)5 GoogleBidResponse (com.xrtb.exchanges.google.GoogleBidResponse)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Campaign (com.xrtb.common.Campaign)2 Creative (com.xrtb.common.Creative)2 AdxBidResponse (com.xrtb.exchanges.adx.AdxBidResponse)2 GoogleBidRequest (com.xrtb.exchanges.google.GoogleBidRequest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2