Search in sources :

Example 1 with AdxBidResponse

use of com.xrtb.exchanges.adx.AdxBidResponse 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 AdxBidResponse

use of com.xrtb.exchanges.adx.AdxBidResponse 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)

Aggregations

HttpPostGet (com.xrtb.common.HttpPostGet)2 AdxBidResponse (com.xrtb.exchanges.adx.AdxBidResponse)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1