3

別のサーバーにその wsdl URL を送信することにより、別のサーバーに登録することになっている Web サービスを構築しています。

Netbeans で非常に基本的な Web サービスを構築しました。

@WebService
public class RegisterTest{
    @WebMethod(operationName = "emphasize")
    public String emphasize(@WebParam(name = "inputStr") String input){
        return input + "!!!";
    }
}

Netbeans は自動的に localhost:8080/RegisterTest/RegisterTestService?Tester に誘導します。当然、wsdl は localhost:8080/RegisterTest/RegisterTestService?wsdl にあります。

プログラムでこの URL を取得するにはどうすればよいですか?

編集: この URL を保存しているように見える唯一の場所は、glassfish サーバー自体であることに気付きました。context-root は、glassfish/domain//config/domain.xml でのみ見つかるようです。Glassfish サーバー API にアクセスする良い方法はありますか? アプリケーション > serviceName > View Endpoint の UI からエンドポイント アドレスを簡単に取得できます。プログラムでこれを行う方法はありますか? asadmin コマンドを調べてみましたが、context-root またはエンドポイント URL を取得するものが見つからないようです。

4

1 に答える 1

0

テストされていませんが、探しているものにかなり近いはずです:

@WebService
public class RegisterTest
{
    @Resource
    private WebServiceContext context;

    @WebMethod(operationName = "emphasize")
    public String emphasize(@WebParam(name = "inputStr") String input)
    {
        return input + "!!!";
    }

    @WebMethod(operationName = "getWsdlUrl")
    public String getWsdlUrl()
    {
        final ServletContext sContext = (ServletContext)
            this.context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
        final HttpServletRequest req = (HttpServletRequest)
            this.context.getMessageContext().get(MessageContext.SERVLET_REQUEST);
        final StringBuilder sb = new StringBuilder();

        sb.append(req.isSecure() ? "https" : "http");
        sb.append("://");
        sb.append(req.getLocalName());

        if ((req.isSecure() && req.getLocalPort() != 443) || 
            (!req.isSecure() && req.getLocalPort() != 80))
        {
            sb.append(":");
            sb.append(req.getLocalPort());          
        }

        sb.append(sContext.getContextPath());
        sb.append(RegisterTest.class.getSimpleName());
        sb.append("Service?wsdl");

        return sb.toString();
    }
}
于 2013-09-04T05:22:17.867 に答える