Mentions légales du service

Skip to content
Snippets Groups Projects
Commit cc06e9e8 authored by Achraf Achkari's avatar Achraf Achkari
Browse files

Fix follow redirect for distant decor retrieving

parent 32312d2f
No related branches found
No related tags found
2 merge requests!44Develop,!43Feature/cdapesos4 update
Pipeline #738420 failed
...@@ -232,7 +232,7 @@ public class AttributeAnalyzer extends AttributeProcessorImpl { ...@@ -232,7 +232,7 @@ public class AttributeAnalyzer extends AttributeProcessorImpl {
@Override @Override
public void processIsOptional(Boolean isOptional) { public void processIsOptional(Boolean isOptional) {
if ((isOptional == null || !isOptional.booleanValue()) && (selectedAttribute.isProhibited() != null && !selectedAttribute.isProhibited().booleanValue())){ if ((isOptional == null || !isOptional.booleanValue()) ){
List<String> listAttrNames = AttributeUtil.getListAttributesNames(selectedAttribute); List<String> listAttrNames = AttributeUtil.getListAttributesNames(selectedAttribute);
for (String attrName : listAttrNames) { for (String attrName : listAttrNames) {
if (AttributeUtil.assertAttributeIsNotRequiredByDefault(this.selectedAttribute, attrName)){ if (AttributeUtil.assertAttributeIsNotRequiredByDefault(this.selectedAttribute, attrName)){
......
...@@ -229,5 +229,6 @@ ...@@ -229,5 +229,6 @@
<version>1.4.1</version> <version>1.4.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
package net.ihe.gazelle.tempmodel.org.decor.art.utils; package net.ihe.gazelle.tempmodel.org.decor.art.utils;
import java.io.FileInputStream; import net.ihe.gazelle.tempmodel.org.decor.art.model.Decor;
import java.io.IOException; import org.apache.commons.validator.routines.UrlValidator;
import java.io.InputStream; import org.slf4j.Logger;
import java.io.OutputStream; import org.slf4j.LoggerFactory;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.FileInputStream;
import org.apache.commons.validator.routines.UrlValidator; import java.io.IOException;
import org.slf4j.Logger; import java.io.InputStream;
import org.slf4j.LoggerFactory; import java.io.OutputStream;
import java.net.URL;
import net.ihe.gazelle.tempmodel.org.decor.art.model.Decor; import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
/** /**
* *
...@@ -27,6 +27,11 @@ public final class DecorMarshaller { ...@@ -27,6 +27,11 @@ public final class DecorMarshaller {
private static Logger log = LoggerFactory.getLogger(DecorMarshaller.class); private static Logger log = LoggerFactory.getLogger(DecorMarshaller.class);
private static HttpClient httpClient = HttpClient.newBuilder()
.connectTimeout(java.time.Duration.ofSeconds(10))
.followRedirects(HttpClient.Redirect.ALWAYS)
.build();
private DecorMarshaller() {} private DecorMarshaller() {}
...@@ -65,19 +70,13 @@ public final class DecorMarshaller { ...@@ -65,19 +70,13 @@ public final class DecorMarshaller {
InputStream is = null; InputStream is = null;
try { try {
if (UrlValidator.getInstance().isValid(path)) { if (UrlValidator.getInstance().isValid(path)) {
URL url; is = getInputStreamFromURL(path);
url = new URL(path);
URLConnection urlConnection = url.openConnection();
urlConnection.setConnectTimeout(10000);
urlConnection.setReadTimeout(10000);
is = urlConnection.getInputStream();
} }
else { else {
is = new FileInputStream(path); is = new FileInputStream(path);
} }
return loadDecor(is); return loadDecor(is);
} catch (IOException e) { } catch (IOException | InterruptedException e) {
log.error("Error to load decor from url : " + path, e); log.error("Error to load decor from url : " + path, e);
}finally { }finally {
if (is != null) { if (is != null) {
...@@ -106,5 +105,14 @@ public final class DecorMarshaller { ...@@ -106,5 +105,14 @@ public final class DecorMarshaller {
mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
mar.marshal(decor, os); mar.marshal(decor, os);
} }
private static InputStream getInputStreamFromURL(String url) throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri(java.net.URI.create(url))
.build();
HttpResponse<InputStream> response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
return response.body();
}
} }
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