Skip to content
Snippets Groups Projects
Commit f3b62e12 authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

Fixed post request to minervanet

parent 500785ee
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!589Feature error reporting
Pipeline #8385 failed
package lcsb.mapviewer.api.minervanet; package lcsb.mapviewer.api.minervanet;
import java.time.Instant;
public class ErrorReport { public class ErrorReport {
private String url; private String url;
private String login; private String login;
private String email; private String email;
private String browser; private String browser;
private Instant timestamp; private String timestamp;
private String stacktrace; private String stacktrace;
private String version; private String version;
private String comment; private String comment;
...@@ -45,11 +43,11 @@ public class ErrorReport { ...@@ -45,11 +43,11 @@ public class ErrorReport {
this.browser = browser; this.browser = browser;
} }
public Instant getTimestamp() { public String getTimestamp() {
return timestamp; return timestamp;
} }
public void setTimestamp(Instant timestamp) { public void setTimestamp(String timestamp) {
this.timestamp = timestamp; this.timestamp = timestamp;
} }
......
...@@ -4,10 +4,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -4,10 +4,15 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.user.ConfigurationElementType; import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.services.interfaces.IConfigurationService; import lcsb.mapviewer.services.interfaces.IConfigurationService;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -17,6 +22,8 @@ import java.io.IOException; ...@@ -17,6 +22,8 @@ import java.io.IOException;
@RequestMapping("/minervanet") @RequestMapping("/minervanet")
public class MinervaNetController { public class MinervaNetController {
private Logger logger = Logger.getLogger(MinervaNetController.class);
private IConfigurationService configurationService; private IConfigurationService configurationService;
@Autowired @Autowired
...@@ -33,12 +40,18 @@ public class MinervaNetController { ...@@ -33,12 +40,18 @@ public class MinervaNetController {
String jsonReport = mapper.writeValueAsString(report); String jsonReport = mapper.writeValueAsString(report);
String server = configurationService.getValue(ConfigurationElementType.MINERVANET_URL).getValue(); String server = configurationService.getValue(ConfigurationElementType.MINERVANET_URL).getValue();
HttpPost httpPost = new HttpPost(server);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setEntity(new StringEntity(jsonReport));
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
httpClient.execute(httpPost); StringEntity requestEntity = new StringEntity(jsonReport, ContentType.APPLICATION_JSON);
HttpPost post = new HttpPost(server);
post.setEntity(requestEntity);
try (CloseableHttpResponse response = client.execute(post)) {
HttpEntity responseEntity = response.getEntity();
String responseBody = EntityUtils.toString(responseEntity, "UTF-8");
if (response.getStatusLine().getStatusCode() != 200) {
logger.error("Could not submit report to MinervaNet. Reason: " + responseBody);
}
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment