Skip to content

Commit 28c3ce0

Browse files
authored
Set user agent (#29)
1 parent 46828f9 commit 28c3ce0

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

labkey-api-sas/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ artifactory_contextUrl=https://artifactory.labkey.com/artifactory
55

66
artifactoryPluginVersion=4.21.0
77
gradlePluginsVersion=1.32.2
8-
labkeyClientApiVersion=1.4.0
8+
labkeyClientApiVersion=1.5.2

labkey-client-api/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# The LabKey Remote API Library for Java - Change Log
22

3+
## version 1.5.2
4+
*Released*: 14 July 2022
5+
* Add Connection.setUserAgent() and Connection.getUserAgent()
6+
* Set Java library user agent to "LabKey Java API"
7+
* Set SAS library user agent to "LabKey SAS API"
8+
39
## version 1.5.1
410
*Released*: 7 July 2022
511
* Fix NPE when saving assay protocol with transform scripts

labkey-client-api/src/org/labkey/remoteapi/Connection.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public class Connection
120120
// The user email when impersonating a user
121121
private String _impersonateUser;
122122
private String _impersonatePath;
123+
private String _userAgent = "LabKey Java API";
123124

124125
/**
125126
* Constructs a new Connection object given a base URL and a credentials provider.
@@ -262,6 +263,9 @@ protected HttpClientBuilder clientBuilder()
262263
}
263264
}
264265

266+
if (null != _userAgent)
267+
builder.setUserAgent(_userAgent);
268+
265269
return builder;
266270
}
267271

@@ -491,6 +495,16 @@ public Connection setAcceptSelfSignedCerts(boolean acceptSelfSignedCerts)
491495
return this;
492496
}
493497

498+
public String getUserAgent()
499+
{
500+
return _userAgent;
501+
}
502+
503+
public void setUserAgent(String userAgent)
504+
{
505+
_userAgent = userAgent;
506+
}
507+
494508
/**
495509
* @param name The cookie name
496510
* @param value The cookie value

labkey-client-api/src/org/labkey/remoteapi/sas/SASConnection.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.labkey.remoteapi.ApiKeyCredentialsProvider;
1919
import org.labkey.remoteapi.BasicAuthCredentialsProvider;
2020
import org.labkey.remoteapi.Connection;
21+
import org.labkey.remoteapi.CredentialsProvider;
2122
import org.labkey.remoteapi.NetrcCredentialsProvider;
2223

2324
import java.io.IOException;
@@ -31,24 +32,30 @@
3132
*/
3233
public class SASConnection extends Connection
3334
{
35+
private SASConnection(String baseUrl, CredentialsProvider credentialsProvider)
36+
{
37+
super(baseUrl, credentialsProvider);
38+
setUserAgent("LabKey SAS API");
39+
}
40+
3441
@SuppressWarnings({"UnusedDeclaration"})
3542
// Called from SAS macros via reflective JavaObj interface
36-
public SASConnection(String baseUrl, String userName, String password) throws IOException, URISyntaxException
43+
public SASConnection(String baseUrl, String userName, String password)
3744
{
38-
super(baseUrl, new BasicAuthCredentialsProvider(userName, password));
45+
this(baseUrl, new BasicAuthCredentialsProvider(userName, password));
3946
}
4047

4148
@SuppressWarnings({"UnusedDeclaration"})
4249
// Called from SAS macros via reflective JavaObj interface
4350
public SASConnection(String baseUrl) throws IOException, URISyntaxException
4451
{
45-
super(baseUrl, new NetrcCredentialsProvider(new URI(baseUrl)));
52+
this(baseUrl, new NetrcCredentialsProvider(new URI(baseUrl)));
4653
}
4754

4855
@SuppressWarnings({"UnusedDeclaration"})
4956
// Called from SAS macros via reflective JavaObj interface
50-
public SASConnection(String baseUrl, String apiKey) throws IOException, URISyntaxException
57+
public SASConnection(String baseUrl, String apiKey)
5158
{
52-
super(baseUrl, new ApiKeyCredentialsProvider(apiKey));
59+
this(baseUrl, new ApiKeyCredentialsProvider(apiKey));
5360
}
5461
}

0 commit comments

Comments
 (0)