Search code examples
javaweb-servicestomcatsoapjax-ws

How to change port from 8080 of jax ws webservice?


I followed https://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/ this tutorial and made a webservice running on port 8080.

I saw this option:

jax-ws webservice's endpoint is always localhost

But I want to know if there is another way in setting the port in a configurable file?

I only have sun-jaxws.xml and web.xml. Do I need 1 more file?

I defined it something like this:

@WebService(endpointInterface="com.abc.service.ClassName",portName = "WebservicePort", 
serviceName = "ABCFunctions")

Sun jaxws.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<endpoints
  xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
  version="2.0">
  <endpoint
      name="ABCFunctions"
      implementation="com.abc.service.ClassName""
      url-pattern="/ABCFunctions"/>
</endpoints>

web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, 
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

<web-app>
    <listener>
        <listener-class>
                com.sun.xml.ws.transport.http.servlet.WSServletContextListener
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>ABCFunctions</servlet-name>
        <servlet-class>
            com.sun.xml.ws.transport.http.servlet.WSServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>ABCFunctions</servlet-name>
        <url-pattern>/ABCFunctions</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>120</session-timeout>
    </session-config>
</web-app>

As of now I can only change it via server.xml Connector config of Tomcat. Is there a way that the webservice has a separate port??

<Connector port="8080" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" />

Solution

  • While publishing the web service you can change the port number