BroadleafCommerce / ReactStarter

Broadleaf Commerce Spring Boot React Starter
Creative Commons Zero v1.0 Universal
43 stars 41 forks source link

An error occurred after site started :The valid characters are defined in RFC 7230 and RFC 3986 #4

Closed ninjya88 closed 6 years ago

ninjya88 commented 6 years ago

The following error occurred after the site was started ..>>> 2017-11-08 17:14:17.024 INFO 10648 --- [io-8082-exec-10] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:476) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) ..>>> I found a similar problem from stackoverflower,How should I solve the problem I have encountered.

ncrum commented 6 years ago

@ninjya88 First time I'm seeing this, but looks related to https://stackoverflow.com/questions/41053653/tomcat-8-is-not-able-to-handle-get-request-with-in-query-parameters. What are your reproduction steps that gave you this error? Was this on startup or after you tried to make a request?

ninjya88 commented 6 years ago

@ncrum

but looks related to https://stackoverflow.com/questions/41053653/tomcat-8-is-not-able-to-handle-get-request-with-in-query-parameters.

Yes,Is the error message given by tomcat,But I didn't make any requests. site is startuped, ApiApplication gives this error.

ncrum commented 6 years ago

@ninjya88 the app/server/util/i18nService.js does some eager fetching of translations on startup and caches them. That's probably the request that is hitting the api application and causing that error. The question is why that request would be an issue.

As a workaround you can comment out lines 60-71 of app/server/util/i18nService.js to avoid the eager fetching for now.

Also, are you running the ApiApplication using mvn spring-boot:run?

ninjya88 commented 6 years ago

I'm sorry that the information I gave at the beginning was quite hasty.

Also, are you running the ApiApplication using mvn spring-boot:run?

An Error parsing HTTP request header is a message that ApiApplication throws.

As a workaround you can comment out lines 60-71 of app/server/util/i18nService.js to avoid the eager fetching for now.

It doesn't work on my side.

The three projects, Api, admin, and site, are configured by [readme], and admin and Api are normal.I'm sorry that I can't launch site successfully until now. Also, [demostie] is not a problem to use, I can start it locally and access it.

My work environment: windows7,java1.8,node v8.9.0,pyhton2.7.13

ncrum commented 6 years ago

I just want to confirm some things. Are you saying that API and Admin are starting up fine, but site is not? So the issue here is that site is failing to startup?

If so, what errors are being thrown by the NodeJS app when you run yarn develop?

In addition, that workaround should prevent any requests from being sent out. I had pushed some other stuff out later last week so the lines may have changed. It's this specific code that is doing the requests:

// Initialize Locale data
LOCALES.forEach((locale) => {
    const language = locale.substring(0, locale.indexOf('-'))
    if (!getLocaleData(language)) {
        localeData[language] = fs.readFileSync(path.join(process.cwd(), `node_modules/react-intl/locale-data/${language}.js`)).toString();
    }

    if (!getMessages(language) && !eagerlyFetchedLanguages.includes(language)) {
        eagerlyFetchedLanguages.push(language)
        request.get(`${process.env.API_HOST}${process.env.API_CONTEXT_PATH}messages/${language}.json`).then(response => {
            messages[language] = response.body
        })
    }
});
ninjya88 commented 6 years ago

I reinstalled the ReactStarter.This is some of my steps, and I started the API and site, but still the previous error.

`D:\IdeaProjects\ReactStarter\site>yarn yarn install v1.2.1 [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.1.1: The platform "win32" is incompatible with this module. info "fsevents@1.1.1" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning "react-motion@0.5.1" has incorrect peer dependency "react@^0.14.9 || ^15.3.0". warning "redbox-react@1.4.1" has incorrect peer dependency "react@^0.14.0 || ^15.0.0". warning "redbox-react@1.4.1" has incorrect peer dependency "react-dom@^0.14.0 || ^15.0.0". [4/4] Building fresh packages... warning Your current version of Yarn is out of date. The latest version is "1.3.2" while you're on "1.2.1". info To upgrade, download the latest installer at "https://yarnpkg.com/latest.msi". Done in 194.53s.

D:\IdeaProjects\ReactStarter\site>yarn develop yarn run v1.2.1 $ node -r dotenv/config webpack-server.js dotenv_config_path=config/development.env

Starting dev server Listening at http://localhost:3000`

This exception comes from the API application.

`2017-11-14 10:13:30.873 INFO 2020 --- [nio-8082-exec-8] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:476) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)`

ncrum commented 6 years ago

