Does a pure spring based servlet have an endpoint URL such as CXF based WSDL?

I have a perfectly working pair of demo servers / client applications using Spring (only!) - CXF or WSDL are not involved. It works with Apache Tomcat 7.0.34.

I was curious to find out if I could see any trace in her presence in the browser ( http://localhost:8080/ ), but I could not find any hint of the URL in the source code (copied verbatim from the tutorial).

Then I found this thread , which provided a way to get the endpoint URL:

 TransportContext tc = TransportContextHolder.getTransportContext(); WebServiceConnection wc = tc.getConnection(); URI uri = wc.getUri(); 

I added this to my demo / tutorial client code, and while the first statement ( getTransportContext() ) throws no exception, it returns null , and so the second ( getConnection() ) throws a NullPointerException.

Why?

Clean Spring Servlets Don't Have Endpoint URLs?

If not, what am I missing? How can I get the service url?

I know that the client knows about the server using the context path and the bean identifier (as defined in general by beans.xml):

 ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] {"/sample/spring/beans.xml" } ); 

But isn't the URL equivalent to this? How do WSDLs do?

+4
source share
1 answer

I agree with @GreyBeardedGeek's comment, there is no concept of an endpoint URL in a Spring web application (the Java servlet web application as a whole).

If you need to check the time which URL the user used for your application, you can use the ServletRequest / HttpServletRequest methods such as getRemoteAddr (), getRemoteHost (), getURL (), getContextPath (), etc. For instance:

 @RequestMapping("/home") public String home(HttpServletRequest req) { String host = req.getRemoteHost(); // ... } 

However, be aware that multiple URLs may point to the same tomcat server, for example, if reverse proxy / DNS -CName is set. And this may (or may not) give you a different URL.

+1
source

All Articles