Skip to content

Commit adb86ab

Browse files
committed
fix(core/protocols): x-amz-target in rpc protocols
1 parent ad00b16 commit adb86ab

File tree

8 files changed

+47
-14
lines changed

8 files changed

+47
-14
lines changed

clients/client-cloudwatch-logs/src/runtimeConfig.shared.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export const getRuntimeConfig = (config: CloudWatchLogsClientConfig) => {
3131
},
3232
],
3333
logger: config?.logger ?? new NoOpLogger(),
34-
protocol: config?.protocol ?? new AwsJson1_1Protocol({ defaultNamespace: "com.amazonaws.cloudwatchlogs" }),
34+
protocol:
35+
config?.protocol ??
36+
new AwsJson1_1Protocol({ defaultNamespace: "com.amazonaws.cloudwatchlogs", serviceTarget: "Logs_20140328" }),
3537
serviceId: config?.serviceId ?? "CloudWatch Logs",
3638
urlParser: config?.urlParser ?? parseUrl,
3739
utf8Decoder: config?.utf8Decoder ?? fromUtf8,

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddProtocolConfig.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
7070
return Collections.emptyMap();
7171
}
7272
String namespace = settings.getService().getNamespace();
73+
String rpcTarget = settings.getService().getName();
7374
String xmlns = settings.getService(model)
7475
.getTrait(XmlNamespaceTrait.class)
7576
.map(XmlNamespaceTrait::getUri)
@@ -145,7 +146,11 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
145146
writer.addImportSubmodule(
146147
"AwsJson1_0Protocol", null,
147148
AwsDependency.AWS_SDK_CORE, "/protocols");
148-
writer.write("new AwsJson1_0Protocol({ defaultNamespace: $S })", namespace);
149+
writer.write(
150+
"new AwsJson1_0Protocol({ defaultNamespace: $S, serviceTarget: $S })",
151+
namespace,
152+
rpcTarget
153+
);
149154
}
150155
);
151156
} else if (Objects.equals(settings.getProtocol(), AwsJson1_1Trait.ID)) {
@@ -154,7 +159,11 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
154159
writer.addImportSubmodule(
155160
"AwsJson1_1Protocol", null,
156161
AwsDependency.AWS_SDK_CORE, "/protocols");
157-
writer.write("new AwsJson1_1Protocol({ defaultNamespace: $S })", namespace);
162+
writer.write(
163+
"new AwsJson1_1Protocol({ defaultNamespace: $S, serviceTarget: $S })",
164+
namespace,
165+
rpcTarget
166+
);
158167
}
159168
);
160169
}

packages/core/src/submodules/protocols/json/AwsJson1_0Protocol.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
55
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
66
*/
77
export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
8-
public constructor({ defaultNamespace }: { defaultNamespace: string }) {
8+
public constructor({ defaultNamespace, serviceTarget }: { defaultNamespace: string; serviceTarget: string }) {
99
super({
1010
defaultNamespace,
11+
serviceTarget,
1112
});
1213
}
1314

@@ -18,4 +19,8 @@ export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
1819
protected getJsonRpcVersion() {
1920
return "1.0" as const;
2021
}
22+
23+
protected getDefaultContentType(): string {
24+
return "application/x-amz-json-1.1";
25+
}
2126
}

packages/core/src/submodules/protocols/json/AwsJson1_1Protocol.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
55
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
66
*/
77
export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
8-
public constructor({ defaultNamespace }: { defaultNamespace: string }) {
8+
public constructor({ defaultNamespace, serviceTarget }: { defaultNamespace: string; serviceTarget: string }) {
99
super({
1010
defaultNamespace,
11+
serviceTarget,
1112
});
1213
}
1314

@@ -18,4 +19,8 @@ export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
1819
protected getJsonRpcVersion() {
1920
return "1.1" as const;
2021
}
22+
23+
protected getDefaultContentType(): string {
24+
return "application/x-amz-json-1.1";
25+
}
2126
}

