Skip to content

Commit

Permalink
check URL API (teamdigitale#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnespolino authored Oct 23, 2023
1 parent 4ffa55c commit c609141
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jacocoTestCoverageVerification {
'it.gov.innovazione.ndc.model.profiles.*',
'it.gov.innovazione.ndc.gen.*',
'it.gov.innovazione.ndc.validator.BaseSemanticAssetValidator',
'it.gov.innovazione.ndc.controller.exception.*'
'it.gov.innovazione.ndc.controller.*'
]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package it.gov.innovazione.ndc.controller;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.HttpURLConnection;
import java.net.URL;

@RestController
@RequestMapping("check-url")
@Slf4j
public class CheckUrlController {
@GetMapping
@SneakyThrows
public ResponseEntity<?> check(@RequestParam String url) {
log.info("Checking url {}", url);
HttpURLConnection huc = (HttpURLConnection) new URL(url).openConnection();
huc.setConnectTimeout(5000);
log.info("Response code for url {} is : {}", url, huc.getResponseCode());
return new ResponseEntity<>(HttpStatus.valueOf(huc.getResponseCode()));
}
}

0 comments on commit c609141

Please sign in to comment.