Heroku Java Websocket Endpoint - java

I am trying to build a chat application.
+Server : I use java websocket to create an endpoint. Here is my endpoint:
#ServerEndpoint("/server")
public class ChatServer {
//My code is ok ! Tested in localhost
}
+Client : I use java swing to create GUI. In my localhost, I use this URL :
ws://localhost:8080/ChatServer-1.0/server
to connect to Server Endpoint and my app run successful.
-> I have deployed my server endpoint to Heroku
My Heroku Server Endpoint
How can my client to connect to server endpoint ?
I have tried to use:
wss://jp-chatting-server.herokuapp.com/server
But it gives a 404 code.

I think you have used instruction for webapp-runner. I'm afraid this solution will not work for websockets. It is because support of websocket is not implemented yeat. Issue with websocket in webapp-runner. I see one of the options in using Tomcat 7 and it's custom implementation. Like in this example.

Related

How to send request to backend SSL url that converts from HTTP:7000 to HTTPS:7001 after verification running on weblogic using Angular front end app

I have a backend application that is running on weblogic server. It is running on http://localhost:7000. This application has to be called with http://localhost:7000 then after verification it checks if the application schema is on https or not. If its not then it asks you to redirect to https://localhost:7001. The HTTPS configuration is enabled on weblogic server
WEBLOGIC SSL CONFIGURATION
So far everything running on same domain meaning the application is full fledge with java backend and angular js embedded frontend. So everything running on weblogic server.
Now we are in the process of migrating from angular js to angular. Now angular is running on http://localhost:4200. So I have created a proxy for HTTP call
{
"/api": {
"target": " http://127.0.01:7000",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
And started server like so:
ng serve --proxy-config proxy.conf.json -o
server started on 4200 and creates proxy on http://127.0.01:7000/api
I have also created ssl proxy for HTTPS call
{
"/api": {
"target": "https://127.0.01:7001",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
Also started server like so on different port
ng serve --proxy-config proxy.ssl.conf.json –-port 4400
server started on 4400 and creates proxy on https://127.0.01:7001/api
Now I make the first call to backend url http://127.0.01:7000/api/permission
It calls through as http://localhost:4200/api/permission
It goes through filter and does some processing then it checks if call is through http or https if not then asks to redirect to https://localhost:7001/api/permission with some status code.
So in angular inside interceptor I check for the status, if status is for redirect, I redirect the url to
https://127.0.01:7001/api/permission
using
window.location.href=”https://localhost:4400/api/permission”
don’t be confuse because it calls like https://localhost:4400 and concat with backend url which is /api/permission.
Angular folks must be aware of that.
But I get a 504 error gateway timeout on chrome dev tools console
On cmd where I have started the ng server I get this
Error occurred while trying to proxy request /api/permission from localhost:4400 to https://127.0.01:7001 (ECONNRESET) (https ://nodejs.org/api/errors.html#errors_common_system_errors)
I am dead sure it’s a SSL issue but I just don’t know how to fix this.
I have done a lot research on this. I am frustrated, I have spent more than enough time to find a solution for this. I cant basically move pass this till its converted from http to https because rest of the uri calls must be made on https.
I found a link
How to send an HTTPS request from an Angular front-end to a server secured with a self signed certificate?
I think solution number one made sense
Add the self-signed certificate to the trusted store on the server where the angular app runs. (But in your case u cant do this because u got no access to the gitpages trusted store.
But I cant say for sure.
Any help please. I would really appreciate that. I am pretty much stuck at this point.
Cheers
This should work:
#Injectable()
export class httpsInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log(req.url);
const secureReq = req.clone({
url: req.url.replace('http://', 'https://')
});
return next.handle(secureReq);
}
}
you must create an interceptor and import it in the module inside provider,
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true } ]
Sorry I am a bit late to answer. But the exact answer to my problem was PKI which is mutual authentication configured on weblogic and the way its done is you need to deploy your angular app on weblogic to kick in mutual authentication. There are several videos out their on how to deploy angular app on weblogic if someone looking to learn as well as how to configure mutual authentication on weblogic. Cheers

URI for connecting to Heroku WebSocket endpoint

We have a Java web application at http://ourapp.com hosted at Heroku and the frontend of the app cannot connect to the WebSocket endpoint (endpoint) running in a Heroku dyno. We have tried these URIs:
ws://ourapp.com/endpoint
ws://ourapp.com:80/endpoint
ws://ourapp.com:8080/endpoint
ws://ourapp.com:8084/endpoint
ws://ourapp.com:443/endpoint
wss://ourapp.com/endpoint
wss://ourapp.com:80/endpoint
wss://ourapp.com:8080/endpoint
wss://ourapp.com:8084/endpoint
wss://ourapp.com:443/endpoint
None of the above open a connection. What are we missing here?
PS: I have set up a test ground: http://vakuutustiedot-dev.herokuapp.com/websocket.test.html (the URI is PROTOCOL:vakuutustiedot-dev.herokuapp.com:PORT/trial)
The target app runs in a Heroku Apache Tomcat 8.5.38.
What comes to the port number, I am not sure how to get one.
Perhaps you have missed adding the support of WebSockets to Heroku, like in this answer (https://stackoverflow.com/a/50002416/11197115)?
Maybe you should try configuring the proxy attribute of devServer. This attribute is used when the frontend app and backend api are not running on the same host. Perhaps the below setting might solve your problem.
module.exports = {
devServer: {
proxy: 'ws://ourapp.com:8080/endpoint'
}
}
For more info see the docs: https://cli.vuejs.org/config/#devserver

GWT back-end intercepting/blocking external requests

My company’s web application is using GWT both for front-end and back-end and we’d like to remove GWT from the project. Our current objective would be to make a new login page in Angular2 using the existing GWT back-end.
The main problem we encounter at the moment is that all the requests coming from outside the current GWT front-end seem to be intercepted/blocked and don’t return anything. I’m currently using Postman to make GET requests from the server.
Here is the URL I’m calling : http://localhost:9997/RestServer/api/users/1.
Postman’s response:
« Could not get any response
There was an error connecting to http://localhost:9997/RestServer/api/users/1. »
GWT Development Mode’s console returns an error:
[TRACE] Connection received from 127.0.0.1:60296
[ERROR] Unrecognized command for client; closing connection
com.google.gwt.dev.shell.BrowserChannelException: Invalid message type 71
at com.google.gwt.dev.shell.BrowserChannel$Message.readMessageType(BrowserChannel.java:1135)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:248)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
at java.lang.Thread.run(Thread.java:745)
Have you got any idea why my requests are intercepted? Why I can't even receive a http response?
If you need more informations to answer just ask for it.
Port 9997 in the old dev mode is not an HTTP server. This is the port on which the legacy browser plugin (unsupported in modern FF and Chrome due to breaking changes in those browsers) would connect to run Java code and enable remote debugging, hotswapping, etc.
Instead, you need to connect to the HTTP port, which is 8888 or 8080 or something like that.

Spring websocket connection not being established

I followed this tutorial to build a spring websocket application. I've kept each file as it is but I'm neither using maven nor gradle. I run the index.html file on the tomcat server. When I click connect I get:
Opening Web Socket... GET http://localhost:8080/hello/info 404 (Not
Found) Whoops! Lost connection to undefined
in my Chrome's Developer window.
Why is this happening?
link may help. here I have given whole example.
for this you will require stomp.js, sockjs on your client side
and spring-websocket & spring-messaging 4.2.6.RELEASE jar in your server side,

