Search in sources :

Example 1 with Configuration

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

the class AppnexusBidResponse method makeResponse.

/**
	 * Makes the RTB bid response's JSON response and URL.
	 */
@Override
public void makeResponse(double price) throws Exception {
    /** Set the response type ****************/
    if (imp.nativead)
        this.adtype = "native";
    else if (imp.video != null)
        this.adtype = "video";
    else
        this.adtype = "banner";
    /******************************************/
    /** The configuration used for generating this response */
    Configuration config = Configuration.getInstance();
    StringBuilder nurl = new StringBuilder();
    StringBuilder linkUrlX = new StringBuilder();
    linkUrlX.append(config.redirectUrl);
    linkUrlX.append("/");
    linkUrlX.append(oidStr.replaceAll("#", "%23"));
    linkUrlX.append("/?url=");
    if (br.lat != null)
        lat = br.lat.doubleValue();
    if (br.lon != null)
        lon = br.lon.doubleValue();
    seat = br.getExchange();
    snurl = new StringBuilder(config.winUrl);
    snurl.append("/");
    snurl.append(br.getExchange());
    snurl.append("/");
    // to get the win price back from the
    snurl.append("${AUCTION_PRICE}");
    // Exchange....
    snurl.append("/");
    snurl.append(lat);
    snurl.append("/");
    snurl.append(lon);
    snurl.append("/");
    snurl.append(adid);
    snurl.append("/");
    snurl.append(creat.impid);
    snurl.append("/");
    snurl.append(oidStr.replaceAll("#", "%23"));
    response = new StringBuilder("{\"seatbid\":[{\"seat\":\"");
    response.append(Configuration.getInstance().seats.get(exchange));
    response.append("\",\"group\":0,");
    response.append("\"bid\":[{\"impid\":\"");
    // the impression id from the request
    response.append(impid);
    response.append("\",\"id\":\"");
    // the request bid id
    response.append(br.id);
    response.append("\"");
    if (creat.currency != null && creat.currency.length() != 0) {
        // fyber
        // uses
        // this,
        // but
        // is
        // not
        // standard.
        response.append(",");
        response.append("\"cur\":\"");
        response.append(creat.currency);
        response.append("\"");
    }
    response.append(",\"price\":");
    response.append(price);
    response.append(",\"adid\":\"");
    if (creat.alternateAdId == null)
        response.append(adid);
    else
        response.append(creat.alternateAdId);
    response.append("\",\"nurl\":\"");
    response.append(snurl);
    response.append("\",\"cid\":\"");
    response.append(adid);
    response.append("\",\"crid\":\"");
    response.append(creat.impid);
    if (dealId != null) {
        response.append("\",\"dealid\":\"");
        response.append(dealId);
    }
    response.append("\",\"iurl\":\"");
    response.append(imageUrl);
    response.append("\",\"adomain\": [\"");
    response.append(camp.adomain);
    response.append("\"]");
    // Does not use the ADM field.
    response.append("}]}],");
    response.append("\"id\":\"");
    // backwards?
    response.append(oidStr);
    response.append("\",\"bidid\":\"");
    response.append(br.id);
    response.append("\",\"cur\":\"");
    response.append(creat.cur);
    response.append("\"}");
    // pass this along so the bid response object
    this.cost = price;
    // has a copy of the price
    macroSubs(response);
}
Also used : Configuration(com.xrtb.common.Configuration)

Example 2 with Configuration

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

the class BidResponse method makeResponse.

/**
	 * Makes the RTB bid response's JSON response and URL.
	 */
public void makeResponse(double price) throws Exception {
    /** Set the response type ****************/
    if (imp.nativead)
        this.adtype = "native";
    else if (imp.video != null)
        this.adtype = "video";
    else
        this.adtype = "banner";
    /******************************************/
    /** The configuration used for generating this response */
    Configuration config = Configuration.getInstance();
    StringBuilder nurl = new StringBuilder();
    StringBuilder linkUrlX = new StringBuilder();
    linkUrlX.append(config.redirectUrl);
    linkUrlX.append("/");
    linkUrlX.append(oidStr.replaceAll("#", "%23"));
    linkUrlX.append("/?url=");
    if (br.lat != null)
        lat = br.lat.doubleValue();
    if (br.lon != null)
        lon = br.lon.doubleValue();
    seat = br.getExchange();
    snurl = new StringBuilder(config.winUrl);
    snurl.append("/");
    snurl.append(br.getExchange());
    snurl.append("/");
    // to get the win price back from the
    snurl.append("${AUCTION_PRICE}");
    // Exchange....
    snurl.append("/");
    snurl.append(lat);
    snurl.append("/");
    snurl.append(lon);
    snurl.append("/");
    snurl.append(adid);
    snurl.append("/");
    snurl.append(creat.impid);
    snurl.append("/");
    snurl.append(oidStr.replaceAll("#", "%23"));
    response = new StringBuilder("{\"seatbid\":[{\"seat\":\"");
    response.append(Configuration.getInstance().seats.get(exchange));
    response.append("\",");
    response.append("\"bid\":[{\"impid\":\"");
    // the impression id from the request
    response.append(impid);
    response.append("\",\"id\":\"");
    // the request bid id
    response.append(br.id);
    response.append("\"");
    if (creat.currency != null && creat.currency.length() != 0) {
        // fyber
        // uses
        // this,
        // but
        // is
        // not
        // standard.
        response.append(",");
        response.append("\"cur\":\"");
        response.append(creat.currency);
        response.append("\"");
    }
    response.append(",\"price\":");
    response.append(price);
    response.append(",\"adid\":\"");
    if (creat.alternateAdId == null)
        response.append(adid);
    else
        response.append(creat.alternateAdId);
    response.append("\",\"nurl\":\"");
    response.append(snurl);
    response.append("\",\"cid\":\"");
    response.append(adid);
    response.append("\",\"crid\":\"");
    response.append(creat.impid);
    if (dealId != null) {
        response.append("\",\"dealid\":\"");
        response.append(dealId);
    }
    response.append("\",\"iurl\":\"");
    response.append(imageUrl);
    response.append("\",\"adomain\": [\"");
    response.append(camp.adomain);
    response.append("\"],\"adm\":\"");
    if (this.creat.isVideo()) {
        if (br.usesEncodedAdm) {
            response.append(this.creat.encodedAdm);
            // not part of protocol, but stuff here for logging purposes
            this.forwardUrl = this.creat.encodedAdm;
        } else {
            //System.out.println(this.creat.unencodedAdm );
            response.append(this.creat.unencodedAdm);
            this.forwardUrl = this.creat.unencodedAdm;
        }
    } else if (this.creat.isNative()) {
        if (br.usesEncodedAdm) {
            nativeAdm = this.creat.getEncodedNativeAdm(br);
        } else {
            nativeAdm = this.creat.unencodedAdm;
        }
        response.append(nativeAdm);
    } else {
        response.append(getTemplate());
    }
    response.append("\"}]}],");
    response.append("\"id\":\"");
    // backwards?
    response.append(oidStr);
    response.append("\",\"bidid\":\"");
    response.append(br.id);
    response.append("\",\"cur\":\"");
    response.append(creat.cur);
    response.append("\"}");
    // pass this along so the bid response object
    this.cost = price;
    // has a copy of the price
    macroSubs(response);
}
Also used : Configuration(com.xrtb.common.Configuration)

