ListBuckets method return nothing but in http log there are many? - aws-sdk-go

here is my go.mod:
module aws-s3-go-sdk-test
go 1.18
require github.com/aws/aws-sdk-go v1.44.33
require github.com/jmespath/go-jmespath v0.4.0 // indirect
here is my main code:
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
fun main(){
client := loadClient()
input := &s3.ListBucketsInput{}
output, err := client.ListBuckets(input)
if err != nil {
panic(err)
}
buckets := output.Buckets
println(len(buckets)) //this is 0
}
here is the log:
2022/06/14 12:39:58 DEBUG: Request s3/ListBuckets Details:
---[ REQUEST POST-SIGN ]-----------------------------
GET / HTTP/1.1
Host: xxooxxooxxooxxooxoo.com
User-Agent: aws-sdk-go/1.44.33 (go1.18.2; windows; amd64)
Authorization: AWS4-HMAC-SHA256 Credential=xxoxoxox
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20220614T043958Z
Accept-Encoding: gzip
-----------------------------------------------------
2022/06/14 12:40:00 DEBUG: Response s3/ListBuckets Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK--------------------------------------
Content-Length: 374895
Content-Type: application/xml
Date: Tue, 14 Jun 2022 04:40:00 GMT
Server: nginx
X-Amz-Request-Id: tx000000000000000438068-0062a81120-142bf304-region
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>oss-2022522151170001</Name>
<Prefix></Prefix>
<Marker></Marker>
<NextMarker>paas1451002243523284992</NextMarker>
<MaxKeys>1000</MaxKeys>
<IsTruncated>true</IsTruncated>
<Contents>
<Key>aos-storage-test/</Key>
<LastModified>2022-06-14T02:04:41.223Z</LastModified>
<ETag>"d41d8cd98f00b204e9800998ecf8427e"</ETag>
<Size>0</Size>
<StorageClass>STANDARD</StorageClass>
<Owner>
<ID>d4a96a2d-eca9-4aca-9925-37ddd839563c</ID>
<DisplayName>d4a96a2d-eca9-4aca-9925-37ddd839563c</DisplayName>
</Owner>
<Type>Normal</Type>
</Contents>
<Contents>
.....
</Contents>
</ListBucketResult>
And The XML response looks like the SOAP-API,is correct?
if so ,is there any go-sdk compatible with https over SOAP-API?
or how can i fix this? thanks guys
And The XML response looks like the SOAP-API,is correct?
if so ,is there any go-sdk compatible with https over SOAP-API?
or how can i fix this? thanks guys
And The XML response looks like the SOAP-API,is correct?
if so ,is there any go-sdk compatible with https over SOAP-API?
or how can i fix this? thanks guys

Related

Delphi: set Content-type of TCustomRestRequest on PUT

I'm fighting a REST API call from Delphi. I want to send a PUT request to a server, with contenttype set to application/json:
aCustomRestClient.BaseURL := domein;
aCustomRestRequest.Client := aCustomRestClient;
aCustomRestRequest.Response := aCustomRestResponse;
aCustomRestRequest.Method := rmPUT;
aCustomRestRequest.Resource := '/service/API/1501/allowanceCategory';
aCustomRestRequest.Params.AddHeader('sessionId', SessionToken);
qryAllowanceCategory.First;
o := TJSONObject.Create;
arr:=TJSONarray.create;
try
o.AddPair('createdBy',qryAllowanceCategory.fieldbyname('createdBy').AsString);
{lot more pairs here}
o.AddPair('percentage', TJSONnumber.create(qryAllowanceCategory.fieldbyname('percentage').AsFloat));
o.AddPair('remark', 'JUR '+ qryAllowanceCategory.fieldbyname('remark').AsString);
arr.add(o);
aCustomRestRequest.ClearBody;
aCustomRestResponse.contenttype:='application/json';
aCustomRestClient.contenttype:='application/json';
aCustomRestRequest.AddBody(arr.ToString);
aCustomRestRequest.Execute;
However, when I view my request as sent with Fiddler:
PUT http://shadow.jdvretail.com/service/API/1501/allowanceCategory HTTP/1.1
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/plain; q=0.9, text/html;q=0.8,
Accept-Charset: utf-8, *;q=0.8
Authorization: Basic <<Authorization properly filled>>
User-Agent: Embarcadero RESTClient/1.0
sessionId: <<sessionID GUID properly filled here>>
Content-Length: 542
The Content-type remains wrong... how/where do I correctly set the contentType to 'application/json'?
TRestClient.AddBody(<string>) has an optional second parameter allowing to set the content type.
procedure AddBody(const ABodyContent: string; AContentType: TRESTContentType = ctNone); overload;

