How to receive an HTML attachment in WSO2 ESB - wso2

I have a need to call a jasperreports server from WSO2 ESB to generate a PDF. The REST API of Jasperserver sends this back as an attachment in a HTTP response.
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Cache-Control: private
Expires: Thu, 01 Jan 1970 01:00:00 CET
P3P: CP="ALL"
Content-Disposition: attachment; filename="Report.pdf"
output-final: true
Content-Type: application/pdf
Content-Length: 12060
Date: Tue, 22 Sep 2015 15:22:50 GMT
%PDF-1.4
WSO2 ESB cannot parse this - how can I make this work, so I can process the generated PDF?
ESB Error:
TID: [0] [ESB] [2015-09-22 17:13:16,326] ERROR {org.apache.synapse.transport.passthru.util.RelayUtils}
- Error while building Passthrough stream {org.apache.synapse.transport.passthru.util.RelayUtils}
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.

Did you try to configure the binary relay ?
Maybe the following link can help you: docs.wso2.com/display/ESB481/Configuring+Message+Relay

Related

Go AWS SDK "Unable to determine service/operation name to be authorized"

I am using the Go SDK to connect to the Kinesis Video Streams service. When issuing a GetMedia request, I'm receiving a 403 response with the following body:
<AccessDeniedException>
<Message>Unable to determine service/operation name to be authorized</Message>
</AccessDeniedException>
I am using LogLevel LogDebugWithHTTPBody to see this since the SDK is expecting JSON and receives XML, causing a SerializationError.
I am using Go 1.9.2 and have attempted this operation with both v1 and v2 of aws-sdk-go with the same result.
Here is my request:
POST /getMedia HTTP/1.1
Host: kinesisvideo.us-west-2.amazonaws.com
User-Agent: aws-sdk-go/2.0.0-preview.1 (go1.9.2; darwin; amd64)
Content-Length: 141
Authorization: AWS4-HMAC-SHA256 Credential=AKIAXXXXXXXXXXXXXX/20180112/us-west-2/kinesisvideo/aws4_request, SignedHeaders=content-length;host;x-amz-date, Signature=60c625357b67c64caed32f5a0924882f26ffc776211801e94e7ecae84e7213c2
X-Amz-Date: 20180112T012511Z
Accept-Encoding: gzip
{"StartSelector":{"StartSelectorType":"NOW"},"StreamARN":"arn:aws:kinesisvideo:us-west-2:XXXXXXXXXXXXX:stream/StreamTest/XXXXXXXXXXXXX"}
Response:
HTTP/1.1 403 Forbidden
Content-Length: 130
Date: Fri, 12 Jan 2018 01:25:11 GMT
X-Amzn-Requestid: 6f1701aa-f737-11e7-bcd5-c70a68e72add
<AccessDeniedException>
<Message>Unable to determine service/operation name to be authorized</Message>
</AccessDeniedException>
Any help would be greatly appreciated.
To follow up, I have tried to issue the HTTP request above directly with the Content-Type: application/json header added, and the response is now:
{
"Output": {
"__type": "com.amazon.coral.service#UnknownOperationException",
"message": null
},
"Version": "1.0"
}
I have found the solution. From the docs,
"You must first call the GetDataEndpoint API to get an endpoint to which you can then send the GetMedia requests."

EI and APIm: Response payload is wrapped inside binary element

1.1 - API Manager 2.1.0
If I sent a POST request through a simple mediation (pass through) when the binary relay was enabled, the response payload generated by ESB has been wrapped inside a binary element as follows..
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction
Content-Type: text/xml; charset=UTF-8
Date: Tue, 16 Jan 2018 14:53:00 GMT
Transfer-Encoding: chunked
Connection: close
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">DCAAAAApACkAAAJxdXVpZDo3MTRDNkM0MC00NT.......</ns:binary></soapenv:Body></soapenv:Envelope>
In ESB 5.0.0 and API manager 2.0.0 all works well.

Why don't I get a HTTP status code from Firebase Server? Swift - Vapor server

