Redmine API doesn't work after 2.0.3 upgrade

Added by Jon Lumpkin about 8 years ago

Was previously running 1.0.1, and had some simple code to call the API. After the upgrade, I now get a 500 error on the post.

Log shows something like this:

Started POST "/redmine/issues.json" for 127.0.0.1 at Thu Jun 28 16:12:37 -0400 2012

MultiJson::DecodeError (705: unexpected token at ''issue': { 'project_id': 'asystem','subject': 'Object reference not set to an instance of an object.','description': 'Stack Trace:    at App.proxy.CheckStatus() :
  json-1.4.6-x86 (mingw32) lib/json/common.rb:146:in `parse'
  json-1.4.6-x86 (mingw32) lib/json/common.rb:146:in `parse'
  multi_json (1.1.0) lib/multi_json/engines/json_common.rb:9:in `decode'
  multi_json (1.1.0) lib/multi_json.rb:79:in `decode'
  activesupport (3.2.6) lib/active_support/json/decoding.rb:17:in `decode'
  actionpack (3.2.6) lib/action_dispatch/middleware/params_parser.rb:47:in `parse_formatted_parameters'
  actionpack (3.2.6) lib/action_dispatch/middleware/params_parser.rb:17:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/cookies.rb:338:in `call'
  activerecord (3.2.6) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
  activesupport (3.2.6) lib/active_support/callbacks.rb:405:in `_run__940163778__call__4__callbacks'
  activesupport (3.2.6) lib/active_support/callbacks.rb:405:in `send'
  activesupport (3.2.6) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.6) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.6) lib/active_support/callbacks.rb:81:in `send'
  activesupport (3.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.6) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.6) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.6) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/static.rb:62:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:143:in `pass'
  rack-cache (1.2) lib/rack/cache/context.rb:155:in `invalidate'
  rack-cache (1.2) lib/rack/cache/context.rb:71:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  railties (3.2.6) lib/rails/engine.rb:479:in `call'
  railties (3.2.6) lib/rails/application.rb:220:in `call'
  railties (3.2.6) lib/rails/railtie/configurable.rb:30:in `send'
  railties (3.2.6) lib/rails/railtie/configurable.rb:30:in `method_missing'
  rack (1.4.1) lib/rack/urlmap.rb:64:in `call'
  rack (1.4.1) lib/rack/urlmap.rb:49:in `each'
  rack (1.4.1) lib/rack/urlmap.rb:49:in `call'
  thin (1.3.1) lib/thin/connection.rb:80:in `pre_process'
  thin (1.3.1) lib/thin/connection.rb:78:in `catch'
  thin (1.3.1) lib/thin/connection.rb:78:in `pre_process'
  thin (1.3.1) lib/thin/connection.rb:53:in `process'
  thin (1.3.1) lib/thin/connection.rb:38:in `receive_data'
  eventmachine (0.12.10) lib/eventmachine.rb:256:in `run_machine'
  eventmachine (0.12.10) lib/eventmachine.rb:256:in `run'
  thin (1.3.1) lib/thin/backends/base.rb:61:in `start'
  thin (1.3.1) lib/thin/server.rb:159:in `start'
  thin (1.3.1) lib/thin/controllers/controller.rb:86:in `start'
  thin (1.3.1) lib/thin/runner.rb:185:in `send'
  thin (1.3.1) lib/thin/runner.rb:185:in `run_command'
  thin (1.3.1) lib/thin/runner.rb:151:in `run!'
  thin (1.3.1) bin/thin:6
  bin/thin:16:in `load'
  bin/thin:16

How do we get around this?

Replies (7)

RE: Redmine API doesn't work after 2.0.3 upgrade - Added by Jon Lumpkin about 8 years ago

Well, it looks like the way it parses JSON has changed quite a bit. As in, a bit more strict. I can now submit an issue, but what would be the right way to encode something like a stack trace, where one would have new lines?

RE: Redmine API doesn't work after 2.0.3 upgrade - Added by William Roush about 8 years ago

Jon Lumpkin wrote:

Well, it looks like the way it parses JSON has changed quite a bit. As in, a bit more strict. I can now submit an issue, but what would be the right way to encode something like a stack trace, where one would have new lines?

Can you post your current JSON request and the more strict one that works?

I'm curious if the strictness is a bug or if it enforcing proper JSON was a bug fix before you go posting it to the issue tracker.

RE: Redmine API doesn't work after 2.0.3 upgrade - Added by Jon Lumpkin about 8 years ago

Sorry about the late reply. It used to look like:

"'issue': { " +
"'project_id': 'system', " +
"'subject': '" + message + "'," +
"'description': '" + theDescription + "'" +
"}"

What I changed it too now looks like this:

"{\"issue\": { " +
"\"project_id\": \"" + redmineProjectID + "\"," +
"\"subject\": \"" + message + "\"," +
"\"description\": \"" + theDescription + "\"" +
"}}"
What changed was:
  • wrap the whole request in {}
  • " versus '

So, it looks like over the time of our setup (from 1.0.1 to 2.0.3), something really changed with the way JSON is parsed, and perhaps became more strict (my previous one doesn't verify I do not think).

So, by making those changes, the only thing that doesn't work now is my theDescription. This is a multiline string (http://www.redmine.org/boards/2/topics/30999), but I was using Microsoft's .net Server.HTMLEncode() (http://msdn.microsoft.com/en-us/library/w3te6wfz.aspx) method to encode this. I don't think that's placing the new lines correctly, but it worked in previous iterations. If I just put a random string (or literally pass the string 'theDescription'), the new way works.

theDescription is something like this:

Stack Trace:
   at System.Windows.Window.OnClosing(CancelEventArgs e)
   at System.Windows.Window.WmClose()
   at System.Windows.Window.WindowFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

Report Number: 

Report Key: 0

User: randomuser

Machine: amachine

Server:

I am just wondering what changed with the way it handles this formatted text (basically just need newlines), and how I should handle that, especially in a .net world.

RE: Redmine API doesn't work after 2.0.3 upgrade - Added by Alexey Filatov almost 8 years ago

I have the same problem when I try to send multistring. It works in 1.3 and I don't know what to do now. My perl example:

my $str = sprintf('{"issue": {"notes": "%s", "custom_field_values":{"4":"%u"}}}', join("\n", @changed), $rev);

How to send the text with several strings?

RE: Redmine API doesn't work after 2.0.3 upgrade - Added by Etienne Massip almost 8 years ago

GIYF:

With .Net, use HttpUtility JavaScriptStringEncode() methods.

With Perl, you can try e.g. JavaScript-Value-Escape.

RE: Redmine API doesn't work after 2.0.3 upgrade - Added by Alexey Filatov almost 8 years ago

I've changed "\n" to "\r" and how it works.

$files = join("", @changed);
$files =~ s/\n/\\r/g;
$files =~ s/\'/\\'/g;

RE: Redmine API doesn't work after 2.0.3 upgrade - Added by Jon Lumpkin almost 8 years ago

Changing mine to use HttpUtilityJavaScriptStringEncode, as well as changing my \n to \r fixed the issue. Now to figure out why JavaScriptSerializer.Deserialize gives me back a different object. It now looks like the JSON returned has an extra level deep.

(1-7/7)