Load performance testing with Gatling and Content-Type

I am using gatling for load performance testing on a brand new API. It seems fairly easy and well documented but I am facing an issue as simple as POST a request with Content-Type set to 'application/vnd.api+json' on the Header. All works well when doing the GET stuff but when launching a POST test I get a
HTTP response:
status=
415 Unsupported Media Type
headers=
cache-control: [no-cache]
Content-Type: [application/vnd.api+json; charset=utf-8]
Date: [Fri, 08 Sep 2017 12:57:10 GMT]
Server: [nginx]
Vary: [Origin]
x-content-type-options: [nosniff]
x-frame-options: [SAMEORIGIN]
X-Request-Id: [ff993645-8e01-4689-82a8-2f0920e4f2a9]
x-runtime: [0.040662]
x-xss-protection: [1; mode=block]
Content-Length: [218]
Connection: [keep-alive]
body=
{"errors":[{"title":"Unsupported media type","detail":"All requests that create or update must use the 'application/vnd.api+json' Content-Type. This request specified 'application/json'.","code":"415","status":"415"}]}
Here is the scala code I am using for the http request:
object PostTokenGcm {
val token = exec {
http("TestAPI POST /tokens")
.post("/tokens")
.headers(Map("Authorization" -> testApiToken,
"Content-Type" -> "application/vnd.api+json",
"Accept" -> "application/vnd.api+json" ))
.body(StringBody(gcmTokenRequestBody)).asJSON
.check(status.is(201))
.check(bodyString.exists)
}}
It seems that it is not setting the Content-Type?
Thank you for any lead!
In your POST definition you're using asJSON. According to notes in documentation about request headers:
http("foo").get("bar").asJSON is equivalent to:
http("foo").get("bar")
.header(HttpHeaderNames.ContentType, HttpHeaderValues.ApplicationJson)
.header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
... so, headers set in:
.headers(Map("Authorization" -> testApiToken,
"Content-Type" -> "application/vnd.api+json",
"Accept" -> "application/vnd.api+json" ))
... get overwritten by asJSON to "application/json" (which is the value of HttpHeaderValues.ApplicationJson).

Unexpected character in payload

