简体   繁体   English

如何获得简单的javax.ws REST服务URL

[英]How to get simple javax.ws REST service url

Below is a toy example of a simple service using javax.ws . 下面是一个使用javax.ws的简单服务的玩具示例。 I want to get the service URL, callable from a web browser or curl. 我想获取可从Web浏览器或curl调用的服务URL。 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. 我通过bash运行Java文件而没有错误。

Shouldn't navigating to http://localhost:7777/service/test produce the text of the test() function? 不应浏览到http://localhost:7777/service/test生成test()函数的文本吗? I am getting a Server not found error from my browser. 我从浏览器中收到“找不到服务器”错误。

Below is the wsdl file at http://localhost:7777/?wsdl . 以下是位于http://localhost:7777/?wsdl的wsdl文件。 Is the information I am looking for somewhere here? 我在这里寻找信息吗? I have tried some urls by getting information from below (testserverService, etc) without success. 我尝试通过从下面获取信息(testserverService等)来尝试一些URL,但没有成功。

  <!-- 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 ? 你能帮我吗 ?

You are mixing both SOAP and REST APIs, which is NOT correct. 您正在混合使用SOAP和REST API,这是不正确的。 You can't use them together for the same endpoint. 您不能将它们一起用于同一端点。

javax.jws.* package (called as JAX-WS) represents SOAP API javax.jws.*包(称为JAX-WS)表示SOAP API

javax.ws.rs.* package (called as JAX-RS) represents REST API javax.ws.rs.*包(称为JAX-RS)表示REST API

You need to understand the difference between SOAP & REST web services. 您需要了解SOAP和REST Web服务之间的区别。 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 假设您正在寻找REST服务的实现,通常,REST服务已部署到服务器(例如Tomcat,Jetty,Weblogic)中,但是如果您需要独立运行它们,请看这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM