Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jumblrClient.blogAvatar() gets wrong response code? #94

Open
BryanRansil opened this issue May 1, 2016 · 4 comments · May be fixed by #95
Open

jumblrClient.blogAvatar() gets wrong response code? #94

BryanRansil opened this issue May 1, 2016 · 4 comments · May be fixed by #95

Comments

@BryanRansil
Copy link

Firstly thanks to everyone who contributed to this api, it's fun to play with!
I'm trying to get the blog avatar right now, and that goes to requestBuilder.getRedirectUrl(). I'm getting a response code of 200 (HTTP_OK) as opposed to 301 (HTTP_MOVED_PERMANENTLY). It seems HTTP_OK the response doesn't have the Location header, so it makes sense to not try to use the response. However I don't know if there's anything I can do on my side to deal with this (like something I've just not setup correctly) or if I can get help from anyone for how to debug this further. Any help would be appreciated!

@ceyko
Copy link
Contributor

ceyko commented May 2, 2016

@BryanRansil I just gave it a test and do receive a 301 response when requesting an avatar.

Input

User user = client.user();
Blog blog = user.getBlogs().get(0);
System.out.println("Blog.avatar(): " + blog.avatar());
System.out.println("JumblrClient.blogAvatar(): " + client.blogAvatar(blog.getName()));

Output

Blog.avatar(): https://secure.assets.tumblr.com/images/default_avatar/pyramid_open_64.png
JumblrClient.blogAvatar(): https://secure.assets.tumblr.com/images/default_avatar/pyramid_open_64.png

I also checked the request directly in curl.

Curl (abridged)

$ curl -v https://api.tumblr.com/v2/blog/staff.tumblr.com/avatar
> GET /v2/blog/staff.tumblr.com/avatar HTTP/1.1
< HTTP/1.1 301 Moved Permanently
{"meta":{"status":301,"msg":"Moved Permanently"},"response":{"avatar_url":"https:\/\/66.media.tumblr.com\/avatar_db722a134cda_64.png"}}

Closing this issue unless @BryanRansil can provide some code to reproduce.

@ceyko ceyko closed this as completed May 2, 2016
@BryanRansil
Copy link
Author

BryanRansil commented May 2, 2016

@ceyko Thanks for the quick response! I tried the code you provided on two phones, one which is Ice Cream Sandwich (where it worked) and one which is an LG3 on Marshmellow (where it failed). Hopefully I can test my current theory that it's a Marshmellow issue by downgrading the Marshmellow phone and seeing if it still works but won't be getting to it tonight. Here's the error that appears when I try on the LG3:

