我有一个EJB无状态Bean,由Websphere内的Scheduler自动执行.我的EJB安装在Websphere中.在我的EJB内部,我想向其他应用程序公开的Web服务发出http请求(在同一个服务器内部).我尝试使用相对路径,因为这是我通常在应用程序之间发出请求的方式,但在我的bean中我不知道如何获取主机名和端口来构建URL.
我设法通过这样做得到主机(IP):
InetAddress.getLocalHost().toString();
Run Code Online (Sandbox Code Playgroud)
但我也需要端口号.问题是:如何获取安装EJB应用程序的应用程序服务器(Websphere)的主机和端口号?这可能吗?
这段代码是我尝试发出请求的方式,但这不起作用,因为我需要完整的路径:
URL url = new URL("/MyOtherAppName/myservice");
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length",
Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoOutput(true);
Run Code Online (Sandbox Code Playgroud)
- 编辑1 ----
我认为用户Gas的方法很好,并且使我的应用程序更容易配置.
我按照本指南实现了URL Provider方法:
我有这两个错误:
'System.Array'不包含'Aggregate'的定义,并且没有扩展方法'Aggregate'接受类型'System.Array'的第一个参数可以找到(你是否缺少using指令或程序集引用?)
'System.Collections.Generic.IEnumerable <object []>'不包含'ToArray'的定义,也没有扩展方法'ToArray'接受类型'System.Collections.Generic.IEnumerable <object []>'的第一个参数可以找到(你错过了使用指令或程序集引用吗?)
这是我的代码:
/*
* Get all the possible permutations
*/
public static IEnumerable<object[]> CartesianProduct(params object[][] inputs)
{
//ERROR: Function Aggregate is not recognized
return inputs.Aggregate(
(IEnumerable<object[]>)new object[][] { new object[0] },
(soFar, input) =>
from prevProductItem in soFar
from item in input
select prevProductItem.Concat(new object[] { item }).ToArray());
}
public void test()
{
//Get all the posible permutations between parents values.
var cartesianProduct = CartesianProduct(parentsValues);
object[][] producto = cartesianProduct.ToArray();
//ERROR: Function ToArray is not …Run Code Online (Sandbox Code Playgroud) .net ×1
.net-4.5 ×1
c# ×1
ejb ×1
ienumerable ×1
inetaddress ×1
java ×1
stateless ×1
system.array ×1
websphere ×1