/** * Creates a new {@link ClientDriverResponse} object. * * @param content * The content to return * @param contentType * The content-type of the response * @return The newly created response */ public static ClientDriverResponse giveResponse(String content, String contentType) { return new ClientDriverResponse(content, contentType); }
/** * <p>Creates a new response with the given body, a suitable default status * code and a given content-type.</p> * <p>If the content given is null a 204 status code is given, otherwise 200.</p> * * @param content * The content of the response * @param contentType * The content type */ public ClientDriverResponse(InputStream content, String contentType) { this(convertInputStreamToByteArray(content), contentType); }
/** * <p>Creates a new response with the given body, a suitable default status * code and a given content-type.</p> * <p>If the content given is null a 204 status code is given, otherwise 200.</p> * * @param content * The content of the response * @param contentType * The content type */ public ClientDriverResponse(String content, String contentType) { this(convertStringToByteArray(content), contentType); }
response.setContentType(matchedResponse.getContentType()); response.setStatus(matchedResponse.getStatus()); response.setHeader("Server", "rest-client-driver(" + RestDriverProperties.getVersion() + ")"); for (Entry<String, String> thisHeader : matchedResponse.getHeaders().entrySet()) { response.setHeader(thisHeader.getKey(), thisHeader.getValue()); if (matchedResponse.hasBody()) { OutputStream output = response.getOutputStream(); output.write(matchedResponse.getContentAsBytes());
private void delayIfNecessary(ClientDriverResponse response) { if (response.getDelayTime() > 0) { try { response.getDelayTimeUnit().sleep(response.getDelayTime()); } catch (InterruptedException ie) { throw new ClientDriverInternalException("Requested delay was interrupted", ie); } } }
/** * Adds an expectation on the ClientDriver to expect the given request and response. * * @param request The request to expect * @param response The response to expect * * @return The newly added expectation. */ public ClientDriverExpectation addExpectation(ClientDriverRequest request, ClientDriverResponse response) { LOGGER.info("addExpectation: {} {}", request.getMethod(), request.getPath()); if (!response.canExpire() && (expectedResponseTimeout > 0)) { response.within(expectedResponseTimeout, TimeUnit.MILLISECONDS); } return clientDriver.addExpectation(request, response); }
if (response.canExpire() && response.hasNotExpired()) { period = DEFAULT_WAIT_INTERVAL; break;
/** * @return The content as a string, or an empty string if the content byte array is null or empty. */ public String getContent() { if (getContentAsBytes() == null) { return ""; } else { return new String(content); } }
response.setContentType(matchedResponse.getContentType()); response.setStatus(matchedResponse.getStatus()); response.setHeader("Server", "rest-client-driver(" + RestDriverProperties.getVersion() + ")"); for (Entry<String, String> thisHeader : matchedResponse.getHeaders().entrySet()) { response.setHeader(thisHeader.getKey(), thisHeader.getValue()); if (matchedResponse.hasBody()) { OutputStream output = response.getOutputStream(); output.write(matchedResponse.getContentAsBytes());
private void delayIfNecessary(ClientDriverResponse response) { if (response.getDelayTime() > 0) { try { response.getDelayTimeUnit().sleep(response.getDelayTime()); } catch (InterruptedException ie) { throw new ClientDriverInternalException("Requested delay was interrupted", ie); } } }
/** * Adds an expectation on the ClientDriver to expect the given request and response. * * @param request The request to expect * @param response The response to expect * * @return The newly added expectation. */ public ClientDriverExpectation addExpectation(ClientDriverRequest request, ClientDriverResponse response) { LOGGER.info("addExpectation: {} {}", request.getMethod(), request.getPath()); if (!response.canExpire() && (expectedResponseTimeout > 0)) { response.within(expectedResponseTimeout, TimeUnit.MILLISECONDS); } return clientDriver.addExpectation(request, response); }
if (response.canExpire() && response.hasNotExpired()) { period = DEFAULT_WAIT_INTERVAL; break;
/** * @return The content as a string, or an empty string if the content byte array is null or empty. */ public String getContent() { if (getContentAsBytes() == null) { return ""; } else { return new String(content); } }
/** * Creates a new {@link ClientDriverResponse} object with no content. * * @return The newly created response */ public static ClientDriverResponse giveEmptyResponse() { return new ClientDriverResponse(); }
/** * <p>Creates a new response with the given body, a suitable default status * code and a given content-type.</p> * <p>If the content given is null a 204 status code is given, otherwise 200.</p> * * @param content * The content of the response * @param contentType * The content type */ public ClientDriverResponse(String content, String contentType) { this(convertStringToByteArray(content), contentType); }
/** * <p>Creates a new response with the given body, a suitable default status * code and a given content-type.</p> * <p>If the content given is null a 204 status code is given, otherwise 200.</p> * * @param content * The content of the response * @param contentType * The content type */ public ClientDriverResponse(InputStream content, String contentType) { this(convertInputStreamToByteArray(content), contentType); }
/** * Creates a new {@link ClientDriverResponse} object. * * @param content * The content to return * @param contentType * The content-type of the response * @return The newly created response */ public static ClientDriverResponse giveResponseAsBytes(InputStream content, String contentType) { return new ClientDriverResponse(content, contentType); }
/** * <p>Creates a new response with the given body, a suitable default status * code and a Content-Type of 'text/plain'.</p> * <p>If the content given is null a 204 status code is given, otherwise 200.</p> * * @param content * The content of the response * @deprecated Use {@link #ClientDriverResponse(String, String)} instead. */ @Deprecated public ClientDriverResponse(String content) { this(convertStringToByteArray(content), DEFAULT_TEXT_CONTENT_TYPE); }
/** * Creates a new {@link ClientDriverResponse} object with no content. * * @return The newly created response */ public static ClientDriverResponse giveEmptyResponse() { return new ClientDriverResponse(); }
/** * <p>Creates a new response with the given body, a suitable default status * code and a Content-Type of 'text/plain'.</p> * <p>If the content given is null a 204 status code is given, otherwise 200.</p> * * @param content * The content of the response * @deprecated Use {@link #ClientDriverResponse(String, String)} instead. */ @Deprecated public ClientDriverResponse(String content) { this(convertStringToByteArray(content), DEFAULT_TEXT_CONTENT_TYPE); }