use of org.commonjava.maven.ext.io.rest.exception.RestException in project pom-manipulation-ext by release-engineering.
the class ListingBlacklistMapper method readValue.
@Override
public Object readValue(String s) {
List<ProjectVersionRef> result = new ArrayList<>();
if (s.length() == 0) {
errorString = "No content to read.";
return result;
} else if (s.startsWith("<")) {
// Read an HTML string.
String stripped = s.replaceFirst(".*</h1>\n", "").replaceFirst("\n</body></html>", "");
logger.debug("Read HTML string '{}' rather than a JSON stream; stripping message to {}", s, stripped);
errorString = stripped;
return result;
} else if (s.startsWith("{\\\"message\\\":") || s.startsWith("{\"message\":")) {
String endStripped = s.replace("\\\"}", "").replace("\"}", "");
errorString = endStripped.substring(endStripped.lastIndexOf("\"") + 1);
logger.debug("Read message string {}, processed to {} ", s, errorString);
return result;
}
List<Map<String, Object>> responseBody;
try {
responseBody = objectMapper.readValue(s, List.class);
} catch (IOException e) {
logger.error("Failed to decode map when reading string {}", s);
throw new RestException("Failed to read list-of-maps response from version server: " + e.getMessage(), e);
}
for (Map<String, Object> gav : responseBody) {
String groupId = (String) gav.get("groupId");
String artifactId = (String) gav.get("artifactId");
String version = (String) gav.get("version");
ProjectVersionRef project = new SimpleProjectVersionRef(groupId, artifactId, version);
result.add(project);
}
return result;
}
use of org.commonjava.maven.ext.io.rest.exception.RestException in project pom-manipulation-ext by release-engineering.
the class HttpHeaderHeaderTest method testVerifyContentHeaderMessageNoEscape.
@Test
public void testVerifyContentHeaderMessageNoEscape() {
testResponseStart = "{\"message\":\"";
testResponseEnd = "\"}";
List<ProjectVersionRef> gavs = new ArrayList<ProjectVersionRef>() {
{
add(new SimpleProjectVersionRef("com.example", "example", "1.0"));
}
};
try {
versionTranslator.translateVersions(gavs);
fail("Failed to throw RestException.");
} catch (RestException ex) {
assertTrue(systemOutRule.getLog().contains("message"));
}
}
Aggregations