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 ?