use of org.springframework.http.HttpEntity in project metron by apache.
the class RestTestingUtil method getPcapsByIdentifiers.
private static void getPcapsByIdentifiers(String srcIp, String dstIp, String protocol, String srcPort, String dstPort) {
System.out.println("**********************getPcapsByKeysRange ******************************************************************************************");
// 1.
String url = "http://" + hostName + "/pcapGetter/getPcapsByIdentifiers?srcIp={srcIp}" + "&dstIp={dstIp}" + "&protocol={protocol}" + "&srcPort={srcPort}" + "&dstPort={dstPort}";
// default values
String startTime = "-1";
String endTime = "-1";
String maxResponseSize = "6";
@SuppressWarnings("rawtypes") Map map = new HashMap();
map.put("srcIp", srcIp);
map.put("dstIp", dstIp);
map.put("protocol", protocol);
map.put("srcPort", srcPort);
map.put("dstPort", dstPort);
RestTemplate template = new RestTemplate();
// set headers and entity to send
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_OCTET_STREAM_VALUE);
HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers);
// 1.
ResponseEntity<byte[]> response1 = template.exchange(url, HttpMethod.GET, requestEntity, byte[].class, map);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.format("getPcapsByIdentifiers : request= <srcIp=%s; dstIp=%s; protocol=%s; endTime=%s; srcPort=%s; dstPort=%s> \n response= %s \n", srcIp, dstIp, protocol, endTime, srcPort, dstPort, response1);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.println();
// 2. with time range
startTime = System.getProperty("startTime", "-1");
endTime = System.getProperty("endTime", "-1");
map.put("startTime", startTime);
map.put("endTime", endTime);
ResponseEntity<byte[]> response2 = template.exchange(url, HttpMethod.GET, requestEntity, byte[].class, map);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.format("getPcapsByIdentifiers : request= <srcIp=%s; dstIp=%s; protocol=%s; endTime=%s; srcPort=%s; dstPort=%s> \n response= %s \n", srcIp, dstIp, protocol, endTime, srcPort, dstPort, response2);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.println();
// 3. with maxResponseSize
maxResponseSize = System.getProperty("maxResponseSize", "6");
map.put("maxResponseSize", maxResponseSize);
ResponseEntity<byte[]> response3 = template.exchange(url, HttpMethod.GET, requestEntity, byte[].class, map);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.format("getPcapsByIdentifiers : request= <srcIp=%s; dstIp=%s; protocol=%s; endTime=%s; srcPort=%s; dstPort=%s> \n response= %s \n", srcIp, dstIp, protocol, endTime, srcPort, dstPort, response3);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.println();
}
use of org.springframework.http.HttpEntity in project metron by apache.
the class RestTestingUtil method getPcapsByKeysRange.
/**
* Gets the pcaps by keys range.
*
* @param startKey
* the start key
* @param endKey
* the end key
* @return the pcaps by keys range
*/
@SuppressWarnings("unchecked")
private static void getPcapsByKeysRange(String startKey, String endKey) {
System.out.println("**********************getPcapsByKeysRange ******************************************************************************************");
// 1.
String url = "http://" + hostName + "/cisco-rest/pcapGetter/getPcapsByKeyRange?startKey={startKey}" + "&endKey={endKey}" + "&startTime={startTime}" + "&endTime={endTime}" + "&maxResponseSize={maxResponseSize}";
// default values
String startTime = "-1";
String endTime = "-1";
String maxResponseSize = "6";
@SuppressWarnings("rawtypes") Map map = new HashMap();
map.put("startKey", startKey);
map.put("endKey", "endKey");
map.put("startTime", startTime);
map.put("endTime", endTime);
map.put("maxResponseSize", maxResponseSize);
RestTemplate template = new RestTemplate();
// set headers and entity to send
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_OCTET_STREAM_VALUE);
HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers);
// 1.
ResponseEntity<byte[]> response1 = template.exchange(url, HttpMethod.GET, requestEntity, byte[].class, map);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.format("getPcapsByKeysRange : request= <startKey=%s; endKey=%s; startTime=%s; endTime=%s; maxResponseSize=%s> \n response= %s \n", startKey, endKey, startTime, endTime, maxResponseSize, response1);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.println();
// 2. with time range
startTime = System.getProperty("startTime", "-1");
endTime = System.getProperty("endTime", "-1");
map.put("startTime", startTime);
map.put("endTime", endTime);
ResponseEntity<byte[]> response2 = template.exchange(url, HttpMethod.GET, requestEntity, byte[].class, map);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.format("getPcapsByKeysRange : request= <startKey=%s; endKey=%s; startTime=%s; endTime=%s; maxResponseSize=%s> \n response= %s \n", startKey, endKey, startTime, endTime, maxResponseSize, response2);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.println();
// 3. with maxResponseSize
maxResponseSize = System.getProperty("maxResponseSize", "6");
map.put("maxResponseSize", maxResponseSize);
ResponseEntity<byte[]> response3 = template.exchange(url, HttpMethod.GET, requestEntity, byte[].class, map);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.format("getPcapsByKeysRange : request= <startKey=%s; endKey=%s; startTime=%s; endTime=%s; maxResponseSize=%s> \n response= %s \n", startKey, endKey, startTime, endTime, maxResponseSize, response3);
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.println();
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestPasswordManagementService method findEmail.
@Override
public String findEmail(final String username) {
final PasswordManagementProperties.Rest rest = properties.getRest();
if (StringUtils.isBlank(rest.getEndpointUrlEmail())) {
return null;
}
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
headers.put("username", CollectionUtils.wrap(username));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<String> result = restTemplate.exchange(rest.getEndpointUrlEmail(), HttpMethod.GET, entity, String.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value() && result.hasBody()) {
return result.getBody();
}
return null;
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class ClickatellSmsSender method send.
@Override
public boolean send(final String from, final String to, final String message) {
try {
final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", this.token);
headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
final Map<String, Object> map = new HashMap<>();
map.put("content", message);
map.put("to", CollectionUtils.wrap(to));
map.put("from", from);
final StringWriter stringify = new StringWriter();
mapper.writeValue(stringify, map);
final HttpEntity<String> request = new HttpEntity<>(stringify.toString(), headers);
final ResponseEntity<Map> response = restTemplate.postForEntity(new URI(this.serverUrl), request, Map.class);
if (response.hasBody()) {
final List<Map> messages = (List<Map>) response.getBody().get("messages");
final String error = (String) response.getBody().get("error");
if (StringUtils.isNotBlank(error)) {
LOGGER.error(error);
return false;
}
final List<String> errors = messages.stream().filter(m -> m.containsKey("accepted") && !Boolean.parseBoolean(m.get("accepted").toString()) && m.containsKey("error")).map(m -> (String) m.get("error")).collect(Collectors.toList());
if (errors.isEmpty()) {
return true;
}
errors.forEach(LOGGER::error);
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestConsentRepository method findConsentDecisions.
@Override
public Collection<ConsentDecision> findConsentDecisions() {
try {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<List> result = restTemplate.exchange(this.endpoint, HttpMethod.GET, entity, List.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
return result.getBody();
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new ArrayList<>(0);
}
Aggregations