Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to access server configuration information from JAX-WS web service implementation?

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I set up a working project which deploys a web service using JAX-WS to a Jetty web server via Maven Jetty Plugin.
I attached part of pom.xml, web service interface and web service implementation below.

So, what's the problem?

The web service generates a file which must be made available via http. The web service responds with the URI of that file.
I thought the best option to accomplish this is to define a ContextHandler serving as a file server (see pom.xml below).
I want to be able to configure the resourceBase and contextPath.

However, I did not find a way to access this (any) configuration from the web service implementation in order to provide the necessary 
information to the web service where to store the generated file on disk. Besides persisting the file, I need to determine the URI to be returned
back to the client. While I am only declaring the contextPath in pom.xml, which I need to have access to, how can I actually determine host and port
within the web service implemention? There is nothing such as a request object known from servlets.  

Or is there a better way?


<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<contextHandler implementation="org.mortbay.jetty.handler.ContextHandler">
<handler implementation="org.mortbay.jetty.handler.ResourceHandler"/>

Web Service Interface

@WebService(targetNamespace = "", name = "Service")
public interface Service {

@WebResult(name = "return", targetNamespace = "")
@RequestWrapper(localName = "Align", targetNamespace = "", className = "")
@WebMethod(operationName = "Align", action = "Align")
@ResponseWrapper(localName = "AlignResponse", targetNamespace = "", className = "")
public java.lang.String align(
@WebParam(name = "param1", targetNamespace = "")
java.lang.String param1,
@WebParam(name = "param2", targetNamespace = "")
java.lang.String param2,
@WebParam(name = "input3", targetNamespace = "")
java.lang.String input3,
@WebParam(name = "parameters", targetNamespace = "")
java.util.List<> parameters
) throws SERVICEFault;

Web Service implementation

targetNamespace = "",

public class ServiceImpl implements Service {
Ranch Hand
Posts: 2198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to obtain the HttpServletRequest object of a web service request in a JAX-WS web service handler.
Using the getRequestURL method you should be able to retrieve the URL the client used to perform the request.
In the handler, you can then insert the data you need in the web service into the SOAP message context.
The message context can later be obtained in the web service, via the WebServiceContext.
Best wishes!
    Bookmark Topic Watch Topic
  • New Topic