Link to wsdl custom url

I am creating a web service that needs to register on another server by sending my wsdl url to that server.

I built a very simple web service in Netbeans,

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

and Netbeans automatically directs me to localhost: 8080 / RegisterTest / RegisterTestService? Tester, and of course wsdl can be found in localhost: 8080 / RegisterTest / RegisterTestService? wsdl.

How to get this URL programmatically?

Edit: I noticed that the only place that seems to store this URL is the Glassfish server itself. The context root seems to be found only in glassfish / domain // config / domain.xml. Is there a good way to access Glassfish APIs? I can easily get the endpoint address through the user interface in applications> serviceName> View Endpoint, is there a programmatic way to do this? I tried looking at asadmin commands but cannot find anything there that has a context url or a final url.

+3
source share
1 answer

Unconfirmed, but should be close to what you are looking for:

@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();
    }
}
0
source

All Articles