connect websocket to ubuntu server hosted in virtualbox

I've created a basic java EE 7 chat application - with Intellij Ultimate 14 - that lets users send messages and receive messages (using sessions, no room, no user identification).
I've tried the application by itself on a glassfish 4.1 server on windows 8.1 : it works perfectly.
Now I'm trying to run it in an ubuntu 14.04 server hosted in virtualbox (same glassfish and java ee version), this is so that I can later work on clustering the application.
When I install the application on the ubuntu server, using the web based interface (that I access from the windows host), I can load the application in a chrome, but the websocket doesn't seem to connect properly and therefore I cannot send any message at all.
By the way, I've tried connecting the websocket on the glassfish installed on the windows and it works fine.
Here is the html side of the app connecting the websocket to the server :
var host = "ws://" + document.location.host + "/GlassFish7_war/test";
wsocket = new WebSocket(host);
wsocket.onmessage = onMessage; // the function that displays received messages
and here is the relevant part of the server accepting the socket :
#ServerEndpoint("/test")
public class MyEndPoint {
#OnOpen
public void openConnection(Session session) {
session.getBasicRemote().sendText("hello there !");
// [...]
}
}
you guessed it : I never receive the "hello there !" message on the client side.
I think the problem might come from the configuration of the virtualbox network, yet I can't seem to figure out what to do about it. Currently I have a bridged and a NAT adapter.
Any help would be greatly appreciated !
Thanks a lot !

Categories

Resources