Java callout access request content as stream

I have a proxy deployed in Apigee Hybrid which uses a java callout to redirect the request over ICAP to a virus scanning service. The callout accesses the request payload as an InputStream and pipes it over a socket as an ICAP message. Everything works fine without streaming enabled on the proxy, but is obviously constrained by the 10MB payload size limit.

According to this answer, it should be possible to access the raw request stream with streaming enabled, but this one implies that it isn't, and in my testing the stream is empty when I try to access it via messageContext.getRequestMessage().getContentAsStream()

Intuitively it feels to me like there must be some way of accessing the raw request stream inside a Java callout if we aren't doing anything that would cause it to buffer, but I haven't been able to find it - could you give me any pointers as to what I should be doing?

Solved Solved
0 1 135
1 ACCEPTED SOLUTION

I don't think so.  I don't believe there is a way to get at the Stream when you have streaming enabled.  Apigee doesn't make it available to the proxy, so whether you are using builtin policies or Java callouts, the stream is not accessible to you.  This is by design.

Also I think you are over the line with respect to the 10mb payload limit. That's a stated limit of the platform. Going beyond it will lead to unhappiness. 

Maybe you can solve your problem in some other way, that does not involve sending >10mb data payloads through Apigee. I can imagine a custom microservice, gated by Apigee, that accepts the inbound payload and checks it. 

app -> Apigee : request to check payload for antivirus

Apigee-> app: ack, here's your signed URL

app->service that handles signedURL: here's my payload

service that handles signedURL  (thinks about it)

service that handles signedURL -> app: result of the scan

 

app -> Apigee : here's the result of the scan

...etc...

This is more complicated than just "sending it through Apigee", that's obvious. But there is the 10mb payload limit to contend with.There's no real escaping that. Wishing it away won't make it so. You will need the added complexity if you want to stay within the product limits. Sorry. 

View solution in original post

1 REPLY 1

I don't think so.  I don't believe there is a way to get at the Stream when you have streaming enabled.  Apigee doesn't make it available to the proxy, so whether you are using builtin policies or Java callouts, the stream is not accessible to you.  This is by design.

Also I think you are over the line with respect to the 10mb payload limit. That's a stated limit of the platform. Going beyond it will lead to unhappiness. 

Maybe you can solve your problem in some other way, that does not involve sending >10mb data payloads through Apigee. I can imagine a custom microservice, gated by Apigee, that accepts the inbound payload and checks it. 

app -> Apigee : request to check payload for antivirus

Apigee-> app: ack, here's your signed URL

app->service that handles signedURL: here's my payload

service that handles signedURL  (thinks about it)

service that handles signedURL -> app: result of the scan

 

app -> Apigee : here's the result of the scan

...etc...

This is more complicated than just "sending it through Apigee", that's obvious. But there is the 10mb payload limit to contend with.There's no real escaping that. Wishing it away won't make it so. You will need the added complexity if you want to stay within the product limits. Sorry.