Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 68eb241b authored by Pawel GUTOWSKI's avatar Pawel GUTOWSKI
Browse files

EDELIVERY-3184 Added URL-encoding for ServiceMetadata references

parent 3481f754
No related branches found
No related tags found
No related merge requests found
...@@ -18,9 +18,15 @@ import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier; ...@@ -18,9 +18,15 @@ import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType; import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ProcessIdentifier; import org.oasis_open.docs.bdxr.ns.smp._2016._05.ProcessIdentifier;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* Factory and utility methods for API classes generated from OASIS XSD. * Factory and utility methods for API classes generated from OASIS XSD.
* *
...@@ -56,6 +62,21 @@ public class Identifiers { ...@@ -56,6 +62,21 @@ public class Identifiers {
return String.format("%s::%s", docId.getScheme(), docId.getValue()); return String.format("%s::%s", docId.getScheme(), docId.getValue());
} }
public static String asUrlEncodedString(ParticipantIdentifierType participantId){
try {
return URLEncoder.encode(asString(participantId), UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
public static String asUrlEncodedString(DocumentIdentifier docId){
try {
return URLEncoder.encode(asString(docId), UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
private static String extract(String doubleColonDelimitedId, String groupName) { private static String extract(String doubleColonDelimitedId, String groupName) {
try { try {
......
...@@ -165,4 +165,22 @@ public class IdentifiersTest { ...@@ -165,4 +165,22 @@ public class IdentifiersTest {
assertEquals(MALFORMED_INPUT_MSG + negativeInput, e.getMessage()); assertEquals(MALFORMED_INPUT_MSG + negativeInput, e.getMessage());
} }
@Test
public void testUrlEncodingParticipantId(){
//given
ParticipantIdentifierType participantId = new ParticipantIdentifierType("0088:conformance:sg01#", "ehealth:actorid:qns");
//when-then
assertEquals("ehealth%3Aactorid%3Aqns%3A%3A0088%3Aconformance%3Asg01%23", Identifiers.asUrlEncodedString(participantId));
}
@Test
public void testUrlEncodingDocumentId(){
//given
DocumentIdentifier docId = new DocumentIdentifier("urn::ehealth##services:extended:epsos01::101", "busdox:docid:qns");
//when-then
assertEquals("busdox%3Adocid%3Aqns%3A%3Aurn%3A%3Aehealth%23%23services%3Aextended%3Aepsos01%3A%3A101", Identifiers.asUrlEncodedString(docId));
}
} }
...@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
import java.net.URI; import java.net.URI;
import static eu.europa.ec.smp.api.Identifiers.asString; import static eu.europa.ec.smp.api.Identifiers.asString;
import static eu.europa.ec.smp.api.Identifiers.asUrlEncodedString;
/** /**
* Created by gutowpa on 13/07/2017. * Created by gutowpa on 13/07/2017.
...@@ -47,7 +48,7 @@ public class ServiceMetadataPathBuilder { ...@@ -47,7 +48,7 @@ public class ServiceMetadataPathBuilder {
String path = ServletUriComponentsBuilder.fromCurrentRequestUri() String path = ServletUriComponentsBuilder.fromCurrentRequestUri()
.replacePath(getUrlContext()) .replacePath(getUrlContext())
.path("/{participantId}/services/{docId}") .path("/{participantId}/services/{docId}")
.buildAndExpand(asString(participantId), asString(docId)) .buildAndExpand(asUrlEncodedString(participantId), asUrlEncodedString(docId))
.toUriString(); .toUriString();
return path; return path;
......
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