Search in sources :

Example 11 with HttpPostGet

use of com.xrtb.common.HttpPostGet 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);
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) ArrayList(java.util.ArrayList) WinObject(com.xrtb.pojo.WinObject) CountDownLatch(java.util.concurrent.CountDownLatch) BidResponse(com.xrtb.pojo.BidResponse) Bid(com.xrtb.pojo.Bid) Test(org.junit.Test)

Example 12 with HttpPostGet

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

the class MyReader method testGoogleProtobufBanner.

/**
	 * Test a valid bid response.
	 * 
	 * @throws Exception
	 *             on networking errors.
	 */
//@Test
public void testGoogleProtobufBanner() throws Exception {
    HttpPostGet http = new HttpPostGet();
    GoogleBidRequest google = GoogleBidRequest.fromRTBFile("./SampleBids/nexage.txt");
    byte[] protobytes = google.getInternal().toByteArray();
    byte[] returns = http.sendPost("http://" + Config.testHost + "/rtb/bids/google", protobytes, 300000, 300000);
    int code = http.getResponseCode();
    assertTrue(code == 200);
    assertNotNull(returns);
    GoogleBidResponse rr = new GoogleBidResponse(returns);
    System.out.println(rr.getInternal());
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) GoogleBidRequest(com.xrtb.exchanges.google.GoogleBidRequest) GoogleBidResponse(com.xrtb.exchanges.google.GoogleBidResponse)

Example 13 with HttpPostGet

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

the class MyReader method testGoogleProtobufVideo.

//@Test
public void testGoogleProtobufVideo() throws Exception {
    HttpPostGet http = new HttpPostGet();
    GoogleBidRequest google = GoogleBidRequest.fromRTBFile("./SampleBids/nexage.txt");
    byte[] protobytes = google.getInternal().toByteArray();
    byte[] returns = http.sendPost("http://" + Config.testHost + "/rtb/bids/google", protobytes, 300000, 300000);
    int code = http.getResponseCode();
    assertTrue(code == 200);
    assertNotNull(returns);
    GoogleBidResponse rr = new GoogleBidResponse(returns);
    System.out.println(rr.getInternal());
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) GoogleBidRequest(com.xrtb.exchanges.google.GoogleBidRequest) GoogleBidResponse(com.xrtb.exchanges.google.GoogleBidResponse)

Example 14 with HttpPostGet

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

the class MyReader method testGoogleDecrypt.

@Test
public void testGoogleDecrypt() throws Exception {
    String payload = "http://localhost:8080/rtb/win/google/WP5SPgAE9TEKDFtHAAnnOm9LuUuqG14LOdRXXQ/0.0/0.0/55/87/WPfq6wABDYsKUaXKwgwIUw";
    HttpPostGet http = new HttpPostGet();
    http.sendGet(payload, 300000, 300000);
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) Test(org.junit.Test)

Example 15 with HttpPostGet

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

the class LoadGoogle 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 = "SampleBids/google.txt";
    boolean print = true;
    int count = -1;
    boolean step = false;
    int timeout = 300000;
    String endPoint = "http://localhost:8080/rtb/bids/google";
    Scanner sc = null;
    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 "-s":
                sc = new Scanner(System.in);
                step = true;
                i++;
                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("-s                 [step one message                                                          ]");
                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) {
            if (step) {
                System.out.println(protobuf);
                System.out.print("\nSTEP>");
                sc.nextLine();
            }
            byte[] protobytes = DatatypeConverter.parseBase64Binary(protobuf);
            try {
                HttpPostGet hp = new HttpPostGet();
                byte[] rets = hp.sendPost(endPoint, protobytes, timeout, timeout);
                if (print) {
                    if (rets == null) {
                        System.out.println("*** NO BID ****");
                    } else {
                        GoogleBidResponse r = new GoogleBidResponse(rets);
                        System.out.println("-----------------------------------------");
                        System.out.println(r.getInternal());
                    }
                    System.out.println("Next bid will be:");
                }
                if (count != -1)
                    k++;
            } catch (Exception error) {
                System.err.println(error.toString());
            }
        }
    }
}
Also used : Scanner(java.util.Scanner) 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) GoogleBidResponse(com.xrtb.exchanges.google.GoogleBidResponse)

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