All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ingenico.connect.gateway.sdk.java.Response Maven / Gradle / Ivy

Go to download

SDK to communicate with the Ingenico ePayments platform using the Ingenico Connect Server API

There is a newer version: 6.47.0
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy