Search in sources :

Example 46 with HttpPostGet

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

the class ReadInspectorLog method main.

public static void main(String[] args) throws Exception {
    BufferedReader br = null;
    br = new BufferedReader(new FileReader("/home/ben/bin/testdata"));
    String data = null;
    HttpPostGet hp = new HttpPostGet();
    while ((data = br.readLine()) != null) {
        data = data.replace("GOOD, DATA: ", "");
        BidRequest r = new BidRequest(new StringBuilder(data));
    }
}
Also used : BufferedReader(java.io.BufferedReader) HttpPostGet(com.xrtb.common.HttpPostGet) FileReader(java.io.FileReader) BidRequest(com.xrtb.pojo.BidRequest)

Example 47 with HttpPostGet

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

the class MaxLoad method run.

public void run() {
    while (true) {
        try {
            String rc = post.sendPost(url, content, 1000, 1000);
            url = "http://" + host + ":8080/rtb/bids/nexage";
            post = new HttpPostGet();
            count++;
        } catch (Exception e) {
        // TODO Auto-generated catch block
        }
    }
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet)

Example 48 with HttpPostGet

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

the class LoadAdx method main.

public static void main(String[] args) throws Exception {
    BufferedReader br = null;
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    String data = null;
    String fileName = null;
    boolean print = true;
    int count = -1;
    int timeout = 15000;
    String endPoint = "http://localhost:8080/rtb/bids/adx";
    int i = 0;
    while (i < args.length) {
        switch(args[i]) {
            case "-e":
                endPoint = args[i + 1];
                i += 2;
                break;
            case "-f":
                fileName = args[i + 1];
                i += 2;
                break;
            case "-p":
                print = Boolean.parseBoolean(args[i + 1]);
                i += 2;
                break;
            case "-c":
                count = Integer.parseInt(args[i + 1]);
                i += 2;
                break;
            case "-t":
                timeout = Integer.parseInt(args[i + 1]);
                timeout *= 1000;
                i += 2;
                break;
            case "-h":
            case "-help":
                System.out.println("Send bids to the Adx endpoint of RTB4FREE. Usage:\n");
                System.out.println("-h, -help          [This message                                                              ]");
                System.out.println("-c <number         [Send this many messages                                                   ]");
                System.out.println("-e <http endpoint> [Send the bid to this endpoint, default: http://localhost:8080/rtb/bids/adx]");
                System.out.println("-f <fileName>      [Use this file of canned bid requests.                                     ]");
                System.out.println("-p <boolean>       [Print the results. Default is true                                        ]");
                System.out.println("-t <seconds>       [Timeout and report error in seconds, default is 15                        ]");
                System.exit(1);
                break;
            default:
                System.out.println("Huh: " + args[i]);
                System.exit(0);
        }
    }
    if (fileName == null) {
        System.err.println("-f <fileName> is required");
        System.exit(1);
        ;
    }
    br = new BufferedReader(new FileReader(fileName));
    int k = 0;
    while ((data = br.readLine()) != null && k != count) {
        Map map = mapper.readValue(data, Map.class);
        String protobuf = (String) map.get("protobuf");
        if (map.get("feedback") == null) {
            byte[] protobytes = DatatypeConverter.parseBase64Binary(protobuf);
            try {
                HttpPostGet hp = new HttpPostGet();
                byte[] rets = hp.sendPost(endPoint, protobytes, timeout, timeout);
                if (print) {
                    AdxBidResponse r = new AdxBidResponse(rets);
                    System.out.println("-----------------------------------------");
                    System.out.println(r.getInternal());
                }
                if (count != -1)
                    k++;
            } catch (Exception error) {
                System.err.println(error.toString());
            }
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) HttpPostGet(com.xrtb.common.HttpPostGet) FileReader(java.io.FileReader) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AdxBidResponse(com.xrtb.exchanges.adx.AdxBidResponse)

Example 49 with HttpPostGet

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

the class TestWinProcessing method testWinProcessingInvalidHttp.

@Test
public void testWinProcessingInvalidHttp() throws Exception {
    HttpPostGet http = new HttpPostGet();
    // Make the bid
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    s = s.replaceAll("35c22289-06e2-48e9-a0cd-94aeb79fab4", "ADM#ssp#1023#56425#1490316943.792#68738174.223.128.39-1490316943883-130-0-0-6808053509727162318");
    if (s.indexOf("ADM#") == -1) {
        s = s.replaceAll("123", "ADM#ssp#1023#56425#1490316943.792#68738174.223.128.39-1490316943883-130-0-0-6808053509727162318");
    }
    /**
			 * Send the bid
			 */
    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();
    }
    /**
			 * Send the win notification
			 */
    try {
        String repl = bid.nurl.replaceAll("\\$", "");
        bid.nurl = repl.replace("{AUCTION_PRICE}", ".05");
        s = http.sendPost(bid.nurl, "", 300000, 300000);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    System.out.println("---->" + s);
    ;
    assertTrue(s.length() > 10);
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) Bid(com.xrtb.pojo.Bid) Test(org.junit.Test)

Example 50 with HttpPostGet

use of com.xrtb.common.HttpPostGet 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

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