I am writing to Firebase Database from a Vapor server using the Firebase REST API. Why don't I get a Status code in the header received? This would enable me to check if the write was successful or not.
headerReceived items line 83 in
extensionPutRequestToUsersClaimBookingCleaner are
([Connection: "keep-alive", Cache-Control: "no-cache", Server:
"nginx", Date: "Sun, 27 Aug 2017 21:47:25 GMT", Content-Type:
"application/json; charset=utf-8", Content-Length: "1027",
Strict-Transport-Security: "max-age=31556926; includeSubDomains;
preload", Access-Control-Allow-Origin: "*"])
The response's status code is returned in the status property rather than the headers property.
guard response.status == .created else {
// not a 201 response
}

AWS API Gateway return HTML

I am using the AWS labs' serverless container (https://github.com/awslabs/aws-serverless-java-container) to handle the lambda entrypoint and response for a lambda that returns HTML. It appears that it calls the lambda and returns the HTML just fine from the lambda. However, API Gateway then throws a fit processing the response. I am using the API Gateway as a proxy, not configuring individual endpoints.
Wed Jun 21 20:53:29 UTC 2017 : Endpoint response body before transformations: ---
statusCode: 200
headers:
Content-Type: "text/html"
body: "\r\n\r\nhttp://www.w3.org/1999/xhtml\"\r\n \
\ lang=\"en\">\r\n \r\n \r\n \
\ Page Title\r\n \r\n \r\n \
\ \r\n \r\n\
\ \r\n \r\n ... [TRUNCATED]
Wed Jun 21 20:53:29 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=adb2b101-56c3-11e7-afc6-8383d836980f, Connection=keep-alive, Content-Length=17551, Date=Wed, 21 Jun 2017 20:53:29 GMT, X-Amzn-Trace-Id=root=1-594adcc9-6987c6ed102696c505538b02;sampled=0, Content-Type=application/octet-stream}
Wed Jun 21 20:53:29 UTC 2017 : Execution failed due to configuration error: Malformed Lambda proxy response
Wed Jun 21 20:53:29 UTC 2017 : Method completed with status: 502
As you can see from the logs, the AWS own Java object, AwsProxyResponse, properly wraps the HTML content how AWS coded it. You see it returning the proper body and text/html headers. It seems API Gateway then blows up handling a response from AWS's own response.
How do I get AWS Gateway to properly handle the response when the response form the lambda is Content-Type: test/html?
The response from the Lambda function does not look correct. It appears a raw string without any format.
It should be JSON in the format:
{
"statusCode": num,
"headers" : {
"key" : "value"
},
"body" : "anything"
}

401 When trying to create an orgunit using Google API

I'm trying to use Google's Admin SDK to create an orgunit using a shell script. My script is as follows:
# Obtain a token we can use to modify the organisation
auth_header=`oauth2l header --json "..." "admin.directory.orgunit"`
customer_id=...
curl -v -H "Content-Type: application/json" -X POST \
--data-binary "#google-orgunits/technical.json" \
--header "$auth_header" \
"https://www.googleapis.com/admin/directory/v1/customer/$customer_id/orgunits"
This produces the output:
* Trying 216.58.196.138...
* Connected to www.googleapis.com (216.58.196.138) port 443 (#0)
* found 173 certificates in /etc/ssl/certs/ca-certificates.crt
* found 704 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
* server certificate verification OK
* server certificate status verification SKIPPED
* common name: *.googleapis.com (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: C=US,ST=California,L=Mountain View,O=Google Inc,CN=*.googleapis.com
* start date: Wed, 05 Apr 2017 17:01:30 GMT
* expire date: Wed, 28 Jun 2017 16:56:00 GMT
* issuer: C=US,O=Google Inc,CN=Google Internet Authority G2
* compression: NULL
* ALPN, server accepted to use http/1.1
> POST /admin/directory/v1/customer/.../orgunits HTTP/1.1
> Host: www.googleapis.com
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Type: application/json
> Authorization: Bearer ...
> Content-Length: 157
>
* upload completely sent off: 157 out of 157 bytes
< HTTP/1.1 401 Unauthorized
< Vary: X-Origin
< WWW-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token
< Content-Type: application/json; charset=UTF-8
< Date: Sat, 15 Apr 2017 06:26:27 GMT
< Expires: Sat, 15 Apr 2017 06:26:27 GMT
< Cache-Control: private, max-age=0
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Alt-Svc: quic=":443"; ma=2592000; v="37,36,35"
< Accept-Ranges: none
< Vary: Origin,Accept-Encoding
< Transfer-Encoding: chunked
<
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
There must be some problem here: I appear to be obtaining a valid token, (looks like ya29.ElouBGKFig-nXZ9uykyGoDr0hxAxG5PMJTUh3VmtAtj2SAdYEbH2Coumjp5XoaF232oVx3--2EpTyNi5NgFBNrLINJij9tGL3-64MshEXjHhvkH-1NESoxPeVAU). I've followed all of the instructions here, enabled API access, authorized my API client, everything; but still, not working. Where have I gone wrong?
Try checking the documentation about Directory API: Authorize Requests
Every request your application sends to the Directory API must include an authorization token. The token also identifies your application to Google.
Here's the OAuth 2.0 scope information for the Directory API:
https://www.googleapis.com/auth/admin.directory.orgunit - Global scope for access to all organization unit operations.
https://www.googleapis.com/auth/admin.directory.orgunit.readonly -
Scope for only retrieving organization units.
You can check the OAuth 2.0 Playground, an interactive demonstration of using OAuth 2.0 with Google (including the option to use your own client credentials). Also there are many quickstart that can help you on how to properly authorize a request for Admin SDK.
Hope this helps.