Search in sources :

Example 11 with RestException

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;
}
Also used : SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) ArrayList(java.util.ArrayList) RestException(org.commonjava.maven.ext.io.rest.exception.RestException) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Map(java.util.Map)

Example 12 with RestException

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"));
    }
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ArrayList(java.util.ArrayList) RestException(org.commonjava.maven.ext.io.rest.exception.RestException) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Aggregations

RestException (org.commonjava.maven.ext.io.rest.exception.RestException)12 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)11 ArrayList (java.util.ArrayList)10 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)10 Test (org.junit.Test)7 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 FileAppender (ch.qos.logback.core.FileAppender)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 XPath (javax.xml.xpath.XPath)1