Skip to content

Commit

Permalink
Injection of supplier.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmermeister committed Oct 26, 2017
1 parent a080c4d commit 85e97ae
Showing 1 changed file with 51 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
package com.atg.openssp.core.exchange.channel.rtb;

import org.apache.http.Header;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import com.atg.openssp.common.core.connector.JsonPostConnector;
import com.atg.openssp.common.exception.BidProcessingException;

/**
* A wrapper to a concrete connector using JSON notation and post method.
*
* @author André Schmer
*
*/
public class OpenRtbConnector {

private final JsonPostConnector jsonPostConnector;

private final String endpoint;

public OpenRtbConnector(final String endpoint) {
this.endpoint = endpoint;
jsonPostConnector = new JsonPostConnector();
}

/**
* Prepares the post transport.
*
* @param bidrequest
* the request to send
* @param header
* to fill in connection header
* @return the body result from the response
* @throws BidProcessingException
*/
String connect(final String bidrequest, final Header[] header) throws BidProcessingException {
final HttpPost httpPost = new HttpPost(endpoint);
httpPost.setHeaders(header);
return jsonPostConnector.connect(new StringEntity(bidrequest, ContentType.APPLICATION_JSON), httpPost);
}
}
package com.atg.openssp.core.exchange.channel.rtb;

import org.apache.http.Header;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import com.atg.openssp.common.core.connector.JsonPostConnector;
import com.atg.openssp.common.demand.Supplier;
import com.atg.openssp.common.exception.BidProcessingException;

/**
* A wrapper to a concrete connector using JSON notation and post method.
*
* @author André Schmer
*
*/
public class OpenRtbConnector {

private final JsonPostConnector jsonPostConnector;

private final String endpoint;

private final Supplier supplier;

public OpenRtbConnector(final Supplier supplier) {
this.supplier = supplier;
endpoint = supplier.getEndPoint();
jsonPostConnector = new JsonPostConnector();
}

/**
* Prepares the post transport.
*
* @param bidrequest
* the request to send
* @param header
* to fill in connection header
* @return the body result from the response
* @throws BidProcessingException
*/
String connect(final String bidrequest, final Header[] header) throws BidProcessingException {
final HttpPost httpPost = new HttpPost(endpoint);
httpPost.setHeaders(header);
return jsonPostConnector.connect(new StringEntity(bidrequest, ContentType.APPLICATION_JSON), httpPost);
}

public Supplier getSupplier() {
return supplier;
}
}

0 comments on commit 85e97ae

Please sign in to comment.