My Citrus test sends a (travel)request to some REST API. The response is handled as follows:
http()
.client("http://localhost:18082/cases")
.send()
.post()
.accept("application/json; charset=UTF-8")
.contentType("application/json")
//.payload(new ClassPathResource("templates/travelrequest.json"));
.payload(
"{ "+
"\"definition\": \"travelrequest.xml\", "+
"\"name\": \"travelrequest\" "+
"} "
);
Although response code 500 is received, this is what I expect. In Wireshark I captured the following package:
Host: localhost:18082
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
Accept-Encoding: gzip,deflate
{ "definition": "travelrequest.xml", "name": "travelrequest" } HTTP/1.1 500 Internal Server Error
Server: spray-can/1.3.3
Date: Thu, 13 Apr 2017 15:33:37 GMT
When I move the payload to a template, the receive part of my test now looks like this:
http()
.client("http://localhost:18082/cases")
.send()
.post()
.accept("application/json; charset=UTF-8")
.contentType("application/json")
.payload(new ClassPathResource("templates/travelrequest.json"));
//.payload(
// "{ "+
// "\"definition\": \"travelrequest.xml\", "+
// "\"name\": \"travelrequest\" "+
// "} "
//);
The template resource contains this text:
{
"definition": "travelrequest.xml",
"name": "travelrequest"
}
When I run this test, I receive a different response code: 400. In Wireshark I captured the following package:
Host: localhost:18082
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
Accept-Encoding: gzip,deflate
?{
"definition": "travelrequest.xml",
"name": "travelrequest"
}HTTP/1.1 400 Bad Request
Server: spray-can/1.3.3
Date: Thu, 13 Apr 2017 15:36:15 GMT
Do notice that the request starts with an unexpected questionmark. This questionmark is not visible in the Citrus output:
17:36:13,629 DEBUG client.HttpClient| Sending HTTP message to: 'http://localhost:18082/cases'
17:36:13,629 DEBUG client.HttpClient| Message to send:
{
"definition": "travelrequest.xml",
"name": "travelrequest"
}
17:36:13,630 DEBUG ingClientInterceptor| Sending Http request message
Do notice the space directly before the opening bracket.
Is this some special character? Why is it added to the payload? Is there a logical explanation?
Cheers,
Ed
Seems to be an encoding issue. Citrus by default uses UTF-8 encoding when reading the file content. Maybe the file uses some other encoding and the first character is the result of this difference.
Please check the file encoding. You can tell Citrus to use some other encoding by setting the System property
citrus.file.encoding=UTF-8
You can also add this property to the citrus-application.properties file as described here: http://www.citrusframework.org/reference/html/configuration.html#citrus-application-properties

Jasper webservice: Invalid resource descriptor