So just to confirm, you are starting up both, but when you go to localhost:3000 nothing happens and you get that exception on the api application? Or does the site application also give an error when starting up?

I'm not able to recreate this behavior myself. It appears there is something issuing a request with a symbol that tomcat does not seem to agree with. Assuming you commenting out those lines I mentioned, this could only happen when you request a page from the application at localhost:3000. There is nothing else I can see that makes a request to the api application. You are probably going to have to do some debugging to figure out what's going on. Here is what I would do. Look at site/app/core/util/superagent.js and you can add this to the end of each of the request calls to log the error info request.get(url).catch(err => console.log(err) && err). Since all requests use this file, you will be able to figure out which request is failing due to the exception you posted. We can then figure out which endpoint is getting hit and which parameters are being passed and maybe figure out why it is having issues with it.

ninjya88 commented 6 years ago

@ncrum

So just to confirm, you are starting up both, but when you go to localhost:3000 nothing happens and you get that exception on the api application? Or does the site application also give an error when starting up?

Both applications started.It's just that API application throws an exception.

First of all,I debug the tomcat throws an exception of line (Http11InputBuffer. Java: 476), found in the byteBuffer with a backslash (92), the API application exceptions because of this. Then I went back to site and found the cause of the problem. Modify javascript languages version to ECMAScript 6.

Thank you very much for your help!!

But there is another problem. I can see the homepage of site, but the static resource is 404, which is the following

'Failed to load resource: the server responded with a status of 400 (Bad Request) material-kit-1.1.1.css link: (http://localhost:3000/api/theme/css/material-kit-extensions.css) Failed to load resource: the server responded with a status of 400 (Bad Request)shirt-special.jpg link: (http://localhost:3000/cmsstatic/img/banners/shirt-special.jpg) Failed to load resource: the server responded with a status of 400 (Bad Request) United-Kingdom.png link: (http://localhost:3000/img/flags/United-Kingdom.png)'

Is it just my own problem?

ncrum commented 6 years ago

@ninjya88 I'm glad the first issue was resolved! As far as the 400 bad requests go, I'm not able to recreate that. It looks like the response is Bad Request so there should be some sort of exception or stack trace around what's happening when it tries to load those resources. Do you see any errors in the api log?

kishore-alli commented 6 years ago

Hi, I am also facing same issue. I installed in two different machines and got the same errors.

Below are the logs from API:

2017-12-01 10:42:40.539 INFO 7204 --- [ main] com.mycompany.api.ApiApplication : Started ApiApplication in 73.755 seconds (JVM runn ing for 74.665) 2017-12-01 10:43:11.463 INFO 7204 --- [nio-8082-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherSe rvlet' 2017-12-01 10:43:11.464 INFO 7204 --- [nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initializati on started 2017-12-01 10:43:11.543 INFO 7204 --- [nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initializati on completed in 78 ms 2017-12-01 10:43:11.675 INFO 7204 --- [nio-8082-exec-7] o.b.common.cache.StatisticsServiceImpl : Cache hit percentage for SYSTEM_PROPERTY_MISSING_C ACHE_HIT_RATE is: 33.00% 2017-12-01 10:43:11.860 INFO 7204 --- [nio-8082-exec-3] o.h.cache.internal.StandardQueryCache : HHH000248: Starting query cache at region: query.O rder 2017-12-01 10:43:41.829 INFO 7204 --- [nio-8082-exec-9] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:476) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

2017-12-01 10:43:41.829 INFO 7204 --- [nio-8082-exec-5] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:476) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

Attached browser image related to the errors.

image

ncrum commented 6 years ago

@kishore-alli have you checked these requests that are failing in the "Network" tab to see if there are any invalid characters in the requests?

agujral1 commented 6 years ago

@ncrum Hi , I am facing same error .Perform below steps on site 1 yarn 2 yarn develop API server is running successfully and all rest endpoint working fine . But when we try to access API from site , Hit is not going to api server running on 8082 .

Please check below screenshot .

network error

@ninjya88

what exactly you did to To change java script version to ECMAscript 6. I have done below changes in webpack.config.js and set babel loader preset explicitly .But this did not resolve my problem.

test: /.js$/, include: path.resolve(__dirname, 'app'), exclude: /node_modules/, use: { loader: 'babel-loader', options: { plugins: ['transform-decorators-legacy' ], presets: ['es2015','react','stage-2']

ncrum commented 6 years ago

Should be fixed by the same solution as #6

kashidrishi commented 6 years ago

For quick fixed, Add below line in catalina.properties in side conf of tomcat

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

Thanks, RK