Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump httpclient from 4.5.5 to 4.5.13 #1295

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<commons.version>3.6</commons.version>
<commons.collections.version>4.1</commons.collections.version>
<commons.compress.version>1.19</commons.compress.version>
<httpclient.version>4.5.5</httpclient.version>
<httpclient.version>4.5.13</httpclient.version>
<ipaddress.version>5.3.1</ipaddress.version>
<jackson.version>2.10.0</jackson.version>
<json.schema.validator.version>0.1.7</json.schema.validator.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ private ExtImp getExtImp(ObjectNode extImpNode, String impId) {
private Map<String, String> resolveStoredBidResponse(List<ExtStoredBidResponse> storedBidResponse) {
return storedBidResponse.stream()
.collect(Collectors.toMap(ExtStoredBidResponse::getBidder, ExtStoredBidResponse::getId));

}

private List<SeatBid> convertToSeatBid(StoredResponseDataResult storedResponseDataResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -61,27 +62,24 @@ public AdgenerationBidder(String endpointUrl, JacksonMapper mapper) {

@Override
public Result<List<HttpRequest<Void>>> makeHttpRequests(BidRequest request) {
if (CollectionUtils.isEmpty(request.getImp())) {
return Result.withError(BidderError.badInput("No impression in the bid request"));
}

final List<HttpRequest<Void>> requests = new ArrayList<>();
final List<BidderError> errors = new ArrayList<>();
final List<HttpRequest<Void>> result = new ArrayList<>();
for (Imp imp : request.getImp()) {
try {
final ExtImpAdgeneration extImpAdgeneration = parseAndValidateImpExt(imp);
final String extImpAdgenerationId = extImpAdgeneration.getId();
final String adgenerationId = extImpAdgeneration.getId();
final String adSizes = getAdSize(imp);
final String currency = getCurrency(request);
final String uri = getUri(endpointUrl, adSizes, extImpAdgenerationId, currency,
final String uri = getUri(adSizes, adgenerationId, currency,
request.getSite(), request.getSource());
result.add(createSingleRequest(uri, request.getDevice()));

requests.add(createSingleRequest(uri, request.getDevice()));
} catch (PreBidException e) {
errors.add(BidderError.badInput(e.getMessage()));
}
}

return Result.of(result, errors);
return Result.of(requests, errors);
}

private ExtImpAdgeneration parseAndValidateImpExt(Imp imp) {
Expand All @@ -99,9 +97,15 @@ private ExtImpAdgeneration parseAndValidateImpExt(Imp imp) {
return extImpAdgeneration;
}

private String getUri(String endpointUrl, String adSize, String id, String currency, Site site, Source source) {
final URIBuilder uriBuilder = new URIBuilder()
.setPath(endpointUrl)
private String getUri(String adSize, String id, String currency, Site site, Source source) {
final URIBuilder uriBuilder;
try {
uriBuilder = new URIBuilder(endpointUrl);
} catch (URISyntaxException e) {
throw new PreBidException(String.format("Invalid url: %s, error: %s", endpointUrl, e.getMessage()));
}

uriBuilder
.addParameter("posall", "SSPLOC")
.addParameter("id", id)
.addParameter("sdktype", "0")
Expand All @@ -120,38 +124,38 @@ private String getUri(String endpointUrl, String adSize, String id, String curre
uriBuilder.addParameter("tp", page);
}

final String transactionid = source != null ? source.getTid() : null;
if (StringUtils.isNotBlank(transactionid)) {
uriBuilder.addParameter("transactionid", transactionid);
final String transactionId = source != null ? source.getTid() : null;
if (StringUtils.isNotBlank(transactionId)) {
uriBuilder.addParameter("transactionid", transactionId);
}

return uriBuilder.toString();
}

private String getAdSize(Imp imp) {
private static String getAdSize(Imp imp) {
final Banner banner = imp.getBanner();
final List<Format> formats = banner != null ? banner.getFormat() : null;
return CollectionUtils.emptyIfNull(formats).stream()
.map(format -> String.format("%sx%s", format.getW(), format.getH()))
.collect(Collectors.joining(","));
}

private String getCurrency(BidRequest bidRequest) {
private static String getCurrency(BidRequest bidRequest) {
final List<String> currencies = bidRequest.getCur();
return CollectionUtils.isEmpty(currencies)
? DEFAULT_REQUEST_CURRENCY
: currencies.contains(DEFAULT_REQUEST_CURRENCY) ? DEFAULT_REQUEST_CURRENCY : currencies.get(0);
}

private HttpRequest<Void> createSingleRequest(String uri, Device device) {
private static HttpRequest<Void> createSingleRequest(String uri, Device device) {
return HttpRequest.<Void>builder()
.method(HttpMethod.GET)
.uri(uri)
.headers(resolveHeaders(device))
.build();
}

private MultiMap resolveHeaders(Device device) {
private static MultiMap resolveHeaders(Device device) {
final MultiMap headers = HttpUtil.headers();

final String userAgent = device != null ? device.getUa() : null;
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/org/prebid/server/bidder/adocean/AdoceanBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,25 @@ private HttpRequest<Void> createSingleRequest(BidRequest request, Imp imp, ExtIm
.build();
}

private String buildUrl(String impid, ExtImpAdocean extImpAdocean, String consentString, BidRequest bidRequest,
private String buildUrl(String impId, ExtImpAdocean extImpAdocean, String consentString, BidRequest bidRequest,
Map<String, String> slaveSizes) {

final Integer test = bidRequest.getTest();
final String url = endpointUrl.replace("{{Host}}", Objects.toString(extImpAdocean.getEmitterDomain(), ""));
final int randomizedPart = Objects.equals(test, 1) ? 10000000 : 10000000 + (int) (Math.random() * 89999999);
final String updateUrl = String.format("%s/_%s/ad.json", url, randomizedPart);
final URIBuilder uriBuilder = new URIBuilder()
.setPath(updateUrl)
final String resolvedUrl = resolveEndpointUrl(extImpAdocean, test);

final URIBuilder uriBuilder;
try {
uriBuilder = new URIBuilder(resolvedUrl);
} catch (URISyntaxException e) {
throw new PreBidException(String.format("Invalid url: %s, error: %s", resolvedUrl, e.getMessage()));
}

uriBuilder
.addParameter("pbsrv_v", VERSION)
.addParameter("id", extImpAdocean.getMasterId())
.addParameter("nc", "1")
.addParameter("nosecure", "1")
.addParameter("aid", extImpAdocean.getSlaveId() + ":" + impid);
.addParameter("aid", extImpAdocean.getSlaveId() + ":" + impId);

if (StringUtils.isNotEmpty(consentString)) {
uriBuilder.addParameter("gdpr_consent", consentString);
Expand Down Expand Up @@ -249,6 +255,12 @@ private String buildUrl(String impid, ExtImpAdocean extImpAdocean, String consen
return uriBuilder.toString();
}

private String resolveEndpointUrl(ExtImpAdocean extImpAdocean, Integer test) {
final String url = endpointUrl.replace("{{Host}}", Objects.toString(extImpAdocean.getEmitterDomain(), ""));
final int randomizedPart = Objects.equals(test, 1) ? 10000000 : 10000000 + (int) (Math.random() * 89999999);
return String.format("%s/_%s/ad.json", url, randomizedPart);
}

private List<String> setSlaveSizesParam(Map<String, String> slaveSizes, boolean orderByKey) {
final Set<String> slaveIDs = orderByKey ? new TreeSet<>(slaveSizes.keySet()) : slaveSizes.keySet();

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/prebid/server/bidder/amx/AmxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -54,8 +55,17 @@ public class AmxBidder implements Bidder<BidRequest> {

public AmxBidder(String endpointUrl, JacksonMapper mapper) {
this.mapper = Objects.requireNonNull(mapper);
this.endpointUrl = new URIBuilder()
.setPath(HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)))
this.endpointUrl = resolveEndpointUrl(endpointUrl);
}

private static String resolveEndpointUrl(String url) {
final URIBuilder uriBuilder;
try {
uriBuilder = new URIBuilder(HttpUtil.validateUrl(Objects.requireNonNull(url)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we will already have validation for url while creating uri builder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd say new URI(string) doesn't cover invalid url as new URL(url) does.
So, org.prebid.server.bidder.amx.AmxBidderTest#creationShouldFailOnInvalidEndpointUrl will fail.

} catch (URISyntaxException e) {
throw new IllegalArgumentException(String.format("Invalid url: %s, error: %s", url, e.getMessage()));
}
return uriBuilder
.addParameter(VERSION_PARAM, ADAPTER_VERSION)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
}

return Result.withValue(createRequest(extImpBetween, request, modifiedImps));

}

private static Integer resolveSecure(Site site) {
Expand Down Expand Up @@ -160,7 +159,6 @@ private static MultiMap resolveHeaders(Device device, Site site) {
}
if (site != null) {
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.REFERER_HEADER, site.getPage());

}
return headers;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/prebid/server/bidder/dmx/DmxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ private static Video resolveVideo(Video video) {
: video.toBuilder()
.protocols(resolveVideoProtocols(video.getProtocols()))
.build();

}

private static List<Integer> resolveVideoProtocols(List<Integer> videoProtocols) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -110,15 +111,19 @@ public Result<List<HttpRequest<Void>>> makeHttpRequests(BidRequest request) {
return Result.withErrors(errors);
}

final MultiMap headers = createHeaders(request.getDevice());
final String uri = resolveRequestUri(request, requestsStrings, clientId);
final String uri;
try {
uri = resolveRequestUri(request, requestsStrings, clientId);
} catch (PreBidException e) {
return Result.withError(BidderError.badInput(e.getMessage()));
}

return Result.of(Collections.singletonList(
HttpRequest.<Void>builder()
.method(HttpMethod.GET)
.uri(uri)
.headers(createHeaders(request.getDevice()))
.body(null)
.headers(headers)
.payload(null)
.build()),
errors);
Expand Down Expand Up @@ -227,8 +232,14 @@ private String resolveRequestUri(BidRequest request, List<String> requestsString

final String uri = endpointUrl + String.format("/%s/%s/%s/%s", clientId, DFP_CLIENT_ID, requestTarget, SEC);

final URIBuilder uriBuilder = new URIBuilder()
.setPath(uri)
final URIBuilder uriBuilder;
try {
uriBuilder = new URIBuilder(uri);
} catch (URISyntaxException e) {
throw new PreBidException(String.format("Invalid url: %s, error: %s", uri, e.getMessage()));
}

uriBuilder
.addParameter("r", "pbs")
.addParameter("ncb", "1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ private ExtImpFacebook parseAndResolveExtImpFacebook(Imp imp) {
if (StringUtils.isBlank(extImpFacebook.getPublisherId())) {
throw new PreBidException("Missing publisherId param");
}

return extImpFacebook;

} else if (splitLength == 2) {
return ExtImpFacebook.of(placementSplit[1], placementSplit[0]);
} else {
Expand Down Expand Up @@ -323,7 +321,6 @@ private BidderBid toBidderBid(Bid bid, List<Imp> imps, String currency, List<Bid
.build();

return BidderBid.of(modifiedBid, getBidType(modifiedBid.getImpid(), imps), currency);

} catch (DecodeException | PreBidException e) {
errors.add(BidderError.badServerResponse(e.getMessage()));
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ public Result<List<HttpRequest<SharethroughRequestBody>>> makeHttpRequests(BidRe
String.format("Error occurred parsing sharethrough parameters %s", e.getMessage())));
}
final MultiMap headers = makeHeaders(request.getDevice(), page);

final List<BidderError> errors = new ArrayList<>();
final List<HttpRequest<SharethroughRequestBody>> httpRequests = strUriParameters.stream()
.map(strUriParameter -> makeHttpRequest(headers, date, strUriParameter))
.map(strUriParameter -> makeHttpRequest(headers, date, strUriParameter, errors))
.filter(Objects::nonNull)
.collect(Collectors.toList());

return Result.withValues(httpRequests);
return Result.of(httpRequests, errors);
}

/**
Expand Down Expand Up @@ -167,17 +169,24 @@ private MultiMap makeHeaders(Device device, String page) {
* Make {@link HttpRequest} from uri and headers.
*/
private HttpRequest<SharethroughRequestBody> makeHttpRequest(
MultiMap headers, Date date, StrUriParameters strUriParameter) {
MultiMap headers, Date date, StrUriParameters strUriParameter, List<BidderError> errors) {

final String uri;
try {
uri = SharethroughUriBuilderUtil.buildSharethroughUrl(
endpointUrl, SUPPLY_ID, VERSION, DATE_FORMAT.format(date), strUriParameter);
} catch (IllegalArgumentException e) {
errors.add(BidderError.badInput(e.getMessage()));
return null;
}

final String uri = SharethroughUriBuilderUtil.buildSharethroughUrl(
endpointUrl, SUPPLY_ID, VERSION, DATE_FORMAT.format(date), strUriParameter);
final SharethroughRequestBody body = strUriParameter.getBody();

return HttpRequest.<SharethroughRequestBody>builder()
.method(HttpMethod.POST)
.uri(uri)
.body(mapper.encode(body))
.headers(headers)
.body(mapper.encode(body))
.payload(body)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ private SharethroughUriBuilderUtil() {
}

/**
* Creates uri with parameters for sharethrough request
* Creates uri with parameters for Sharethrough request.
*/
static String buildSharethroughUrl(String baseUri, String supplyId, String strVersion, String formattedDate,
StrUriParameters params) {
final URIBuilder uriBuilder = new URIBuilder()
.setPath(baseUri)

final URIBuilder uriBuilder;
try {
uriBuilder = new URIBuilder(baseUri);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(String.format("Invalid url: %s, error: %s", baseUri, e.getMessage()));
}

uriBuilder
.addParameter("placement_key", params.getPkey())
.addParameter("bidId", params.getBidID())
.addParameter("consent_required", getBooleanStringValue(params.getConsentRequired()))
Expand Down Expand Up @@ -51,7 +58,7 @@ private static String getBooleanStringValue(Boolean bool) {
}

/**
* Creates uri with parameters for sharethrough request
* Creates uri with parameters for Sharethrough request.
*/
static StrUriParameters buildSharethroughUrlParameters(String uri) {
try {
Expand All @@ -67,7 +74,6 @@ static StrUriParameters buildSharethroughUrlParameters(String uri) {
.bidID(getValueByKey(queryParams, "bidId"))
.consentString(getValueByKey(queryParams, "consent_string"))
.build();

} catch (URISyntaxException e) {
throw new IllegalArgumentException("Cant resolve uri: " + uri, e);
}
Expand Down Expand Up @@ -99,4 +105,3 @@ private static String getValueByKey(List<NameValuePair> nameValuePairs, String k
.orElse("");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
? validImp.toBuilder().tagid(zoneId).build()
: imp;
validImps.add(updatedImp);

} catch (PreBidException e) {
errors.add(BidderError.badInput(e.getMessage()));
}
Expand Down
Loading