mendhak / teamcity-stash

TeamCity - Stash integration. Plugin for TeamCity which updates Stash with build statuses
https://code.mendhak.com/teamcity-stash/
54 stars 17 forks source link

JSON generation seems to be broken when using latest TeamCity (8.0.6) #17

Closed pedropombeiro closed 10 years ago

pedropombeiro commented 10 years ago

I recently upgraded to TeamCity 8.0.6 and I'm not sure if it is because of that, but the TeamCity/Stash integration stopped working. I looked at the atlassian-stash.log file and I have plenty of JSON parsing exceptions. It looks like the JSON is not UTF-8 encoded, as Stash is expecting.

I took a look around the web and found a hint: http://stackoverflow.com/a/18176032

Can you confirm that the plugin is using the default charset, and not explicitly enforcing UTF-8?

Thanks for your help, Pedro

2014-02-11 05:28:11,228 ERROR [http-bio-80-exec-2] Admin 328x12854x0 1ybsaqb 10.27.184.62 "POST /rest/build-status/1.0/commits/e8e48809370a93e2da82340bbe7410bec498b501 HTTP/1.1" c.a.s.r.e.UnhandledExceptionMapper Unhandled exception while processing REST call
org.codehaus.jackson.JsonParseException: Invalid UTF-8 middle byte 0x76
 at [Source: org.apache.catalina.connector.CoyoteInputStream@44e9027f; line: 6, column: 96]
    at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.impl.Utf8StreamParser._reportInvalidOther(Utf8StreamParser.java:2802) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.impl.Utf8StreamParser._reportInvalidOther(Utf8StreamParser.java:2809) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.impl.Utf8StreamParser._decodeUtf8_3fast(Utf8StreamParser.java:2632) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.impl.Utf8StreamParser._finishString2(Utf8StreamParser.java:1950) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.impl.Utf8StreamParser._finishString(Utf8StreamParser.java:1899) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.impl.Utf8StreamParser.getText(Utf8StreamParser.java:276) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.map.deser.std.UntypedObjectDeserializer.deserialize(UntypedObjectDeserializer.java:59) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.map.deser.std.MapDeserializer._readAndBind(MapDeserializer.java:319) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:249) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:33) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2695) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308) ~[atlassian-rest-module-2.8.2_1384118242000.jar:1.9.13]
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419) ~[atlassian-rest-module-2.8.2_1384118242000.jar:na]
    at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:25) [applinks-plugin-4.0.10_1384733014000.jar:na]
    at com.atlassian.stash.internal.spring.security.StashAuthenticationFilter.onSuccess(StashAuthenticationFilter.java:225) [StashAuthenticationFilter.class:na]
    at com.atlassian.stash.internal.spring.security.StashAuthenticationFilter.doFilter(StashAuthenticationFilter.java:108) [StashAuthenticationFilter.class:na]
    at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doInsideSpringSecurityChain(BeforeLoginPluginAuthenticationFilter.java:111) [BeforeLoginPluginAuthenticationFilter.class:na]
    at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:77) [BeforeLoginPluginAuthenticationFilter.class:na]
    at com.atlassian.security.auth.trustedapps.filter.TrustedApplicationsFilter.doFilter(TrustedApplicationsFilter.java:100) [atlassian-trusted-apps-core-3.0.2.jar:na]
    at com.atlassian.oauth.serviceprovider.internal.servlet.OAuthFilter.doFilter(OAuthFilter.java:61) [atlassian-oauth-service-provider-plugin-1.9.0-m3_1384118242000.jar:na]
    at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doBeforeBeforeLoginFilters(BeforeLoginPluginAuthenticationFilter.java:89) [BeforeLoginPluginAuthenticationFilter.class:na]
    at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:75) [BeforeLoginPluginAuthenticationFilter.class:na]
    at com.atlassian.stash.internal.request.DefaultRequestManager.doAsRequest(DefaultRequestManager.java:72) [stash-service-impl-2.10.1.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_45]
    at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
    ... 170 frames trimmed
pedropombeiro commented 10 years ago

On teamcity-winservice.log:

