• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Strange behavior with Base64Decode  RSS feed

 
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple POST method that Base64Encodes a PDF then sends that POST to a springboot POST method.

What I'm finding is that sometimes, the request never makes it to the service's controller and just throws this error:


<!doctype html><html lang="en"><head><title>HTTP Status 406 ? Not Acceptable</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 406 ? Not Acceptable</h1>

Type Status Report

Description The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation.


<h3>Apache Tomcat/9.0.12</h3></body></html>


My CURL options are currently:

"-X POST " &
"--data data=" & $encodedText &
"--data --header \"Content-Type: text/plain\""

(The encodedText variable is Base64Encoded).

===

Other times, the Request data does make it to the service, but when I try to Base64Decode it, I get the same result as above.

With small files, it seems to work OK.

Baffling. Been looking at this now for hours. Very confused.

I created a setenv.sh in Tomcat's bin directory already to see if upping the memory would help.

CATALINA_OPTS="$CATALINA_OPTS -Xms1024m -Xmx4096m"

(no help)

Suggestions please....

Thanks,

-- mike
 
Saloon Keeper
Posts: 9707
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error indicates that the server can't return a response type that the client expects.

What response does the server send? You can set an Accept header for that response type in your request, and annotate the controller action with a RequestMapping that specify what type the action produces.
 
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike London wrote:
With small files, it seems to work OK.



That implies that the annotations and headers are (in general) OK, I would have thought.
At least for a normal (successful) run.

What is there in your logs?
Where does it get to in your code?

If there's an exception (for example) I would hope it would be logged.
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:

Mike London wrote:
With small files, it seems to work OK.



That implies that the annotations and headers are (in general) OK, I would have thought.
At least for a normal (successful) run.

What is there in your logs?
Where does it get to in your code?

If there's an exception (for example) I would hope it would be logged.



Thanks Dave for your reply,

Yes, the error is logged and it's kind of odd:

"Forwarding to error page from request [/method_name_here/] due to exception [GC overhead limit exceeded]
"java.lang.OutOfMemoryError: GC overhead limit exceeded"


It seems the request payload is too large for Tomcat.

I've tried adding a setenv.sh to the Tomcat bin folder with: "CATALINA_OPTS="$CATALINA_OPTS -Xms1024m -Xmx4096m"

Not sure what the GC overhead limit is all about since it's just a large request.

I also upped the maxHttpHeaderSize to "1048576" and even larger  values in the connector description:


Hope this additional information is helpful in figuring out what I need to do.

Add more memory to the server perhaps?

Thanks,

- mike
 
Dave Tolls
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right.
Changing the allowed header size wil have no effect, since the payload is coming in the body (looking at your curl).
This is also not Tomcat having an issue.
It's your app.

What was your app doing when it ran out of memory?
That should be there in the stack trace.
This is only a start point for tracking the issue down, though.

How big is the data you have sent?

Since raising the memory to 4Gig seems to have had no effect I suspect you have a leak in your code somewhere.
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Right.
Changing the allowed header size wil have no effect, since the payload is coming in the body (looking at your curl).
This is also not Tomcat having an issue.
It's your app.

What was your app doing when it ran out of memory?
That should be there in the stack trace.
This is only a start point for tracking the issue down, though.

How big is the data you have sent?

Since raising the memory to 4Gig seems to have had no effect I suspect you have a leak in your code somewhere.



This code runs fine with 16 GB RAM locally with no errors at all. There really isn't very much code. The request comes in, gets sent to Tika for text extraction and returns that text. My code isn't doing anything funky with Maps or whatever that would be typical culprits.

The PDFs that are Base64Encoded for POSTing to the REST service are huge. 150 MB is one of them.

But, again, all works locally with no errors.

I'm going to try to up my testing AWS to t2.xlarge which has 16 GB RAM to test and hope that doesn't give me a huge bill from Az.

Will post back.

Thanks,

- mike
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, even on AWS with t2.xlarge (16 GB RAM), I get the same GC Overhead limit exceeded.

Below is the error stack:

