com.ingenico.connect.gateway.sdk.java.Response Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connect-sdk-java Show documentation
Show all versions of connect-sdk-java Show documentation
SDK to communicate with the Ingenico ePayments platform using the Ingenico Connect Server API
package com.ingenico.connect.gateway.sdk.java;
import java.util.Collections;
import java.util.List;
/**
* A response from the Ingenico ePayments platform.
*/
public class Response {
private final int statusCode;
private final String body;
private final List headers;
public Response(int statusCode, String body, List headers) {
this.statusCode = statusCode;
this.body = body;
this.headers = headers != null ? Collections.unmodifiableList(headers) : Collections.emptyList();
}
/**
* @return The HTTP status code that was returned by the Ingenico ePayments platform.
*/
public int getStatusCode() {
return statusCode;
}
/**
* @return The raw response body that was returned by the Ingenico ePayments platform.
*/
public String getBody() {
return body;
}
/**
* @return The headers that were returned by the Ingenico ePayments platform. Never {@code null}.
*/
public List getHeaders() {
return headers;
}
/**
* @return The header with the given name, or {@code null} if there was no such header.
*/
public ResponseHeader getHeader(String headerName) {
for (ResponseHeader header : headers) {
if (header.getName().equalsIgnoreCase(headerName)) {
return header;
}
}
return null;
}
/**
* @return The value of the header with the given name, or {@code null} if there was no such header.
*/
public String getHeaderValue(String headerName) {
ResponseHeader header = getHeader(headerName);
return header != null ? header.getValue() : null;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(getClass().getName())
.append("[statusCode=").append(statusCode);
if (body != null && body.length() > 0) {
sb.append(",body='").append(body).append("'");
}
if (!headers.isEmpty()) {
sb.append(",headers=").append(headers);
}
return sb.append("]").toString();
}
}