packages/core/src/submodules/protocols/json/AwsJsonRpcProtocol.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import { loadRestJsonErrorCode } from "./parseJsonBody";
2222
export abstract class AwsJsonRpcProtocol extends RpcProtocol {
2323
protected serializer: ShapeSerializer<string | Uint8Array>;
2424
protected deserializer: ShapeDeserializer<string | Uint8Array>;
25+
protected serviceTarget: string;
2526
private codec: JsonCodec;
2627

27-
protected constructor({ defaultNamespace }: { defaultNamespace: string }) {
28+
protected constructor({ defaultNamespace, serviceTarget }: { defaultNamespace: string; serviceTarget: string }) {
2829
super({
2930
defaultNamespace,
3031
});
32+
this.serviceTarget = serviceTarget;
3133
this.codec = new JsonCodec({
3234
timestampFormat: {
3335
useTrait: true,
@@ -50,9 +52,7 @@ export abstract class AwsJsonRpcProtocol extends RpcProtocol {
5052
}
5153
Object.assign(request.headers, {
5254
"content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
53-
"x-amz-target":
54-
(this.getJsonRpcVersion() === "1.0" ? `JsonRpc10.` : `JsonProtocol.`) +
55-
NormalizedSchema.of(operationSchema).getName(),
55+
"x-amz-target": `${this.serviceTarget}.${NormalizedSchema.of(operationSchema).getName()}`,
5656
});
5757
if (deref(operationSchema.input) === "unit" || !request.body) {
5858
request.body = "{}";

packages/core/src/submodules/protocols/json/AwsRestJsonProtocol.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
8181
} else if (httpPayloadMember.isBlobSchema()) {
8282
request.headers["content-type"] = "application/octet-stream";
8383
} else {
84-
request.headers["content-type"] = "application/json";
84+
request.headers["content-type"] = this.getDefaultContentType();
8585
}
8686
} else if (!inputSchema.isUnitSchema()) {
8787
const hasBody = Object.values(members).find((m) => {
8888
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
8989
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
9090
});
9191
if (hasBody) {
92-
request.headers["content-type"] = "application/json";
92+
request.headers["content-type"] = this.getDefaultContentType();
9393
}
9494
}
9595
}
@@ -157,4 +157,8 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
157157

158158
throw exception;
159159
}
160+
161+
protected getDefaultContentType(): string {
162+
return "application/json";
163+
}
160164
}

packages/core/src/submodules/protocols/query/AwsQueryProtocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,8 @@ export class AwsQueryProtocol extends RpcProtocol {
212212
const errorData = this.loadQueryError(data);
213213
return errorData?.message ?? errorData?.Message ?? data.message ?? data.Message ?? "Unknown";
214214
}
215+
216+
protected getDefaultContentType(): string {
217+
return "application/x-www-form-urlencoded";
218+
}
215219
}

packages/core/src/submodules/protocols/xml/AwsRestXmlProtocol.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,20 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
8585
} else if (httpPayloadMember.isBlobSchema()) {
8686
request.headers["content-type"] = "application/octet-stream";
8787
} else {
88-
request.headers["content-type"] = "application/xml";
88+
request.headers["content-type"] = this.getDefaultContentType();
8989
}
9090
} else if (!ns.isUnitSchema()) {
9191
const hasBody = Object.values(members).find((m) => {
9292
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
9393
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
9494
});
9595
if (hasBody) {
96-
request.headers["content-type"] = "application/xml";
96+
request.headers["content-type"] = this.getDefaultContentType();
9797
}
9898
}
9999
}
100100

101-
if (request.headers["content-type"] === "application/xml") {
101+
if (request.headers["content-type"] === this.getDefaultContentType()) {
102102
if (typeof request.body === "string") {
103103
request.body = '<?xml version="1.0" encoding="UTF-8"?>' + request.body;
104104
}
@@ -172,4 +172,8 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
172172

173173
throw exception;
174174
}
175+
176+
protected getDefaultContentType(): string {
177+
return "application/xml";
178+
}
175179
}

0 commit comments

Comments
 (0)