java url ip_Java URL.getIp方法代碼示例

该段代码涉及Dubbo服务的导出与部署,使用了Jetty服务器,并检查了Servlet上下文。当使用Servlet服务器时,确保了上下文路径与外部web应用路径匹配,并在服务停止时进行卸载。此外,还涉及了Restful资源类的获取与服务器的启动与停止操作。
摘要由CSDN通过智能技术生成

import com.alibaba.dubbo.common.URL; //導入方法依賴的package包/類

protected Runnable doExport(T impl, Class type, URL url) throws RpcException {

String addr = url.getIp() + ":" + url.getPort();

Class implClass = ServiceClassHolder.getInstance().popServiceClass();

RestServer server = servers.get(addr);

if (server == null) {

server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));

server.start(url);

servers.put(addr, server);

}

String contextPath = getContextPath(url);

if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {

ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);

if (servletContext == null) {

throw new RpcException("No servlet context found. Since you are using server='servlet', " +

"make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");

}

String webappPath = servletContext.getContextPath();

if (StringUtils.isNotEmpty(webappPath)) {

webappPath = webappPath.substring(1);

if (!contextPath.startsWith(webappPath)) {

throw new RpcException("Since you are using server='servlet', " +

"make sure that the 'contextpath' property starts with the path of external webapp");

}

contextPath = contextPath.substring(webappPath.length());

if (contextPath.startsWith("/")) {

contextPath = contextPath.substring(1);

}

}

}

final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

server.deploy(resourceDef, impl, contextPath);

final RestServer s = server;

return new Runnable() {

public void run() {

// TODO due to dubbo's current architecture,

// it will be called from registry protocol in the shutdown process and won't appear in logs

s.undeploy(resourceDef);

}

};

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值