Search in sources :

Example 1 with GoogleBidResponse

use of com.xrtb.exchanges.google.GoogleBidResponse 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 2 with GoogleBidResponse

use of com.xrtb.exchanges.google.GoogleBidResponse 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 3 with GoogleBidResponse

use of com.xrtb.exchanges.google.GoogleBidResponse 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)3 GoogleBidResponse (com.xrtb.exchanges.google.GoogleBidResponse)3 GoogleBidRequest (com.xrtb.exchanges.google.GoogleBidRequest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Scanner (java.util.Scanner)1