npit npit - 1 month ago 10
reST (reStructuredText) Question

How to get simple javax.ws REST service url

Below is a toy example of a simple service using

javax.ws
. 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;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@WebService
@Path("/service")
public class testserver
{
@GET
@Path("/test")
@WebMethod
public String test()
{
return "<html>Test text here</html>";
}
}


And this is the service deployer function:

package packagename;
import javax.xml.ws.Endpoint;

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
http://localhost:7777/service/test
produce the text of the
test()
function? I am getting a Server not found error from my browser.

Below is the wsdl file at
http://localhost:7777/?wsdl
. 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 (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<definitions targetNamespace="http://packagename/" name="testserverService">
<types>
<xsd:schema>
<xsd:import namespace="http://packagename/" schemaLocation="http://localhost:7777/?xsd=1"/>
</xsd:schema>
</types>
<message name="test">
<part name="parameters" element="tns:test"/>
</message>
<message name="testResponse">
<part name="parameters" element="tns:testResponse"/>
</message>
<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"/>
</operation>
</portType>
<binding name="testserverPortBinding" type="tns:testserver">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="test">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="testserverService">
<port name="testserverPort" binding="tns:testserverPortBinding">
<soap:address location="http://localhost:7777/"/>
</port>
</service>
</definitions>


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

Answer

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

javax.ws.rs.* 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

Comments