[2014-02-11 10:16:14,772] stdout                            [Info] Auth header: QWRtaW46TGllYmhlcnItMQ==
[2014-02-11 10:16:14,972] stdout                            [Info] Could not send data to Stash.
[2014-02-11 10:16:14,972] stdout                            [Info] Server returned HTTP response code: 500 for URL: http://stash/rest/build-status/1.0/commits/70c97cc05e84b2e0b800d1b40c2f47779f97f58f
[2014-02-11 10:16:14,972] stdout                            [Info] [Ljava.lang.StackTraceElement;@36da3c
[2014-02-11 10:16:14,972] stdout                            [Info] Updated Stash status for revision: 70c97cc05e84b2e0b800d1b40c2f47779f97f58f, buildId: 68346, status: SUCCESSFUL
[2014-02-11 10:17:50,096] stdout                            [Info] Scheduling Stash status update for hash: 70c97cc05e84b2e0b800d1b40c2f47779f97f58f, buildId: 68345, status: SUCCESSFUL
[2014-02-11 10:17:50,096] stdout                            [Info] Sending build status to http://stash/rest/build-status/1.0/commits/70c97cc05e84b2e0b800d1b40c2f47779f97f58f
[2014-02-11 10:17:50,096] stdout                            [Info] With body: {
[2014-02-11 10:17:50,096] stdout                            [Info]     "state": "SUCCESSFUL",
[2014-02-11 10:17:50,096] stdout                            [Info]     "key": "68345",
[2014-02-11 10:17:50,096] stdout                            [Info]     "name": "Build #1.0.22.11066, Tests passed: 5395, ignored: 1",
[2014-02-11 10:17:50,096] stdout                            [Info]     "url": "http://teamcity/viewLog.html?buildId=68345&buildTypeId=Lidia_Features_UnitTest",
[2014-02-11 10:17:50,096] stdout                            [Info]     "description": "[Lioba Family :: LIDIA :: Features :: Unit Test] février 11, 2014 10:17"
[2014-02-11 10:17:50,096] stdout                            [Info] }
[2014-02-11 10:17:50,096] stdout                            [Info] Auth header: QWRtaW46TGllYmhlcnItMQ==
[2014-02-11 10:17:50,196] stdout                            [Info] Could not send data to Stash.
[2014-02-11 10:17:50,196] stdout                            [Info] Server returned HTTP response code: 500 for URL: http://stash/rest/build-status/1.0/commits/70c97cc05e84b2e0b800d1b40c2f47779f97f58f
[2014-02-11 10:17:50,196] stdout                            [Info] [Ljava.lang.StackTraceElement;@1cebfd
[2014-02-11 10:17:50,196] stdout                            [Info] Updated Stash status for revision: 70c97cc05e84b2e0b800d1b40c2f47779f97f58f, buildId: 68345, status: SUCCESSFUL
[2014-02-11 10:17:51,605] stdout                            [Info] Scheduling Stash status update for hash: 70c97cc05e84b2e0b800d1b40c2f47779f97f58f, buildId: 68348, status: IN_PROGRESS
[2014-02-11 10:17:51,605] stdout                            [Info] Sending build status to http://stash/rest/build-status/1.0/commits/70c97cc05e84b2e0b800d1b40c2f47779f97f58f
[2014-02-11 10:17:51,605] stdout                            [Info] With body: {
[2014-02-11 10:17:51,605] stdout                            [Info]     "state": "INPROGRESS",
[2014-02-11 10:17:51,605] stdout                            [Info]     "key": "68348",
[2014-02-11 10:17:51,605] stdout                            [Info]     "name": "Build #1.0.22.11066, Running",
[2014-02-11 10:17:51,605] stdout                            [Info]     "url": "http://teamcity/viewLog.html?buildId=68348&buildTypeId=Lidia_Features_CreateClickOnceApplicationManifest",
[2014-02-11 10:17:51,605] stdout                            [Info]     "description": "[Lioba Family :: LIDIA :: Features :: Create ClickOnce Application Manifest] février 11, 2014 10:17"
[2014-02-11 10:17:51,605] stdout                            [Info] }
mendhak commented 10 years ago

Is your build configuration called février ? I'm not setting an encoding anywhere, so your investigation is probably correct. I'll need to set an encoding somewhere.

The code will be erroring here:

https://github.com/mendhak/teamcity-stash/blob/master/server/src/main/java/mendhak/teamcity/stash/api/StashClient.java

pedropombeiro commented 10 years ago

The build configuration is called Lidia_Features_CreateClickOnceApplicationManifest.

mendhak commented 10 years ago

Ah, the février must be February.

pedropombeiro commented 10 years ago

Exactly :-)

mendhak commented 10 years ago

The problem was here. I tried with wr.writeUtf, and wr.writeBytes, didn't work. I changed it to use wr.write and used String.getBytes("UTF-8") instead.

        DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.write(body.getBytes("UTF-8"));
        wr.flush();
        wr.close();

Seems to be working now.

I've updated the zip. Please test, let me know if it doesn't work.

pedropombeiro commented 10 years ago

Awesome, you're the man! Thanks for being so reactive!

I'll try it out tomorrow morning.

pedropombeiro commented 10 years ago

I can confirm it works now. Thanks again!