File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes How to access server configuration information from JAX-WS web service implementation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to access server configuration information from JAX-WS web service implementation? " Watch "How to access server configuration information from JAX-WS web service implementation? " New topic
Author

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

Steffen Weber
Greenhorn

Joined: Aug 04, 2011
Posts: 1
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?

pom.xml

<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
<webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>
<webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
<contextPath>/Service</contextPath>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>4433</port>
</connector>
</connectors>
<contextHandlers>
<contextHandler implementation="org.mortbay.jetty.handler.ContextHandler">
<contextPath>/Service</contextPath>
<resourceBase>${java.io.tmpdir}</resourceBase>
<handler implementation="org.mortbay.jetty.handler.ResourceHandler"/>
</contextHandler>
</contextHandlers>
</configuration>
</plugin>
</plugins>
</build>

Web Service Interface

@WebService(targetNamespace = "http://project.company.de/project-webutils/wsdl", name = "Service")
@XmlSeeAlso({de.company.project.project_webutils.xsd.ObjectFactory.class, de.company.project.resources.ObjectFactory.class})
public interface Service {

@WebResult(name = "return", targetNamespace = "http://project.company.de/project-webutils/xsd")
@RequestWrapper(localName = "Align", targetNamespace = "http://project.company.de/project-webutils/xsd", className = "de.company.project.project_webutils.xsd.AlignType")
@WebMethod(operationName = "Align", action = "Align")
@ResponseWrapper(localName = "AlignResponse", targetNamespace = "http://project.company.de/project-webutils/xsd", className = "de.company.project.project_webutils.xsd.AlignResponseType")
public java.lang.String align(
@WebParam(name = "param1", targetNamespace = "http://project.company.de/project-webutils/xsd")
java.lang.String param1,
@WebParam(name = "param2", targetNamespace = "http://project.company.de/project-webutils/xsd")
java.lang.String param2,
@WebParam(name = "input3", targetNamespace = "http://project.company.de/project-webutils/xsd")
java.lang.String input3,
@WebParam(name = "parameters", targetNamespace = "http://project.company.de/project-webutils/xsd")
java.util.List<de.company.project.resources.ArgumentType> parameters
) throws SERVICEFault;
}

Web Service implementation

@WebService(portName="Service",
serviceName="Service",
targetNamespace = "http://project.company.de/project-webutils/wsdl",
endpointInterface="de.company.project.project_webutils.wsdl.Service")

public class ServiceImpl implements Service {
...
 }
 
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
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!

My free books and tutorials: http://www.slideshare.net/krizsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access server configuration information from JAX-WS web service implementation?
 
Similar Threads
JSF 2 - Problem with ManagedBean
JAX-WS wsgen using Maven2
How to change jetty binding port number in maven.
Asynchronous web service client
How to change jetty binding port number in maven.