05-01 23:08:00.285 2405-2435/com.coderealities.simpletumblr E/AndroidRuntime: FATAL EXCEPTION: Thread-7189
                                                                              Process: com.coderealities.simpletumblr, PID: 2405
                                                                              �
                                                                              aIDATx��Zkl\G�����zw��;M��i�5iK�
                                                                              ���x^m������;����v�_��Xf��� ~�W�+��.��yQ�|.���~k���_�]�o�ɀN�S���3����)��R#�    >6_{%��z�c%d�E
                                                                              �R ������섑 9���.
                                                                              ��:[��BA��s664�Nj�L���LY
                                                                              �@�r���(��u��������UM��y��Xu�������`����+�}�l6U��`�(���>���O�Ve�n낹�'�W�"U�,����$y�
                                                                              �����h����@~���j�$�I{�^�H���)(��✁Z�'�{�=�U ���0T�����8�kEn��>��l�~X�*���J$6Mfp��C�P�Z�Fͮ4������N����������ލ�'�U]�9BU��9A��$C������,1���De����+��!�
05-01 23:08:00.486 2405-2434/com.coderealities.simpletumblr E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb3158470

And here's what I get when I print the error message and stacktrace:

05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: �
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: (
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: q���D�5`��z� @SP�����0�@��@�a����"P��*hZT��.�    ��Q5��R1jd"G�M�
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: ����S���eH��
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: �$#%��d��$�&���&�f�
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: r2\���O1
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: ��ID���y2<�La�b``a�S���&b�-�d�g�����D�#(��G��!��.0��
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: ƇY����R�*���3D����ɕ���nf�=��{��*X kTph��)!}FغI@� C��*��K����LR"����Fc���p�JS!Cc�h���#�������6r^������u$�����F`�Ma�Ql���%�s�¤�s
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: 4�P�&��6g�M
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: v�l���-
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: ����uY�j��K�5L��B���-��a��.�;E��������J^��h�����=o�ب2<����%��@��,�c�.� ��h\]P���#$Ua��#l�-�3ПƗ�-%��kL�|�R1=�l�8f�G���x�����UY�ǣ��z�E$�`ԱuFOE$�H/۳�������)I2D�����d���Q/y#GS�gJ/�x�.�a�W�XM��_��:�#��I�_��?�`������bM��:E�Q��t���#�P4��[���e�VDz�
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: q��]����0����"S�B�{�)*�����`�� ��u�Kv�x�    ��������0�]o_����$��e��J�žPI��V�D�x���8���:    .�v���1��5�B���.n�Q�Lf���������"�3�E�z�����s���2.PE���*&�����G
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: -�Hep���[��
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: �E̖�%5?v��w�k���^y��U7���r��   ��.Sh�/lL�<�`ٜ�.j�|f��!  ���JH%؞����Xe�J��d   F��E���Q��X�I�su~�=�y��"�D�qr���`x�������3H�ↀ�S���G��u'�P-�p݅9�l �u���pk��U��|`��5�=�{�c"��4�O�����m�`ࣅ����������gt&�-��ti�5�k���~�Gw�d��]��.PA�������g��/���'Z��yFOJKa�ƕ��F�IA�6ybc�#����8����8���,ӄ�
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: )p����I4
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: ���=>�����j��}�|�����;�+Cr�u��˓1���t��;�
05-01 23:12:53.388 3969-4005/com.coderealities.simpletumblr W/System.err: 5����Zkb$�b�I7�Ѯ�l��g������R���
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: ����z�X󴅤&�:J!��;:���S;��s��|�<��
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: ��*|,Ʋ}����r�V��k��1˜;�A�������\be0���ї�����S�,5�L��R��*�����-�׮ty��6�=5Cg�6��19�@���6�_�"����]���u�]����u�����48y�k�>BL���&�D��������Ӭ|�<�BP�r��9��D�N������x�3�_KUy8:�x��3z���1W]��
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: ��y
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: y�+�=�4"��FY�( M�Z:���$
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: %�W��66�y�cJ61��0���g�$b�%�:'�
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: �6ҙA�U�����"墕M0���Ɍ�����>� �0�5�y>��������/r�Z�}o>ʁ�/�|�i���"�����<������A�y��0ڳ�����}�������y̛N�3תr�#�x�I������q��Z�)r�`��X��t�V���7�r��T(����aN�����QC�2�" S=L��C�(!   ��%|���U�8Q�oI�,!�{�"!�
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: �����%F�9,�m����.W���mY�B�Л��X5�}����&��~�ُA���}���L��>�|�~9��\�ru��������y�ZiN��p�Z�grA�o��,^^����b�3����H����������F���"�i"������4��<1u��t�6�N���l�\D(m2�r2�(�p� �F!7��h�<N�Ƭ]{��/vy���:W�"Ð97_�S;p?ʒ�j�_����p����`�p`��fЎ�����>�3�r��BJ�5�לX�^�B
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: ��j�Tl��}�d�(�؎��F7p��F���
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: �F��S�qƍ�Ϯ����&���
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err: ��������;��Ml#�U����(�K�_%O��vI�.A����H���a�T�������g:�F��ҡ�׉��c*�l�bH�؀d�#�^�c�DJ�d�DA��+�_�4�8}b��{��3��$�s���q��I���~�%�? `���ױy�
05-01 23:12:53.389 3969-4005/com.coderealities.simpletumblr W/System.err:     at com.tumblr.jumblr.request.RequestBuilder.getRedirectUrl(RequestBuilder.java:49)
05-01 23:12:53.390 3969-4005/com.coderealities.simpletumblr W/System.err:     at com.tumblr.jumblr.JumblrClient.blogAvatar(JumblrClient.java:271)
05-01 23:12:53.390 3969-4005/com.coderealities.simpletumblr W/System.err:     at com.tumblr.jumblr.types.Blog.avatar(Blog.java:89)
05-01 23:12:53.390 3969-4005/com.coderealities.simpletumblr W/System.err:     at com.tumblr.jumblr.types.Blog.avatar(Blog.java:93)
05-01 23:12:53.390 3969-4005/com.coderealities.simpletumblr W/System.err:     at com.coderealities.simpletumblr.PostContent.loadSourceLine(PostContent.java:71)
05-01 23:12:53.390 3969-4005/com.coderealities.simpletumblr W/System.err:     at com.coderealities.simpletumblr.PostContent.<init>(PostContent.java:57)
05-01 23:12:53.390 3969-4005/com.coderealities.simpletumblr W/System.err:     at com.coderealities.simpletumblr.MainActivity$1.run(MainActivity.java:62)
05-01 23:12:53.390 3969-4005/com.coderealities.simpletumblr W/System.err:     at java.lang.Thread.run(Thread.java:818)
05-01 23:12:53.392 3969-4005/com.coderealities.simpletumblr E/AndroidRuntime: FATAL EXCEPTION: Thread-7361
                                                                              Process: com.coderealities.simpletumblr, PID: 3969
                                                                              �
                                                                              (
05-01 23:12:53.393 3969-4005/com.coderealities.simpletumblr D/Error: ERR: exClass=com.tumblr.jumblr.exceptions.JumblrException
                                                                     �
                                                                     (
05-01 23:12:53.394 3969-4005/com.coderealities.simpletumblr D/Error: ERR: file=RequestBuilder.java
05-01 23:12:53.394 3969-4005/com.coderealities.simpletumblr D/Error: ERR: class=com.tumblr.jumblr.request.RequestBuilder
05-01 23:12:53.394 3969-4005/com.coderealities.simpletumblr D/Error: ERR: method=getRedirectUrl line=49
                                                                     �
                                                                     (
05-01 23:12:53.394 3969-4005/com.coderealities.simpletumblr D/Error: ERR: TOTAL BYTES WRITTEN: 38852
05-01 23:12:53.688 3969-3993/com.coderealities.simpletumblr E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb3117970

Thanks for your time!

@ceyko
Copy link
Contributor

ceyko commented May 3, 2016

@BryanRansil It looks like it is still following the redirect. We do set it to not follow redirects immediately before making the request, and HttpURLConnection#setFollowRedirects() has existed since SDK v1, so I'm not sure if downgrading will fix it.

However, we do use the static version of this setter, so it affects and is affected by anything else calling it. Perhaps you have another thread which is calling HttpURLConnection.setFollowRedirects(true), and we're hitting a race condition.

In light of this, I'm reopening this issue, since it seems like we don't handle multithreading very well. We should replace the usage of HttpURLConnection#setFollowRedirects() with HttpURLConnection#setInstanceFollowRedirects(), or something similar.

@ceyko ceyko reopened this May 3, 2016
ceyko added a commit that referenced this issue May 3, 2016
When setting no-follow-redirects for an avatar request, do so only for
this one request. Previously, it was set globally for all requests, then
set back to its initial state after the request completed. This should
prevent multithreading issues where numerous threads are attempting to
alter the state of HttpURLConnection#setFollowRedirects().

Fixes #94
ceyko added a commit that referenced this issue May 3, 2016
When setting no-follow-redirects for RequestBuilder#getRedirectUrl()
(e.g., avatar requests), do so only for this one request. Previously, it
was set globally for all requests, then set back to its initial state
after the request completed. This should prevent multithreading issues
where numerous threads are attempting to alter the global state of
HttpURLConnection#setFollowRedirects().

Fixes #94
ceyko added a commit that referenced this issue May 3, 2016
When setting no-follow-redirects for RequestBuilder#getRedirectUrl()
(e.g., avatar requests), do so only for this one request. Previously, it
was set globally for all requests, then set back to its initial state
after the request completed. This should prevent multithreading issues
where numerous threads are attempting to alter the global state of
HttpURLConnection#setFollowRedirects().

Fixes #94
@ceyko ceyko linked a pull request May 4, 2016 that will close this issue
@BryanRansil
Copy link
Author

Thanks! I've subscribed to the issue so I'll see how that goes.

BryanRansil added a commit to BryanRansil/SimpleTumblr that referenced this issue Sep 7, 2016
Using the jumblr api calls on an LG3 Phone with Marshmellow caused
a crash, specifically when attempting to get the avatar link. This
was mentioned in tumblr/jumblr#94, but
the crash was not reproduciable by the developers. After several
more attempts on my side to figure out what I was doing differently
I resorted to using the deeper level API to get the avatar.
After getting that to work, I refactored the AuthorView with this
new capability in mind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants