-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send user-agent information in SDK calls. Will track the version of the SDK for usage in the wild. Reference: http://stackoverflow.com/questions/3697449/retrieve-version-from-maven-pom-xml-in-code
- Loading branch information
Rohit Agarwal
committed
Mar 19, 2015
1 parent
833a9a1
commit 9a966a5
Showing
5 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/qubole/qds/sdk/java/client/UserAgentFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.qubole.qds.sdk.java.client; | ||
|
||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
public class UserAgentFilter implements ClientRequestFilter { | ||
|
||
public String version; | ||
|
||
public UserAgentFilter() throws IOException { | ||
try { | ||
Properties prop = new Properties(); | ||
String propFileName = "versionInfo.properties"; | ||
|
||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); | ||
|
||
if (inputStream != null) { | ||
prop.load(inputStream); | ||
} else { | ||
System.err.println("Version Info file '" + propFileName + "' not found in the classpath"); | ||
} | ||
|
||
version = prop.getProperty("version"); | ||
} catch (Exception e) { | ||
System.err.println("Some error while loading the version info for user-agent string."); | ||
} | ||
} | ||
|
||
@Override | ||
public void filter(ClientRequestContext clientRequestContext) throws IOException { | ||
try { | ||
clientRequestContext.getHeaders().add("User-Agent", "qds-sdk-java-" + version); | ||
} catch (Exception e) { | ||
// Silently pass. We don't want anything to fail because of this filter. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version=${project.version} |