"java.lang.OutOfMemoryError: GC overhead limit exceeded
at org.apache.pdfbox.cos.COSNumber.get(COSNumber.java:115)
at org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:949)
at org.apache.pdfbox.pdfparser.BaseParser.parseCOSArray(BaseParser.java:632)
at org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:876)
at org.apache.pdfbox.pdfparser.BaseParser.parseCOSDictionaryValue(BaseParser.java:152)
at org.apache.pdfbox.pdfparser.BaseParser.parseCOSDictionaryNameValuePair(BaseParser.java:279)
at org.apache.pdfbox.pdfparser.BaseParser.parseCOSDictionary(BaseParser.java:212)
at org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:864)
at org.apache.pdfbox.pdfparser.PDFObjectStreamParser.parse(PDFObjectStreamParser.java:88)
at org.apache.pdfbox.pdfparser.COSParser.parseObjectStream(COSParser.java:993)
at org.apache.pdfbox.pdfparser.COSParser.parseObjectDynamically(COSParser.java:879)
at org.apache.pdfbox.pdfparser.COSParser.parseObjectDynamically(COSParser.java:793)
at org.apache.pdfbox.pdfparser.COSParser.parseDictObjects(COSParser.java:753)
at org.apache.pdfbox.pdfparser.PDFParser.initialParse(PDFParser.java:187)
at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:226)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1200)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1173)
at org.apache.tika.parser.pdf.PDFParser.parse(PDFParser.java:153)
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:280)
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:280)
at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:143)
at com.alias.ws.service.TextExtractionService.extractText(TextExtractionService.java:40)
at com.alias.ws.controllers.TextExtractionController.extractText(TextExtractionController.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)


Should I post this on the Tika forum?

Baffling that it works perfectly locally.

-- mike
 
Dave Tolls
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you duplicate this issue locally?
Say by reducing the memory assigned?

Are there different versions of anything at all between the AWS version and the local one?
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Can you duplicate this issue locally?
Say by reducing the memory assigned?

Are there different versions of anything at all between the AWS version and the local one?



Have not been able to reproduce locally on iMac with 16 GB RAM.

Production is an AWS (Windows Server 2008) with, for testing, also 16 GB RAM.

I've tried updating Java 8 to the latest and also using the latest Tika libs (1.20).

So confusing...

-- mike
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I instead set CATALINA_OPTS environment variable to this on AWS server:  

   -Xms2048m -Xmx2048m -XX:-UseGCOverheadLimit

(to disable the GC error), I get this stack:


java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:596)
at java.lang.StringBuilder.append(StringBuilder.java:190)
at org.springframework.util.StreamUtils.copyToString(StreamUtils.java:87)
at org.springframework.http.converter.StringHttpMessageConverter.readInternal(StringHttpMessageConverter.java:88)
at org.springframework.http.converter.StringHttpMessageConverter.readInternal(StringHttpMessageConverter.java:43)
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:198)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:207)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 
Dave Tolls
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how does that compare if you do the same locally?
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:And how does that compare if you do the same locally?



I just made sure I am using the same config for setenv.sh locally as setenv.bat:

CATALINA_OPTS="$CATALINA_OPTS -Xms1024m -Xmx4096m"

--

Could the problem be that I'm running Tomcat on Windows as a "service" instead of from the command line?  I guess I need to download Tomcat and run it that way as a test so I make absolutely sure I have the same environment.

How I run Tomcat is a real difference between the two environments.

Maybe the setenv.bat isn't getting picked up by the service version on AWS???

 
Dave Tolls
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I was wondering if 2048 would cause the same issue on your local one, with the heap running out.

As for setting the options on the service, I think you need to use one of the tomcat tools.
tomcat7w, or whatever version you have, I think (quick Google and yes).
That gives you a gui to set up the service the way you want.
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Well, I was wondering if 2048 would cause the same issue on your local one, with the heap running out.

As for setting the options on the service, I think you need to use one of the tomcat tools.
tomcat7w, or whatever version you have, I think (quick Google and yes).
That gives you a gui to set up the service the way you want.



Brilliant, Dave, thank you!!!

I had noticed those settings in tomcat9w.exe, but thought I needed to use the setenv.bat. But, since those settings wern't getting picked up, it had to be something obvious I was missing.

I really appreciate you hanging in there with me.

I hope the forum ops give you a JavaRanch "cow". You earned it!

Thanks again very much.

-- mike
tomcat-server-memory-config.jpg
[Thumbnail for tomcat-server-memory-config.jpg]
 
Dave Tolls
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem, and thanks for the cow!
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!