Example 3 with Configuration

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

the class BidResponse method macroSubs.

/**
	 * Apply standard macro substitutions to the adm field.
	 * 
	 * @param sb
	 *            StringBuilder. The adm field being substituted into.
	 */
public void macroSubs(StringBuilder sb) {
    String lat = "0.0";
    String lon = "0.0";
    if (br.lat != null && br.lat != 0.0 && br.lon != null && br.lon != 0) {
        lat = br.lat.toString();
        lon = br.lon.toString();
    }
    /** The configuration used for generating this response */
    Configuration config = Configuration.getInstance();
    replaceAll(sb, "{redirect_url}", config.redirectUrl);
    replaceAll(sb, "{pixel_url}", config.pixelTrackingUrl);
    replaceAll(sb, "{creative_forward_url}", creat.forwardurl);
    try {
        MacroProcessing.replace(creat.macros, br, creat, imp, adid, sb, snurl, dealId);
        MacroProcessing.replace(Configuration.getInstance().macros, br, creat, imp, adid, sb, snurl, dealId);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Configuration(com.xrtb.common.Configuration)

Example 4 with Configuration

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

the class Config method teardown.

public static void teardown() {
    //		if (server != null) {
    //			server.halt();
    //		}
    Configuration c = Configuration.getInstance();
    c.campaignsList.clear();
}
Also used : Configuration(com.xrtb.common.Configuration)

Example 5 with Configuration

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

the class TestCampaignProcessor method testOneMatching.

/**
	 * Load a campaign and then use the bidder's campaign processor to make a bid response.
	 * @throws Exception if the config file or the sample bid file fails to load, or they contain JSON errors.
	 */
//	@Test
public void testOneMatching() throws Exception {
    InputStream is = Configuration.getInputStream("SampleBids/nexage.txt");
    BidRequest request = new BidRequest(is);
    Configuration cf = Configuration.getInstance();
    cf.clear();
    cf.initialize("Campaigns/payday.json");
    Campaign c = cf.campaignsList.get(0);
    AbortableCountDownLatch latch = new AbortableCountDownLatch(1, 1);
    CountDownLatch flag = new CountDownLatch(1);
    CampaignProcessor proc = new CampaignProcessor(c, request, flag, latch);
    flag.countDown();
    latch.await();
    SelectedCreative resp = proc.getSelectedCreative();
    assertNotNull(resp);
    assertTrue(resp.getCreative().dimensions.get(0).getLeftX() == 320);
}
Also used : Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) AbortableCountDownLatch(com.xrtb.bidder.AbortableCountDownLatch) InputStream(java.io.InputStream) CampaignProcessor(com.xrtb.bidder.CampaignProcessor) SelectedCreative(com.xrtb.bidder.SelectedCreative) AbortableCountDownLatch(com.xrtb.bidder.AbortableCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) BidRequest(com.xrtb.pojo.BidRequest)

Aggregations

Configuration (com.xrtb.common.Configuration)15 Campaign (com.xrtb.common.Campaign)7 RTBServer (com.xrtb.bidder.RTBServer)5 User (com.xrtb.db.User)5 DbTools (com.xrtb.tools.DbTools)5 SelectedCreative (com.xrtb.bidder.SelectedCreative)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 AbortableCountDownLatch (com.xrtb.bidder.AbortableCountDownLatch)1 CampaignProcessor (com.xrtb.bidder.CampaignProcessor)1 Creative (com.xrtb.common.Creative)1 BidRequest (com.xrtb.pojo.BidRequest)1 InputStream (java.io.InputStream)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1