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

Adds authorization basic to HTTP requests #150

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@
<artifactId>shrinkwrap-descriptors-impl-javaee</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>

</dependencies>

<reporting>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package biz.paluch.logging.gelf.intern.sender;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
import biz.paluch.logging.gelf.intern.GelfSender;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* HTTP-based Gelf sender. This sender uses Java's HTTP client to {@code POST} JSON Gelf messages to an endpoint.
*
Expand Down Expand Up @@ -51,6 +50,10 @@ public boolean sendMessage(GelfMessage message) {
try {

connection = (HttpURLConnection) url.openConnection();
if (url.getUserInfo() != null) {
String basicAuth = "Basic " + org.apache.commons.codec.binary.Base64.encodeBase64String(url.getUserInfo().getBytes());
connection.setRequestProperty("Authorization", basicAuth);
}
connection.setConnectTimeout(connectTimeoutMs);
connection.setReadTimeout(readTimeoutMs);
connection.setDoOutput(true);
Expand Down