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

Added code that sends report to minervanet

parent 08cba6ae
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 #8314 failed
package lcsb.mapviewer.api.minervanet;
import com.fasterxml.jackson.databind.ObjectMapper;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
@RestController
@RequestMapping("/minervanet")
public class MinervaNetController {
private IConfigurationService configurationService;
private static HttpClient httpClient = HttpClients.createDefault();
@Autowired
public MinervaNetController(IConfigurationService configurationService) {
......@@ -21,9 +24,16 @@ public class MinervaNetController {
}
@PostMapping(value = "/submitError")
public void submitError(@RequestBody ErrorReport report) {
public void submitError(@RequestBody ErrorReport report) throws IOException {
ObjectMapper mapper = new ObjectMapper();
String jsonReport = mapper.writeValueAsString(report);
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()) {
httpClient.execute(httpPost);
}
}
}
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