I try to upload a simple image via REST webservice to the jasper server.
This is the HTTP request/response, I'm getting "400 Bad Request: Invalid resource descriptor".
I tried to copy a valid resource descriptor from the repository and re-upload it but it gives the same error!
(The dots represent \r\n and \t chars.)
T 10.84.6.166:36057 -> 10.84.6.166:8080 [AP].
PUT /jasperserver/rest/resource/reports/Customers/3221/image01.gif HTTP/1.1.
User-Agent: useragent.
Host: 10.84.6.166:8080.
Accept: */*.
Cookie: JSESSIONID=5D8D24835E61ED65ABD982964243C06B.
Content-Type: multipart/form-data; boundary="72e01e9922f8bb1669638258c2a2a155".
Content-Length: 23796.
Expect: 100-continue.
.
T 10.84.6.166:8080 -> 10.84.6.166:36057 [AP]
HTTP/1.1 100 Continue.
.
T 10.84.6.166:36057 -> 10.84.6.166:8080 [AP]
--72e01e9922f8bb1669638258c2a2a155.
Content-Disposition: form-data; name="ResourceDescriptor".
Content-Length: 811.
Content-Type: text/plain; charset=UTF-8.
Content-Transfer-Encoding: 8bit.
.
<resourceDescriptor name="s2" wsType="img" uriString="/reports/Customers/3221/s2.png" isNew="true">.
.<label><![CDATA[serverattacks_13-06-01.png]]></label>.
.<creationDate>1373470272965</creationDate>.
.<resourceProperty name="PROP_RESOURCE_TYPE">.
..<value><![CDATA[com.jaspersoft.jasperserver.api.metadata.common.domain.FileResource]]></value>.
.</resourceProperty>.
.<resourceProperty name="PROP_PARENT_FOLDER">.
..<value><![CDATA[/reports/Customers/3221]]></value>.
.</resourceProperty>.
.<resourceProperty name="PROP_VERSION">.
..<value><![CDATA[0]]></value>.
.</resourceProperty>.
.<resourceProperty name="PROP_HAS_DATA">.
..<value><![CDATA[true]]></value>.
.</resourceProperty>.
.<resourceProperty name="PROP_IS_REFERENCE">.
..<value><![CDATA[false]]></value>.
.</resourceProperty>.
</resourceDescriptor>.
--72e01e9922f8bb1669638258c2a2a155.
Content-Disposition: form-data; name="/reports/Customers/3221/s2.png".
Content-Length: 22544.
Content-Type: application/octet-stream.
Content-Transfer-Encoding: binary.
.
<long binary png contents>
--72e01e9922f8bb1669638258c2a2a155--.
T 10.84.6.166:8080 -> 10.84.6.166:36057 [AP]
HTTP/1.1 400 Bad Request.
Server: Apache-Coyote/1.1.
Pragma: No-cache.
Cache-Control: no-cache.
Expires: Thu, 01 Jan 1970 01:00:00 CET.
P3P: CP="ALL".
Content-Type: text/xml;charset=UTF-8.
Content-Length: 27.
Date: Thu, 11 Jul 2013 08:42:09 GMT.
Connection: close.
.
Invalid resource descriptor
Update:
I still don't know what's wrong but I finally got it working and released a Jasper PHP Library on github: http://blog.flowl.info/2013/jasper-php-library-on-github/
I tried to update jrxml on jasperServer. I found and buld java tests. I found working example of updating image on JasperServer.Mаy it is help уou.(With help of this example i wrote request for updating jrxml on jasperServer. And it is works!)
POST http://repsuite.cheby.ru:8080/jasperserver/rest/resource/SAMPLE_REST_FOLDER/JUNIT_IMAGE_FILE HTTP/1.1
Content-Length: 5560
Content-Type: multipart/form-data; boundary=dzFSpJmyJB0pL6bHxKgtqI4VmaKgL9pTWCrLeJv
Host: repsuite.cheby.ru:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Cookie: JSESSIONID=E485652B97C69549403D8CEEA0DC0855
Cookie2: $Version=1
--dzFSpJmyJB0pL6bHxKgtqI4VmaKgL9pTWCrLeJv
Content-Disposition: form-data; name="ResourceDescriptor"
<resourceDescriptor name="JUNIT_IMAGE_FILE" wsType="img" uriString="/SAMPLE_REST_FOLDER/JUNIT_IMAGE_FILE" isNew="true">
<label>jaspersoft logo</label>
<description>jaspersoft logo</description>
<creationDate>1308696383000</creationDate>
<resourceProperty name="PROP_RESOURCE_TYPE">
<value>com.jaspersoft.jasperserver.api.metadata.common.domain.FileResource</value>
</resourceProperty>
<resourceProperty name="PROP_PARENT_FOLDER">
<value>/SAMPLE_REST_FOLDER</value>
</resourceProperty>
<resourceProperty name="PROP_VERSION">
<value>0</value>
</resourceProperty>
<resourceProperty name="PROP_IS_REFERENCE">
<value>false</value>
</resourceProperty>
<resourceProperty name="PROP_HAS_DATA">
<value>true</value>
</resourceProperty>
</resourceDescriptor>
--dzFSpJmyJB0pL6bHxKgtqI4VmaKgL9pTWCrLeJv
Content-Disposition: form-data; name="/SAMPLE_REST_FOLDER/JUNIT_IMAGE_FILE"; filename="jasperSoftLogo_2.jpg"
Content-Type: application/octet-stream
----Binary content of image----

adding a response header to 302 response using perl

i am trying to write a perl page that returns an http 302 response to a different location and adds a custom header to that response.
so my desired http response should be something like this:
HTTP/1.1 302 Moved
Date: Sun, 15 Apr 2012 10:59:02 GMT
Server: Apache
Location: http://www.google.com
Content-Length: 396
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
CUSTOM_HEADER: CUSTOM_VALUE
i tried using CGI:
#!/bin/perl
use strict;
use APR::Request::Apache2;
my $r = shift;
$r->content_type('text/html; charset=utf-8');
$r->headers_out()->add("CUSTOM_HEADER", "CUSTOM_VALUE");
$r->headers_out()->add("Location", "http://www.google.com");
$r->status(302);
and i do get 302 response to google but no CUSTOM_HEADER. once i change the status to 200 by $r->status(200); i do get the CUSTOM_HEADER.
so whats up with this behavior ? how can i add my header to the 302 response ?
Use $r->err_headers_out->set or $r->err_headers_out->add
my $r = shift;
$r->content_type('text/html; charset=utf-8');
$r->err_headers_out->set(Location => "http://www.google.com");
$r->status(302);
You should use err_headers_out(). These will be printed even on errors and redirects.