JPro-one / JPro

The right place to report about bugs or suggest improvements for JPro.
https://www.jpro.one
9 stars 4 forks source link

java.lang.RuntimeException: WebSocket returned for non WebSocket request #110

Open ctoabidmaqbool opened 3 years ago

ctoabidmaqbool commented 3 years ago

Hi! I want to map jPro-one Server to run on different Url on Apache Server without needing of port writing on Url.

Let my jpro.one server is listening on http://localhost:8080 & my Apache server is listening on http://localhost. I want to map my jpro.one server to this virtual domain url http://mydomain.com.

I try ProxyPass on Apache configuration for this purpose, now my jpro.one can listen on http://mydomain.com but only loading bar is shown, not actual application is loading and error is shown:

[info] c.jpro - application requested: 0!hellojpro
[error] a.a.ActorSystemImpl - Internal server error, sending 500 response
java.lang.RuntimeException: WebSocket returned for non WebSocket request
        at scala.sys.package$.error(package.scala:30)or$$anonfun$receive$1$Pickler$macro$1$1$.unpickle(ViewSerializerActor.scala:36)
        at play.core.server.AkkaHttpServer.executeHandler(AkkaHttpServer.scala:383)macro$1$1$.unpickle(ViewSerializerActor.scala:36)
        at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:305)
        at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:174)erActor.scala:36)
        at akka.stream.impl.fusing.MapAsyncUnordered$$anon$31.onPush(Ops.scala:1376)
        at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:523)
        at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:480)ala:22)
        at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:376)
        at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:606)
        at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:485)

What should I do to solve the problem???

My Apache Server (XAMPP) virtual domain setup C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerName http://mydomain.com

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>

My Windows hosts file e.g. C:\Windows\System32\drivers\etc\hosts

127.0.0.1          localhost
127.0.0.1          mydomain.com
FlorianKirmaier commented 3 years ago

I assume accessing JPro over port 80 and localhost is working with this setup?

was "mydomain.com" just an example, or is your domain managed by "mydomain.com"?

The error message looks to me, that somewhere there is a service, which forwards the WebSocket request - but manipulates the header in some way, so it's no longer a valid WebSocket request.

I guess we will have to make an apache example configuration for our documentation.

ctoabidmaqbool commented 3 years ago

@FlorianKirmaier Thanks for reply!

Just to make sure, mydomain.com is my virtual domain setup on Apache webserver e.g. httpd-vhosts.conf and is mapped to localhost e.g. 127.0.0.1.

Actually on port 80 my Apache webserver is listening, And I want to listen jpro.one on this same port too. So I have managed apache ProxyPass for this task.

jPro.one is now listening on port 80 with my custom localhost domain setup e.g. mydomain.com (http://mydomain.com:80)

But the problem is that my jpro app not go forwards from loading bar.

Note in the exact same setup I can successfully run node.js app e.g. wiki.js

I have edit the question too.

FlorianKirmaier commented 3 years ago

@ctoabidmaqbool I did some research, and according to one of our customers, it doesn't work with ProxyPass. But I don't have any details why.

The issue probably relies on apache not correctly supporting WebSocket when using ProxyPass. Or it's just for some reason complex to set up.

I would recommend running JPro on a different port, and only make it accessible through apache. It's quite easy to set up and known to work.

you will have to enable various apache mods: sudo a2enmod proxy proxy_http rewrite ssl proxy_wstunnel

The configuration of the site might look like the following:

<VirtualHost *:80>
    ServerName localhost

    RewriteEngine On

    # websocket request    
    RewriteCond %{HTTP:Upgrade} =websocket [NC] 
    RewriteRule /(.*)           ws://localhost:8080/$1 [P,L]

    # kein websocket request
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule /(.*)           http://localhost:8080/$1 [P,L] 
</VirtualHost>

This was tested on ubuntu 18.04. Keep us updated, whether this information helps you!

We will create an improved version of this configuration for apache, which will support SSL. This will then be added to our documentation.

ctoabidmaqbool commented 3 years ago

@FlorianKirmaier Thanks a lot sir! Your solutions is working like a charm!

So my modified httpd-vhosts.conf file using your provided solutions is:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerName http://mydomain.com

    RewriteEngine On

    # websocket request    
    RewriteCond %{HTTP:Upgrade} =websocket [NC] 
    RewriteRule /(.*)           ws://localhost:8080/$1 [P,L]

    # kein websocket request
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule /(.*)           http://localhost:8080/$1 [P,L] 
</VirtualHost>
ctoabidmaqbool commented 3 years ago

Something like this is enough for my setup including SSL Secure connection e.g. HTTPS

httpd-vhosts.conf:

# localhost
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

# mydomain.com
<VirtualHost *:80>
    ServerAdmin admin@mydomain.com
    DocumentRoot "C:/xampp/htdocs/MyApp-jpro"
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    ErrorLog "logs/mydomain.com-error_log"
    CustomLog "logs/mydomain.com-access_log" common

    <Directory C:/xampp/htdocs/MyApp-jpro>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin admin@mydomain.com
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    ErrorLog "logs/mydomain.com-error_log"
    CustomLog "logs/mydomain.com-access_log" common

    # Example SSL configuration
    SSLEngine                on
    SSLCertificateFile       C:/xampp/apache/conf/ssl/mydomain.com/certificate.crt
    SSLCertificateKeyFile    C:/xampp/apache/conf/ssl/mydomain.com/private.key
    SSLCertificateChainFile  C:/xampp/apache/conf/ssl/mydomain.com/ca_bundle.crt

    RewriteEngine On

    # websocket request    
    RewriteCond %{HTTP:Upgrade} =websocket [NC] 
    RewriteRule /(.*)           ws://localhost:8080/$1 [P,L]

    # kein websocket request
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule /(.*)           http://localhost:8080/$1 [P,L]
</VirtualHost>

.htaccess:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

hosts:

127.0.0.1          localhost
127.0.0.1          mydomain.com