com.github.dreamhead.moco.handler.AbstractHttpResponseHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moco-core Show documentation
Show all versions of moco-core Show documentation
Moco is an easy setup stub framework, mainly focusing on testing and integration.
package com.github.dreamhead.moco.handler;
import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.MutableHttpResponse;
import com.github.dreamhead.moco.Request;
import com.github.dreamhead.moco.Response;
import com.github.dreamhead.moco.internal.SessionContext;
public abstract class AbstractHttpResponseHandler extends AbstractResponseHandler {
protected abstract void doWriteToResponse(HttpRequest httpRequest, MutableHttpResponse httpResponse);
@Override
public void writeToResponse(final SessionContext context) {
Request request = context.getRequest();
Response response = context.getResponse();
if (HttpRequest.class.isInstance(request) && MutableHttpResponse.class.isInstance(response)) {
HttpRequest httpRequest = HttpRequest.class.cast(request);
MutableHttpResponse httpResponse = MutableHttpResponse.class.cast(response);
doWriteToResponse(httpRequest, httpResponse);
}
}
}