Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.client;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.List;
import java.util.function.LongConsumer;
import java.util.function.ObjLongConsumer;
import java.util.stream.Collectors;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.CountingCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ResponseNotifier
{
private static final Logger LOG = LoggerFactory.getLogger(ResponseNotifier.class);
public void notifyBegin(List listeners, Response response)
{
for (Response.ResponseListener listener : listeners)
{
if (listener instanceof Response.BeginListener)
notifyBegin((Response.BeginListener)listener, response);
}
}
private void notifyBegin(Response.BeginListener listener, Response response)
{
try
{
listener.onBegin(response);
}
catch (Throwable x)
{
LOG.info("Exception while notifying listener {}", listener, x);
}
}
public boolean notifyHeader(List listeners, Response response, HttpField field)
{
boolean result = true;
for (Response.ResponseListener listener : listeners)
{
if (listener instanceof Response.HeaderListener)
result &= notifyHeader((Response.HeaderListener)listener, response, field);
}
return result;
}
private boolean notifyHeader(Response.HeaderListener listener, Response response, HttpField field)
{
try
{
return listener.onHeader(response, field);
}
catch (Throwable x)
{
LOG.info("Exception while notifying listener {}", listener, x);
return false;
}
}
public void notifyHeaders(List listeners, Response response)
{
for (Response.ResponseListener listener : listeners)
{
if (listener instanceof Response.HeadersListener)
notifyHeaders((Response.HeadersListener)listener, response);
}
}
private void notifyHeaders(Response.HeadersListener listener, Response response)
{
try
{
listener.onHeaders(response);
}
catch (Throwable x)
{
LOG.info("Exception while notifying listener {}", listener, x);
}
}
public void notifyBeforeContent(Response response, ObjLongConsumer