Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit fdbf376

Browse files
Bootstrapping gax-httpjson (#355)
1 parent b6da833 commit fdbf376

27 files changed

Lines changed: 2126 additions & 0 deletions

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ subprojects {
116116
jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
117117
autovalue: 'com.google.auto.value:auto-value:1.2',
118118
threetenbp: 'org.threeten:threetenbp:1.3.3',
119+
httpClient: "com.google.http-client:google-http-client:1.22.0",
119120
auth: "com.google.auth:google-auth-library-oauth2-http:${authVersion}",
120121
authCredentials: "com.google.auth:google-auth-library-credentials:${authVersion}",
121122
commonProtos: "com.google.api.grpc:proto-google-common-protos:${commonProtosVersion}",

gax-httpjson/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
archivesBaseName = "gax-httpjson"
3+
4+
dependencies {
5+
compile project(':gax'),
6+
libraries.guava,
7+
libraries.jsr305,
8+
libraries.autovalue,
9+
libraries.threetenbp,
10+
libraries.httpClient,
11+
libraries.auth,
12+
libraries.authCredentials,
13+
libraries.apiCommon
14+
15+
testCompile project(':gax').sourceSets.test.output,
16+
libraries.junit,
17+
libraries.mockito,
18+
libraries.truth,
19+
libraries.commons
20+
21+
apt libraries.autovalue
22+
23+
shadowNoGuava libraries.guava
24+
}
25+
26+
task createProperties(dependsOn: processResources) {
27+
doLast {
28+
def propertiesDir = "$buildDir/resources/main/com/google/api/gax/httpjson/"
29+
new File(propertiesDir).mkdirs()
30+
Properties p = new Properties()
31+
p['version'] = project.version.toString()
32+
p.store(new PrintWriter(propertiesDir + "project.properties", "UTF-8"), null)
33+
}
34+
}
35+
36+
classes {
37+
dependsOn createProperties
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2017, Google Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google Inc. nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.httpjson;
31+
32+
import com.google.api.core.BetaApi;
33+
34+
@BetaApi
35+
public class ApiMessage {
36+
// TODO implement
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2017, Google Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google Inc. nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.httpjson;
31+
32+
import com.google.api.core.BetaApi;
33+
34+
@BetaApi
35+
public class ApiMethodDescriptor<RequestT, ResponseT> {
36+
// TODO implement
37+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2017, Google Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google Inc. nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.httpjson;
31+
32+
import com.google.api.gax.retrying.ResultRetryAlgorithm;
33+
import com.google.api.gax.retrying.TimedAttemptSettings;
34+
import org.threeten.bp.Duration;
35+
36+
/* Package-private for internal use. */
37+
class ApiResultRetryAlgorithm<ResponseT> implements ResultRetryAlgorithm<ResponseT> {
38+
// Duration to sleep on if the error is DEADLINE_EXCEEDED.
39+
public static final Duration DEADLINE_SLEEP_DURATION = Duration.ofMillis(1);
40+
41+
@Override
42+
public TimedAttemptSettings createNextAttempt(
43+
Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) {
44+
// TODO figure out the right http code
45+
// if (prevThrowable != null
46+
// && ((HttpJsonApiException) prevThrowable).getStatusCode().getCode() == Code.DEADLINE_EXCEEDED) {
47+
// return new TimedAttemptSettings(
48+
// prevSettings.getGlobalSettings(),
49+
// prevSettings.getRetryDelay(),
50+
// prevSettings.getRpcTimeout(),
51+
// DEADLINE_SLEEP_DURATION,
52+
// prevSettings.getAttemptCount() + 1,
53+
// prevSettings.getFirstAttemptStartTimeNanos());
54+
// }
55+
return null;
56+
}
57+
58+
@Override
59+
public boolean shouldRetry(Throwable prevThrowable, ResponseT prevResponse) {
60+
return (prevThrowable instanceof HttpJsonApiException)
61+
&& ((HttpJsonApiException) prevThrowable).isRetryable();
62+
}
63+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2017, Google Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google Inc. nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.httpjson;
31+
32+
import com.google.api.core.BetaApi;
33+
import java.util.concurrent.Executor;
34+
35+
/**
36+
* FixedHttpJsonChannelProvider is an HttpJsonChannelProvider which always provides the same
37+
* channel.
38+
*/
39+
@BetaApi
40+
public final class FixedHttpJsonChannelProvider implements HttpJsonChannelProvider {
41+
private final ManagedHttpJsonChannel channel;
42+
43+
private FixedHttpJsonChannelProvider(ManagedHttpJsonChannel channel) {
44+
this.channel = channel;
45+
}
46+
47+
@Override
48+
public boolean shouldAutoClose() {
49+
return false;
50+
}
51+
52+
@Override
53+
public boolean needsExecutor() {
54+
return false;
55+
}
56+
57+
@Override
58+
public ManagedHttpJsonChannel getChannel() {
59+
return channel;
60+
}
61+
62+
@Override
63+
public ManagedHttpJsonChannel getChannel(Executor executor) {
64+
throw new IllegalStateException("getChannel(Executor) called when needsExecutor() is false.");
65+
}
66+
67+
/** Creates a FixedHttpJsonChannelProvider. */
68+
public static FixedHttpJsonChannelProvider create(ManagedHttpJsonChannel channel) {
69+
return new FixedHttpJsonChannelProvider(channel);
70+
}
71+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2017, Google Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google Inc. nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.httpjson;
31+
32+
import com.google.api.core.BetaApi;
33+
import com.google.api.gax.rpc.ApiException;
34+
35+
/**
36+
* Represents an exception thrown during an RPC call.
37+
*
38+
* <p>For more information about the status codes returned by the underlying grpc exception see
39+
* https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/Status.java
40+
*/
41+
@BetaApi
42+
public class HttpJsonApiException extends ApiException {
43+
private static final long serialVersionUID = -725668425459379694L;
44+
45+
@BetaApi
46+
public HttpJsonApiException(Throwable cause, int statusCode, boolean retryable) {
47+
super(cause, HttpJsonStatusCode.of(statusCode), retryable);
48+
}
49+
50+
@BetaApi
51+
public HttpJsonApiException(String message, Throwable cause, int statusCode, boolean retryable) {
52+
super(message, cause, HttpJsonStatusCode.of(statusCode), retryable);
53+
}
54+
55+
/**
56+
* Returns the status code of the underlying grpc exception. In cases where the underlying
57+
* exception is not of type StatusException or StatusRuntimeException, the status code will be
58+
* Status.Code.UNKNOWN. For more information about status codes see
59+
* https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/Status.java
60+
*/
61+
public HttpJsonStatusCode getStatusCode() {
62+
return (HttpJsonStatusCode) super.getStatusCode();
63+
}
64+
}

0 commit comments

Comments
 (0)