本文整理了Java中org.mockserver.model.HttpResponse.getFirstHeader()
方法的一些代码示例,展示了HttpResponse.getFirstHeader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getFirstHeader()
方法的具体详情如下:
包路径:org.mockserver.model.HttpResponse
类名称:HttpResponse
方法名:getFirstHeader
暂无
代码示例来源:origin: jamesdbloom/mockserver
private void setHeaderIfNotAlreadyExists(HttpResponse response, String name, String value) {
if (response.getFirstHeader(name).isEmpty()) {
response.withHeader(name, value);
}
}
代码示例来源:origin: jamesdbloom/mockserver
private ByteBuf getBody(HttpResponse response) {
ByteBuf content = Unpooled.buffer(0, 0);
Body body = response.getBody();
if (body != null) {
Object bodyContents = body.getValue();
Charset bodyCharset = body.getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(response.getFirstHeader(CONTENT_TYPE.toString())));
if (bodyContents instanceof byte[]) {
content = Unpooled.copiedBuffer((byte[]) bodyContents);
} else if (bodyContents instanceof String) {
content = Unpooled.copiedBuffer(((String) bodyContents).getBytes(bodyCharset));
} else if (body.toString() != null) {
content = Unpooled.copiedBuffer(body.toString().getBytes(bodyCharset));
}
}
return content;
}
代码示例来源:origin: jamesdbloom/mockserver
throw new IllegalArgumentException(response.getBodyAsString());
String serverVersion = response.getFirstHeader("version");
String clientVersion = Version.getVersion();
if (!Strings.isNullOrEmpty(serverVersion) &&
代码示例来源:origin: jamesdbloom/mockserver
private void setBody(HttpResponse httpResponse, HttpServletResponse httpServletResponse) {
if (httpResponse.getBodyAsString() != null) {
if (httpResponse.getBody() instanceof BinaryBody) {
IOStreamUtils.writeToOutputStream(base64Converter.base64StringToBytes(httpResponse.getBodyAsString()), httpServletResponse);
} else {
Charset bodyCharset = httpResponse.getBody().getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(httpResponse.getFirstHeader(CONTENT_TYPE.toString())));
IOStreamUtils.writeToOutputStream(httpResponse.getBodyAsString().getBytes(bodyCharset), httpServletResponse);
}
}
}
代码示例来源:origin: jamesdbloom/mockserver
if (Strings.isNullOrEmpty(response.getFirstHeader(CONTENT_TYPE.toString()))) {
if (response.getBody() != null
&& response.getBody().getContentType() != null) {
if (Strings.isNullOrEmpty(response.getFirstHeader(CONTENT_LENGTH.toString()))) {
ConnectionOptions connectionOptions = response.getConnectionOptions();
boolean overrideContentLength = connectionOptions != null && connectionOptions.getContentLengthHeaderOverride() != null;
if (body != null) {
Object bodyContents = body.getValue();
Charset bodyCharset = body.getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(response.getFirstHeader(CONTENT_TYPE.toString())));
if (bodyContents instanceof byte[]) {
bodyBytes = (byte[]) bodyContents;
代码示例来源:origin: jamesdbloom/mockserver
if (deserializedMessage instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) deserializedMessage;
String firstHeader = httpResponse.getFirstHeader(WEB_SOCKET_CORRELATION_ID_HEADER_NAME);
WebSocketResponseCallback webSocketResponseCallback = responseCallbackRegistry.get(firstHeader);
if (webSocketResponseCallback != null) {
代码示例来源:origin: org.mock-server/mockserver-core
private void setHeaderIfNotAlreadyExists(HttpResponse response, String name, String value) {
if (response.getFirstHeader(name).isEmpty()) {
response.withHeader(name, value);
}
}
代码示例来源:origin: org.mock-server/mockserver-core
private ByteBuf getBody(HttpResponse response) {
ByteBuf content = Unpooled.buffer(0, 0);
Body body = response.getBody();
if (body != null) {
Object bodyContents = body.getValue();
Charset bodyCharset = body.getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(response.getFirstHeader(CONTENT_TYPE.toString())));
if (bodyContents instanceof byte[]) {
content = Unpooled.copiedBuffer((byte[]) bodyContents);
} else if (bodyContents instanceof String) {
content = Unpooled.copiedBuffer(((String) bodyContents).getBytes(bodyCharset));
} else if (body.toString() != null) {
content = Unpooled.copiedBuffer(body.toString().getBytes(bodyCharset));
}
}
return content;
}
代码示例来源:origin: org.mock-server/mockserver-client-java
throw new IllegalArgumentException(response.getBodyAsString());
String serverVersion = response.getFirstHeader("version");
String clientVersion = Version.getVersion();
if (!Strings.isNullOrEmpty(serverVersion) &&
代码示例来源:origin: org.mock-server/mockserver-core
if (Strings.isNullOrEmpty(response.getFirstHeader(CONTENT_TYPE.toString()))) {
if (response.getBody() != null
&& response.getBody().getContentType() != null) {
if (Strings.isNullOrEmpty(response.getFirstHeader(CONTENT_LENGTH.toString()))) {
ConnectionOptions connectionOptions = response.getConnectionOptions();
boolean overrideContentLength = connectionOptions != null && connectionOptions.getContentLengthHeaderOverride() != null;
if (body != null) {
Object bodyContents = body.getValue();
Charset bodyCharset = body.getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(response.getFirstHeader(CONTENT_TYPE.toString())));
if (bodyContents instanceof byte[]) {
bodyBytes = (byte[]) bodyContents;
代码示例来源:origin: org.mock-server/mockserver-core
private void setBody(HttpResponse httpResponse, HttpServletResponse httpServletResponse) {
if (httpResponse.getBodyAsString() != null) {
if (httpResponse.getBody() instanceof BinaryBody) {
IOStreamUtils.writeToOutputStream(base64Converter.base64StringToBytes(httpResponse.getBodyAsString()), httpServletResponse);
} else {
Charset bodyCharset = httpResponse.getBody().getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(httpResponse.getFirstHeader(CONTENT_TYPE.toString())));
IOStreamUtils.writeToOutputStream(httpResponse.getBodyAsString().getBytes(bodyCharset), httpServletResponse);
}
}
}
代码示例来源:origin: org.mock-server/mockserver-core
void receivedTextWebSocketFrame(TextWebSocketFrame textWebSocketFrame) {
try {
Object deserializedMessage = webSocketMessageSerializer.deserialize(textWebSocketFrame.text());
if (deserializedMessage instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) deserializedMessage;
String firstHeader = httpResponse.getFirstHeader(WEB_SOCKET_CORRELATION_ID_HEADER_NAME);
WebSocketResponseCallback webSocketResponseCallback = callbackResponseRegistry.get(firstHeader);
if (webSocketResponseCallback != null) {
webSocketResponseCallback.handle(httpResponse);
}
} else if (deserializedMessage instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) deserializedMessage;
WebSocketRequestCallback webSocketRequestCallback = callbackForwardRegistry.get(httpRequest.getFirstHeader(WEB_SOCKET_CORRELATION_ID_HEADER_NAME));
if (webSocketRequestCallback != null) {
webSocketRequestCallback.handle(httpRequest);
}
} else {
throw new WebSocketException("Unsupported web socket message " + deserializedMessage);
}
} catch (Exception e) {
throw new WebSocketException("Exception while receiving web socket message" + textWebSocketFrame.text(), e);
}
}
内容来源于网络,如有侵权,请联系作者删除!