import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
private URI buildURI(OTXEndpoints endpoint, Map endpointParametersMap) throws URISyntaxException, MalformedURLException {
String endpointString = endpoint.getEndpoint();
if (endpointParametersMap != null) {
boolean first = true;
for (Map.Entry otxEndpointParametersEntry : endpointParametersMap.entrySet()) {
if (otxEndpointParametersEntry.getKey().isRestVariable()) {
endpointString = endpointString.replace("{" + otxEndpointParametersEntry.getKey().getParameterName() + "}", otxEndpointParametersEntry.getValue().toString());
} else {
if (first) {
endpointString = endpointString + "?";
first = false;
}
try {
String parameterName = otxEndpointParametersEntry.getKey().getParameterName();
String value = UriUtils.encodeQueryParam(otxEndpointParametersEntry.getValue().toString(), "UTF-8");
endpointString = endpointString + String.format("%s=%s&", parameterName, value);
} catch (UnsupportedEncodingException e) {
log.error("Unpossible");
}
}
}
}
if (otxPort != null) {
return new URL(otxScheme, otxHost, otxPort, endpointString).toURI();
} else {
return new URL(otxScheme, otxHost, endpointString).toURI();
}
}