npit npit - 10 months ago 58
reST (reStructuredText) Question

How to get simple REST service url

Below is a toy example of a simple service using
. I want to get the service URL, callable from a web browser or curl.
This is the toy service code:

package packagename;

import javax.jws.WebMethod;
import javax.jws.WebService;

public class testserver
public String test()
return "<html>Test text here</html>";

And this is the service deployer function:

package packagename;

public class deploy
public static void main(String [] args)

String endpointURL = "http://localhost:7777/";
Endpoint.publish(endpointURL,new testserver());

I run the java file via bash without errors.

Shouldn't navigating to
produce the text of the
function? I am getting a Server not found error from my browser.

Below is the wsdl file at
. Is the information I am looking for somewhere here? I have tried some urls by getting information from below (testserverService, etc) without success.

<!-- Published by JAX-WS RI ( RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
<!-- Generated by JAX-WS RI ( RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
<definitions targetNamespace="http://packagename/" name="testserverService">
<xsd:import namespace="http://packagename/" schemaLocation="http://localhost:7777/?xsd=1"/>
<message name="test">
<part name="parameters" element="tns:test"/>
<message name="testResponse">
<part name="parameters" element="tns:testResponse"/>
<portType name="testserver">
<operation name="test">
<input wsam:Action="http://packagename/testserver/testRequest" message="tns:test"/>
<output wsam:Action="http://packagename/testserver/testResponse" message="tns:testResponse"/>
<binding name="testserverPortBinding" type="tns:testserver">
<soap:binding transport="" style="document"/>
<operation name="test">
<soap:operation soapAction=""/>
<soap:body use="literal"/>
<soap:body use="literal"/>
<service name="testserverService">
<port name="testserverPort" binding="tns:testserverPortBinding">
<soap:address location="http://localhost:7777/"/>

I am guessing the answer is very simple or I am making gross syntax errors in my code.
Can you help ?

Answer Source

You are mixing both SOAP and REST APIs, which is NOT correct. You can't use them together for the same endpoint.

javax.jws.* package (called as JAX-WS) represents SOAP API* package (called as JAX-RS) represents REST API

You need to understand the difference between SOAP & REST web services. You can look at here for more details on these concepts.

Assuming that you are looking for REST services implementation, in general, REST services are deployed into servers (like Tomcat, Jetty, Weblogic), but if you need to run them standalone look here