本文整理汇总了Java中org.eclipse.jetty.util.Callback类的典型用法代码示例。如果您正苦于以下问题:Java Callback类的具体用法?Java Callback怎么用?Java Callback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Callback类属于org.eclipse.jetty.util包,在下文中一共展示了Callback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onNext
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Override
public void onNext(ContentChunk chunk) {
provider.offer(chunk.buffer, new Callback.Nested(chunk.callback) {
@Override
public void succeeded() {
super.succeeded();
subscription.request(1);
}
@Override
public void failed(Throwable x) {
super.failed(x);
subscription.cancel();
}
});
}
示例2: setup
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Before
public void setup() throws MalformedURLException {
TestJMeterUtils.createJmeterEnv();
JMeterUtils.setProperty("HTTPResponse.parsers", "htmlParser");
JMeterUtils.setProperty("htmlParser.className","org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser");
JMeterUtils.setProperty("htmlParser.types","text/html application/xhtml+xml application/xml text/xml");
url = new URL("http://www.tenfieldigital.com.uy");
http2Connection = Mockito.mock(HTTP2Connection.class);
stream = Mockito.mock(Stream.class);
pushPromisFrame = Mockito.mock(PushPromiseFrame.class);
headersFrame = Mockito.mock(HeadersFrame.class);
responseMetadata = Mockito.mock(MetaData.Response.class);
callback = Mockito.mock(Callback.class);
dataFrame = Mockito.mock(DataFrame.class);
}
示例3: provideRuleById
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Test(timeout = 5000)
@Category({UnitTest.class})
public void provideRuleById() {
// Arrange
CompletionStage<RuleServiceModel> ruleResult =
Callback.Completable.completedFuture(null);
IRules rules = mock(IRules.class);
RulesController controller = new RulesController(rules);
when(rules.getAsync(
"1")).thenReturn(ruleResult);
// Act
controller.getAsync("1").thenApply(response -> {
// Assert
assertThat(response.body().isKnownEmpty(), is(false));
return null;
});
}
示例4: deleteRule
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Test(timeout = 5000)
@Category({UnitTest.class})
public void deleteRule() {
// Arrange
CompletionStage<Boolean> result =
Callback.Completable.completedFuture(null);
IRules rules = mock(IRules.class);
RulesController controller = new RulesController(rules);
when(rules.deleteAsync(
"1")).thenReturn(result);
// Act
controller.deleteAsync("1").thenApply(response -> {
// Assert
assertThat(response.body().isKnownEmpty(), is(false));
return null;
});
}
示例5: onResponseContent
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Override
protected void onResponseContent(final HttpServletRequest request, final HttpServletResponse response, final Response proxyResponse,
final byte[] buffer, final int offset, final int length, final Callback callback) {
final int plainStatus = needPlainPageErrorStatus(request, proxyResponse.getStatus());
if (plainStatus == 0) {
super.onResponseContent(request, response, proxyResponse, buffer, offset, length, callback);
} else {
try {
// Standard 404/... page, abort the original response
final RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/" + plainStatus + ".html");
dispatcher.forward(getRoot(request), response);
callback.succeeded();
} catch (final Exception e) {
callback.failed(e);
}
}
}
示例6: setup
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Before
public void setup() throws IllegalAccessException {
servletContext = Mockito.mock(ServletContext.class);
servlet = new BackendProxyServlet() {
/**
*
*/
private static final long serialVersionUID = 1L;
{
_log = Log.getLogger("junit");
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
FieldUtils.writeField(servlet, "_log", Mockito.mock(Logger.class), true);
callback = Mockito.mock(Callback.class);
}
示例7: onResponseContent
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Override
protected void onResponseContent(HttpServletRequest request, HttpServletResponse response, Response proxyResponse,
byte[] buffer, int offset, int length, Callback callback) {
// フィルタークラスで必要かどうかを判別後、必要であれば内容をキャプチャする
// 注意: 1回のリクエストで複数回の応答が帰ってくるので全ての応答をキャプチャする必要がある
if (Filter.isNeed(request.getServerName(), response.getContentType())) {
ByteArrayOutputStream stream = (ByteArrayOutputStream) request.getAttribute(Filter.RESPONSE_BODY);
if (stream == null) {
stream = new ByteArrayOutputStream();
request.setAttribute(Filter.RESPONSE_BODY, stream);
}
// ストリームに書き込む
stream.write(buffer, offset, length);
}
super.onResponseContent(request, response, proxyResponse, buffer, offset, length, callback);
}
示例8: handle
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Override
public void handle(String requestTarget, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest clientRequest, HttpServletResponse proxyResponse)
throws ServletException, IOException {
Dialog dialog = new Dialog(_log, clientRequest, proxyResponse);
DialogStrategy strategy = strategy(dialog);
if(strategy == null || !dialog.createServerRequest(strategy.target(), _client, _hostHeader, _viaHost, _timeout)){
return;
}
strategy.modifyRequestHeaders(dialog.proxyRequestHeaders());
// If there is content, the send of the proxy request
// is delayed and performed when the content arrives,
// to allow optimization of the Content-Length header.
if (dialog.hasRequestContent()){
DeferredContentProvider content = new DeferredContentProvider() {
@Override
public boolean offer(ByteBuffer buffer, Callback callback) {
_log.debug("{} proxying content to upstream: {} bytes", dialog.id(), buffer.remaining());
return super.offer(buffer, callback);
}
};
dialog.transferRequestContent(new ProxyReader(dialog, strategy, content), content);
}else{
dialog.send(new ProxyResponseListener(dialog, strategy));
}
}
示例9: onContent
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Override
public void onContent(final Response serverResponse, ByteBuffer content, final Callback callback) {
try {
int contentBytes = content.remaining();
_log.debug("{} received server content: {} bytes", dialog.id(), contentBytes);
hasContent = true;
boolean committed = dialog.hasAttribute(WRITE_LISTENER_ATTRIBUTE);
length += contentBytes;
boolean finished = length == dialog.getResponseContentLength();
ProxyWriter proxyWriter = write(content, finished, callback);
if (finished)
proxyWriter.offer(BufferUtil.EMPTY_BUFFER, complete);
if (committed) {
proxyWriter.onWritePossible();
} else {
dialog.write(proxyWriter);
}
} catch (Throwable x) {
callback.failed(x);
}
}
示例10: onContent
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Override
public void onContent(Response response, ByteBuffer buffer, Callback callback) {
if (logger.isDebugEnabled()) {
logger.debug("received response chunk {} {}", response, BufferUtil.toSummaryString(buffer));
}
content.offer(new ContentChunk(buffer, callback));
}
示例11: onRequest
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Override
protected void onRequest(long n) {
if (!complete) {
complete = true;
Subscriber<? super ContentChunk> subscriber = subscriber();
subscriber.onNext(new ContentChunk(ByteBuffer.wrap(bytes), Callback.NOOP));
subscriber.onComplete();
}
}
示例12: provideRulesList
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Test(timeout = 5000)
@Category({UnitTest.class})
public void provideRulesList() {
// Arrange
CompletionStage<List<RuleServiceModel>> ruleListResult =
Callback.Completable.completedFuture(null);
IRules rules = mock(IRules.class);
RulesController controller = new RulesController(rules);
when(rules.getListAsync(
"asc",
0,
1000,
null))
.thenReturn(ruleListResult);
// Act
controller.listAsync(
"asc",
0,
1000,
null)
.thenApply(response -> {
// Assert
assertThat(response.body().isKnownEmpty(), is(false));
return null;
});
}
示例13: itPostNewRuleWithNoEtagResultHasAllFields
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Test(timeout = 5000)
@Category({UnitTest.class})
public void itPostNewRuleWithNoEtagResultHasAllFields() throws Exception {
CompletionStage<RuleServiceModel> ruleResult =
Callback.Completable.completedFuture(null);
IRules rules = mock(IRules.class);
RulesController controller = new RulesController(rules);
when(rules.postAsync(this.sampleNewRuleServiceModel)).thenReturn(ruleResult);
mockHttpContex();
// Act
controller.postAsync().thenApply(response -> {
// Assert - that body is not null
assertThat(response.body().isKnownEmpty(), is(false));
// Assert - that body contains all fields
JsonNode responseBody = Json.parse(response.body().toString());
assertTrue(responseBody.hasNonNull("ETag"));
assertTrue(responseBody.hasNonNull("Id"));
assertTrue(responseBody.hasNonNull("Name"));
assertTrue(responseBody.hasNonNull("DateCreated"));
assertTrue(responseBody.hasNonNull("DateModified"));
assertTrue(responseBody.hasNonNull("Enabled"));
assertTrue(responseBody.hasNonNull("Description"));
assertTrue(responseBody.hasNonNull("GroupId"));
assertTrue(responseBody.hasNonNull("Severity"));
assertTrue(responseBody.hasNonNull("Conditions"));
return null;
});
}
示例14: itPutNewRuleWithNoEtagResultHasAllFields
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Test(timeout = 5000)
@Category({UnitTest.class})
public void itPutNewRuleWithNoEtagResultHasAllFields() throws Exception {
CompletionStage<RuleServiceModel> ruleResult =
Callback.Completable.completedFuture(null);
IRules rules = mock(IRules.class);
RulesController controller = new RulesController(rules);
when(rules.putAsync(this.sampleNewRuleServiceModel)).thenReturn(ruleResult);
mockHttpContex();
// Act
controller.postAsync().thenApply(response -> {
// Assert - that body is not null
assertThat(response.body().isKnownEmpty(), is(false));
// Assert - that body contains all fields
JsonNode responseBody = Json.parse(response.body().toString());
assertTrue(responseBody.hasNonNull("ETag"));
assertTrue(responseBody.hasNonNull("Id"));
assertTrue(responseBody.hasNonNull("Name"));
assertTrue(responseBody.hasNonNull("DateCreated"));
assertTrue(responseBody.hasNonNull("DateModified"));
assertTrue(responseBody.hasNonNull("Enabled"));
assertTrue(responseBody.hasNonNull("Description"));
assertTrue(responseBody.hasNonNull("GroupId"));
assertTrue(responseBody.hasNonNull("Severity"));
assertTrue(responseBody.hasNonNull("Conditions"));
return null;
});
}
示例15: onData
import org.eclipse.jetty.util.Callback; //导入依赖的package包/类
@Override
public void onData(Stream stream, DataFrame frame, Callback callback) {
LOG.info(frame);
callback.succeeded();
if (frame.isEndStream()) {
phaser.arrive();
}
}