Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

GelfHTTPSender calls getBytes() without a charset #207

Closed
liufitch opened this issue Sep 10, 2019 · 8 comments
Closed

GelfHTTPSender calls getBytes() without a charset #207

liufitch opened this issue Sep 10, 2019 · 8 comments
Labels
type: bug A general bug
Milestone

Comments

@liufitch
Copy link

  • logstash-gelf version :1.13.0

  • logback version:1.0.13

configuration:

  <appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
        <host>https://**************/gelf</host>
        <version>1.1</version>
        <facility>logstash-gelf</facility>
        <additionalFields>***********</additionalFields>
        <additionalFieldTypes>*************</additionalFieldTypes>
        <maximumMessageSize>8192</maximumMessageSize>
    </appender>

The graylog support charset utf-8. but it shows incorrect chinese, so i want to set charset UTF-8 in the GelfLogbackAppender .but i didnt find any like charset tags.

Thanks.

@mp911de
Copy link
Owner

mp911de commented Sep 10, 2019

Can you grab a hex-dump of a packet and one of how it should be to investigate the issue?

There's no charset option that could be set.

We're using our own UTF-8 encoding, see https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java#L209.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Sep 10, 2019
@liufitch
Copy link
Author

thanks for your answer. i find the problem. its a environment problem.
if getBytes() has no any params, it will use system default encode.
reference:
https://docs.azure.cn/zh-cn/articles/azure-operations-guide/app-service-web/aog-app-service-web-java-qa-solve-messy-code-during-sending-chinese-characters-to-third-party-services

@liufitch liufitch reopened this Sep 10, 2019
@mp911de
Copy link
Owner

mp911de commented Sep 10, 2019

Is that a getBytes call in logstash-gelf? If so, can you share a link to see whether we can do something about it?

@liufitch
Copy link
Author

yeah. i just add a configuration file called web.config in the site/wwwroot folder and the content is

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%AZURE_TOMCAT85_HOME%\bin\startup.bat" arguments="">
      <environmentVariables>
        <environmentVariable name="JAVA_OPTS" value="-Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>
```. 

@mp911de
Copy link
Owner

mp911de commented Sep 10, 2019

That isn't what I asked for. Where is the call to getBytes()?

@liufitch
Copy link
Author

  • package: biz.paluch.logging.gelf.intern.sender

  • method: boolean sendMessage(GelfMessage message)
    ` HttpURLConnection connection = null;

      boolean var5;
      try {
          connection = (HttpURLConnection)this.url.openConnection();
          connection.setConnectTimeout(this.connectTimeoutMs);
          connection.setReadTimeout(this.readTimeoutMs);
          connection.setDoOutput(true);
          connection.setRequestMethod("POST");
          connection.addRequestProperty("Content-type", "application/json");
          OutputStream outputStream = connection.getOutputStream();
          outputStream.write(message.toJson().getBytes());
          outputStream.close();
          int responseCode = connection.getResponseCode();
          if (responseCode < 200 || responseCode > 299) {
              this.errorReporter.reportError("Server responded with unexpected status code: " + responseCode, (Exception)null);
              return false;
          }
    
          var5 = true;
      } catch (IOException var9) {
          this.errorReporter.reportError("Cannot send data to " + this.url, var9);
          return false;
      } finally {
          if (connection != null) {
              connection.disconnect();
          }
    
      }
    
      return var5;
    

    }`

@mp911de
Copy link
Owner

mp911de commented Sep 10, 2019

Thanks a lot. We're working with UTF8 all the time so we should change message.toJson().getBytes() to use UTF8 there as well.

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 10, 2019
@mp911de mp911de changed the title how to set charset UTF-8 with logback GelfHTTPSender calls getBytes() without a charset Sep 11, 2019
mp911de added a commit that referenced this issue Sep 11, 2019
We now consistently use UTF8 to encode String values to bytes to prevent platform-dependent encoding.
@mp911de mp911de added this to the 1.14.0 milestone Sep 11, 2019
@mp911de
Copy link
Owner

mp911de commented Sep 11, 2019

That's fixed now.

@mp911de mp911de closed this as completed Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants