ghedeon / awsinterceptor Goto Github PK
View Code? Open in Web Editor NEWAWS Gateway OkHttp Interceptor
AWS Gateway OkHttp Interceptor
I am downloading audio/wav file using AWS APIGateway with authorization but the file downloaded is corrupted and does not downloads more then 660B.
Once the request is signed using the interceptor -
Excepted:
https://www.aws.com/api
Current:
https://www.aws.com/api/
Solution:
private fun Request.sign(): Request {
val canonicalUrl = url.canonicalized()
val awsDummyRequest = DefaultRequest<Any>(serviceName).apply {
****endpoint = url.host
resourcePath = url.resource**** //separate out the host and resource
httpMethod = HttpMethodName.valueOf(method)
setQueryParams(canonicalUrl)
setBody(body)
}
signer.sign(awsDummyRequest, credentialsProvider.credentials)
return newBuilder()
.url(canonicalUrl)
.applyAwsHeaders(awsDummyRequest.headers)
.build()}
This is a runtime dependency, not only a debug one.
Also latest gradle needs "implementation" instead of "compile"
repositories {
maven {
url "https://dl.bintray.com/ghedeon/maven"
}
}
Works as well :)
if interceptor throw an exception that is not child of IOException app will crash
FIX: wrap AmazonClientException with IOException
https://github.com/xanscale/AwsInterceptor/commit/de62271956717d2b4dcf48a84267230ee0372845
More of a question but when I try to add the example gradle snippet to my build.gradle file it errors with:
Error:Could not find com.android.support:support-annotations:25.3.0.
Required by:
my-project:0.0.1
my-project:0.0.1 > com.ghedeon:aws-interceptor:0.3
Please install the Android Support Repository from the Android SDK Manager.
I don't use the Android SDK as I'm developing a Java application and I can't import this due to project constraints. Is there no way round this?
Just curious if I can use this library to do HTTP post requests to AWS IoT. How can we modify this to actually do MQTT publish over websockets using Dagger/Retrofit?
Occurs for POST method, GET methods are working fine though.
@POST("getfixtures") fun getFixtures(@Body fixturesRequestPOJO: FixturesRequestPOJO): Call<List<FixturePOJO>>
FATAL EXCEPTION: OkHttp Dispatcher Process: net.test.app, PID: 22550 com.amazonaws.AmazonClientException: Unable to reset stream after calculating AWS4 signature at com.amazonaws.auth.AWS4Signer.calculateContentHash(AWS4Signer.java:360) at com.amazonaws.auth.AWS4Signer.sign(AWS4Signer.java:113) at com.ghedeon.AwsInterceptor.sign(AwsInterceptor.java:72) at com.ghedeon.AwsInterceptor.intercept(AwsInterceptor.java:53) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: java.io.IOException: Mark has been invalidated. at java.io.BufferedInputStream.reset(BufferedInputStream.java:336) at com.amazonaws.auth.AWS4Signer.calculateContentHash(AWS4Signer.java:358) at com.amazonaws.auth.AWS4Signer.sign(AWS4Signer.java:113) at com.ghedeon.AwsInterceptor.sign(AwsInterceptor.java:72) at com.ghedeon.AwsInterceptor.intercept(AwsInterceptor.java:53) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
Please explain variables:
String authUrl = ""; //AUTH URL
String userName = ""; //USERNAME
String password = ""; //PASSWORD
What is authURI and which username and password we have to give in here.
Hi, coming from stackoverflow I gave a look at your implementation.
Your awsDummyRequest
in your interceptor assume only 1 call to the interceptor is performed at the same time. This is wrong assumption.
If multiple Http calls are perfomed in parallel they all work on the same instance of Request
(the awsDummyRequest
).
You should either create a new request every time or build a pool of reusable request, you create a new one if the others are busy and put the used one in the pool to reuse the objects.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.