Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] After upgrading to 9.4.14.v20181114 getContentAsString() prepends previously fetched strings


It looks like a change in BufferingResponseListener, which used to allocate a new buffer in onHeaders.   It now will just keep accumulating responses!

A work around until this is fixed is to assign a new BufferingResponseListener for each request.    





On Sun, 2 Dec 2018 at 16:19, Alexander Farber <alexander.farber@xxxxxxxxx> wrote:
Good afternoon,

I run a custom WebSocketServlet for Jetty, which sends short text push notifications (for an async mobile and desktop word game) to many platforms (Facebook, Vk.com, Mail.ru, Ok.ru also Firebase and Amazon messaging) using a Jetty HttpClient instance:

public class MyServlet extends WebSocketServlet {
    private final SslContextFactory mSslFactory = new SslContextFactory();
    private final HttpClient mHttpClient = new HttpClient(mSslFactory);

    @Override
    public void init() throws ServletException {
        super.init();

        try {
            mHttpClient.start();
        } catch (Exception ex) {
            throw new ServletException(ex);
        }

        mFcm      = new Fcm(mHttpClient);    // Firebase
        mAdm      = new Adm(mHttpClient);    // Amazon
        mApns     = new Apns(mHttpClient);   // Apple
        mFacebook = new Facebook(mHttpClient);
        mMailru   = new Mailru(mHttpClient);
        mOk       = new Ok(mHttpClient);
        mVk       = new Vk(mHttpClient);
    }

This has worked very good for the past year (thank you!), but since I have recently upgraded my WAR-file to use Jetty 9.4.14.v20181114 the trouble has begun -

public class Facebook {
    private final static String APP_ID      = "XXXXX";
    private final static String APP_SECRET  = "XXXXX";
    private final static String MESSAGE_URL = "https://graph.facebook.com/%s/notifications?" +
            // the app access token is: "app id | app secret"
            "access_token=%s%%7C%s" +
            "&template=%s";

    private final HttpClient mHttpClient;

    public Facebook(HttpClient httpClient) {
        mHttpClient = httpClient;
    }

    private final BufferingResponseListener mMessageListener = new BufferingResponseListener() {
        @Override
        public void onComplete(Result result) {
            if (!result.isSucceeded()) {
                LOG.warn("facebook failure: {}", result.getFailure());
                return;
            }

            try {
                // THE jsonStr SUDDENLY CONTAINS PREVIOUS CONTENT!
                String jsonStr = getContentAsString(StandardCharsets.UTF_8);
                LOG.info("facebook success: {}", jsonStr);
            } catch (Exception ex) {
                LOG.warn("facebook exception: ", ex);
            }
        }
    };

    public void postMessage(int uid, String sid, String body) {
        String url = "" sid, APP_ID, APP_SECRET, UrlEncoded.encodeString(body));
        mHttpClient.POST(url).send(mMessageListener);
    }
}

Suddenly the getContentAsString method called for successful HttpClient invocations started to deliver the strings, which were fetched previously - prepended to the the actual result string.

What could it be please, is it some changed BufferingResponseListener behaviour or maybe some non-obvious Java quirk?

Best regards
Alex

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users


--

Back to the top