0

I am coding a Spring-Boot project that fetches the PhishTank database and stores it locally. At the moment I'm able to get the JSON data and persist it without problems. The problem comes when I try to call the API that returns a GZipped response:

private static final String DB_API = "https://data.phishtank.com/data/" + API_KEY_PLACEHOLDER + "/online-valid.json.gz";

The error I get is:

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [java.util.List<my.project.domain.phishtank.PhishThreat>] and content type [application/gzip]

These are the classes that I have implemented until now:

package my.project.domain.phishtank;

import com.fasterxml.jackson.annotation.JsonAlias;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;

@Document
@Getter
@Setter
public class Detail {
    @JsonAlias("ip_address")
    private String ipAddress;

    /**
     * Classless Inter-Domain Routing block.
     */
    @JsonAlias("cidr_block")
    private String classlessInterDomainRoutingBlock;

    @JsonAlias("announcing_network")
    private String announcingNetwork;

    @JsonAlias("rir")
    private String regionalInternetRegistry;

    private String country;

    @JsonAlias("detail_time")
    private String detailTime;
}

.

package my.projectdomain.phishtank;

import com.fasterxml.jackson.annotation.JsonAlias;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.math.BigInteger;
import java.util.List;

/**
 * Phishing Threat from PhishTank database.
 */
@Document
@Getter
@Setter
public class PhishThreat {
    @Id
    private BigInteger id;

    @JsonAlias("phish_id")
    @Indexed(unique = true, dropDups = true)
    private BigInteger phishID;

    private String url;

    @JsonAlias("phish_detail_url")
    private String phishDetailURL;

    @JsonAlias("submission_time")
    private String submissionTime;

    private String verified;

    @JsonAlias("verification_time")
    private String verificationTime;

    private String online;

    private List<Detail> details;

    private String target;
}

while this is the corresponding service:

@Service
public class PhishTankService {

    @Autowired
    private PhishTankAPIConfiguration configuration;

    @Autowired
    private RestTemplate restTemplate;

    public static final String API_KEY_PLACEHOLDER = "{API_KEY}";

    private static final String DB_API = "https://data.phishtank.com/data/" + API_KEY_PLACEHOLDER + "/online-valid.json.gz";

    @Override
    public List<PhishThreat> downloadDB() {
        HttpHeaders headers = new HttpHeaders();
        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

        String url = DB_API.replace(API_KEY_PLACEHOLDER, this.configuration.getKey());

        HttpEntity<List<PhishThreat>> request = new HttpEntity<>(null, headers);

        ResponseEntity<List<PhishThreat>> response = this.restTemplate.exchange(
                url,
                HttpMethod.GET,
                request,
                new ParameterizedTypeReference<List<PhishThreat>>() {
                }
        );

        return response.getBody();
    }
}

How can I make it to automatically unzip the GZipped response JSON from the API? I have tryied the suggestion of other response with a Filter but without success. Any help would be very appreciated. Thanks

John
  • 1
  • 1

0 Answers0