@Test public void malformedRequest() throws JsonMappingException, JsonParseException, IOException { String jsonRequest = "{xyz}"; String jsonResponse = server.process(jsonRequest); System.out.println(" IN:"+jsonRequest); System.out.println("OUT:"+jsonResponse); AdvertiserBlocklistResponseTranslator resTrans = new AdvertiserBlocklistResponseTranslator(); AdvertiserBlocklistResponse response = resTrans.fromJSON(jsonResponse); assertTrue("bad MD5 status code",response.getStatus().getCode()==Status.OTHER_ERROR_CODE); }
public String process(String jsonRequest) { AdvertiserBlocklistRequest request = null; AdvertiserBlocklistResponse response = new AdvertiserBlocklistResponse(); Status status = new Status("n/a"); String requestToken = null; String jsonResponse = null; Identification identification = new Identification(ssp.getOrganization(),System.currentTimeMillis()); String dsp = null; try { request = reqTrans.fromJSON(jsonRequest); dsp = request.getIdentification().getOrganization(); if (dsp==null || !request.verify(ssp.getSharedSecret(dsp),reqTrans)) throw new IllegalArgumentException("Invalid MD5 checksum"); requestToken = request.getIdentification().getToken(); status.setRequestToken(requestToken); Collection<Advertiser> advertisers = request.getAdvertisers(); advertisers = ssp.setBlocklists(advertisers); response.setAdvertisers(advertisers); status.setResponseCode(Status.SUCCESS_CODE, Status.SUCCESS_MESSAGE); } catch (IllegalArgumentException e) { status.setResponseCode(Status.AUTH_ERROR_CODE, e.getMessage()); } catch (JsonMappingException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (JsonParseException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (IOException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } response.setStatus(status); response.setIdentification(identification); try { if (dsp!=null) response.sign(ssp.getSharedSecret(dsp), resTrans); jsonResponse = resTrans.toJSON(response); } catch (Exception e) { log.error("Response signing/translation failed",e); jsonResponse = null; } return jsonResponse; }
SupplySideServer { public String process(String jsonRequest) { AdvertiserBlocklistRequest request = null; AdvertiserBlocklistResponse response = new AdvertiserBlocklistResponse(); Status status = new Status("n/a"); String requestToken = null; String jsonResponse = null; Identification identification = new Identification(ssp.getOrganization(),System.currentTimeMillis()); String dsp = null; try { request = reqTrans.fromJSON(jsonRequest); dsp = request.getIdentification().getOrganization(); if (dsp==null || !request.verify(ssp.getSharedSecret(dsp),reqTrans)) throw new IllegalArgumentException("Invalid MD5 checksum"); requestToken = request.getIdentification().getToken(); status.setRequestToken(requestToken); Collection<Advertiser> advertisers = request.getAdvertisers(); advertisers = ssp.setBlocklists(advertisers); response.setAdvertisers(advertisers); status.setResponseCode(Status.SUCCESS_CODE, Status.SUCCESS_MESSAGE); } catch (IllegalArgumentException e) { status.setResponseCode(Status.AUTH_ERROR_CODE, e.getMessage()); } catch (JsonMappingException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (JsonParseException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (IOException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } response.setStatus(status); response.setIdentification(identification); try { if (dsp!=null) response.sign(ssp.getSharedSecret(dsp), resTrans); jsonResponse = resTrans.toJSON(response); } catch (Exception e) { log.error("Response signing/translation failed",e); jsonResponse = null; } return jsonResponse; } }
SupplySideServer { public String process(String jsonRequest) { AdvertiserBlocklistRequest request = null; AdvertiserBlocklistResponse response = new AdvertiserBlocklistResponse(); Status status = new Status("n/a"); String requestToken = null; String jsonResponse = null; Identification identification = new Identification(ssp.getOrganization(),System.currentTimeMillis()); String dsp = null; try { request = reqTrans.fromJSON(jsonRequest); dsp = request.getIdentification().getOrganization(); if (dsp==null || !request.verify(ssp.getSharedSecret(dsp),reqTrans)) throw new IllegalArgumentException("Invalid MD5 checksum"); requestToken = request.getIdentification().getToken(); status.setRequestToken(requestToken); Collection<Advertiser> advertisers = request.getAdvertisers(); advertisers = ssp.setBlocklists(advertisers); response.setAdvertisers(advertisers); status.setResponseCode(Status.SUCCESS_CODE, Status.SUCCESS_MESSAGE); } catch (IllegalArgumentException e) { status.setResponseCode(Status.AUTH_ERROR_CODE, e.getMessage()); } catch (JsonMappingException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (JsonParseException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (IOException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } response.setStatus(status); response.setIdentification(identification); try { if (dsp!=null) response.sign(ssp.getSharedSecret(dsp), resTrans); jsonResponse = resTrans.toJSON(response); } catch (Exception e) { log.error("Response signing/translation failed",e); jsonResponse = null; } return jsonResponse; } SupplySideServer(SupplySideService ssp); }
SupplySideServer { public String process(String jsonRequest) { AdvertiserBlocklistRequest request = null; AdvertiserBlocklistResponse response = new AdvertiserBlocklistResponse(); Status status = new Status("n/a"); String requestToken = null; String jsonResponse = null; Identification identification = new Identification(ssp.getOrganization(),System.currentTimeMillis()); String dsp = null; try { request = reqTrans.fromJSON(jsonRequest); dsp = request.getIdentification().getOrganization(); if (dsp==null || !request.verify(ssp.getSharedSecret(dsp),reqTrans)) throw new IllegalArgumentException("Invalid MD5 checksum"); requestToken = request.getIdentification().getToken(); status.setRequestToken(requestToken); Collection<Advertiser> advertisers = request.getAdvertisers(); advertisers = ssp.setBlocklists(advertisers); response.setAdvertisers(advertisers); status.setResponseCode(Status.SUCCESS_CODE, Status.SUCCESS_MESSAGE); } catch (IllegalArgumentException e) { status.setResponseCode(Status.AUTH_ERROR_CODE, e.getMessage()); } catch (JsonMappingException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (JsonParseException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (IOException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } response.setStatus(status); response.setIdentification(identification); try { if (dsp!=null) response.sign(ssp.getSharedSecret(dsp), resTrans); jsonResponse = resTrans.toJSON(response); } catch (Exception e) { log.error("Response signing/translation failed",e); jsonResponse = null; } return jsonResponse; } SupplySideServer(SupplySideService ssp); String process(String jsonRequest); }
SupplySideServer { public String process(String jsonRequest) { AdvertiserBlocklistRequest request = null; AdvertiserBlocklistResponse response = new AdvertiserBlocklistResponse(); Status status = new Status("n/a"); String requestToken = null; String jsonResponse = null; Identification identification = new Identification(ssp.getOrganization(),System.currentTimeMillis()); String dsp = null; try { request = reqTrans.fromJSON(jsonRequest); dsp = request.getIdentification().getOrganization(); if (dsp==null || !request.verify(ssp.getSharedSecret(dsp),reqTrans)) throw new IllegalArgumentException("Invalid MD5 checksum"); requestToken = request.getIdentification().getToken(); status.setRequestToken(requestToken); Collection<Advertiser> advertisers = request.getAdvertisers(); advertisers = ssp.setBlocklists(advertisers); response.setAdvertisers(advertisers); status.setResponseCode(Status.SUCCESS_CODE, Status.SUCCESS_MESSAGE); } catch (IllegalArgumentException e) { status.setResponseCode(Status.AUTH_ERROR_CODE, e.getMessage()); } catch (JsonMappingException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (JsonParseException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } catch (IOException e) { status.setResponseCode(Status.OTHER_ERROR_CODE, e.getMessage()); } response.setStatus(status); response.setIdentification(identification); try { if (dsp!=null) response.sign(ssp.getSharedSecret(dsp), resTrans); jsonResponse = resTrans.toJSON(response); } catch (Exception e) { log.error("Response signing/translation failed",e); jsonResponse = null; } return jsonResponse; } SupplySideServer(SupplySideService ssp); String process(String jsonRequest);  }