While I am within a Servlet Context I can easily get the real system file path by calling on request.getServletContext().getRealPath(UPLOAD_PATH). Please friends how can I do the equivalent from within a WebSocket Endpoint in Java EE 7. Thanks in advance.
Asked
Active
Viewed 1,004 times
1 Answers
0
You can get path information from the ServerEndpointConfig#getPath(). The only difference between the results of this method and ServletContext#getRealPath()
is that this gives the relateive path; you could just prefix the results of that method with the root context name. To get the results, you need to implement onOpen
(from the javax.websocket.Endpoint
class)
//called when the client first negotiates the opening of the websocket connection
public void onOpen(Session session, ServerEndpointConfig config){
String path = config.getPath();
}

kolossus
- 20,559
- 3
- 52
- 104
-
Thanks so much @kolossus for the responses, but unfortunately that didn't solve my problem. ServerEndpointConfig#getPath() return path for the deployed endpoint. But what i am looking is the real system path. Something that could look like /home/projects/java/web/projectname just as it is in ServletContext#getRealPath() – Paullo Sep 23 '14 at 19:02
-
@Paullo - you could use [this](http://stackoverflow.com/a/23405830/1530938) to get the servletcontext, and from there see if the path returned works for you – kolossus Sep 26 '14 at 19:50
-
I dont think so, I have searched through the API but there's nothing like that. But I will any sample code if you thing it is posible – Paullo Sep 27 '14 at 23:57