Wso2 如何获得';碳之家';在java代码中
我试图实现一个Axis2服务,该服务接收用户请求,并使用carbon databridge thrift(通过“org.wso2.carbon.databridge.agent.thrift.DataPublisher”)将它们作为事件发布到CEP 我遵循wso2cep-3.1.0/samples/producers/activity-monitor中提供的代码示例 请参阅下面的代码片段Wso2 如何获得';碳之家';在java代码中,wso2,wso2cep,wso2as,Wso2,Wso2cep,Wso2as,我试图实现一个Axis2服务,该服务接收用户请求,并使用carbon databridge thrift(通过“org.wso2.carbon.databridge.agent.thrift.DataPublisher”)将它们作为事件发布到CEP 我遵循wso2cep-3.1.0/samples/producers/activity-monitor中提供的代码示例 请参阅下面的代码片段 public class GatewayServiceSkeleton{ private
public class GatewayServiceSkeleton{
private static Logger logger = Logger.getLogger(GatewayServiceSkeleton.class);
public RequestResponse request(Request request)throws AgentException,
MalformedStreamDefinitionException,StreamDefinitionException,
DifferentStreamDefinitionAlreadyDefinedException,
MalformedURLException,AuthenticationException,DataBridgeException,
NoStreamDefinitionExistException,TransportException, SocketException,
org.wso2.carbon.databridge.commons.exception.AuthenticationException
{
final String GATEWAY_SERVICE_STREAM = "gateway.cep";
final String VERSION = "1.0.0";
final String PROTOCOL = "tcp://";
final String CEPHOST = "cep.gubnoi.com";
final String CEPPORT = "7611";
final String CEPUSERNAME = "admin";
final String CEPPASSWORD = "admin";
Object[] metadata = { request.getDeviceID(), request.getViewID()};
Object[] correlationdata = { request.getSessionID()};
Object[] payloaddata = {request.getBucket()};
KeyStoreUtil.setTrustStoreParams();
KeyStoreUtil.setKeyStoreParams();
DataPublisher dataPublisher = new DataPublisher(PROTOCOL + CEPHOST + ":" + CEPPORT, CEPUSERNAME, CEPPASSWORD);
//create event
Event event = new Event (GATEWAY_SERVICE_STREAM + ":" + VERSION, System.currentTimeMillis(), metadata, correlationdata, payloaddata);
//Publish event for a valid stream
dataPublisher.publish(event);
//stop
dataPublisher.stop();
RequestResponse response = new RequestResponse();
response.setSessionID(request.getSessionID());
response.setDeviceID(request.getDeviceID());
response.setViewID(request.getViewID());
response.setBucket(request.getBucket());
return response;
}
还有一个实用程序类用于设置密钥存储参数,如下所示
public class KeyStoreUtil {
static File filePath = new File("../../../repository/resources/security");
public static void setTrustStoreParams() {
String trustStore = filePath.getAbsolutePath();
System.setProperty("javax.net.ssl.trustStore", trustStore + "/client-truststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
}
public static void setKeyStoreParams() {
String keyStore = filePath.getAbsolutePath();
System.setProperty("Security.KeyStore.Location", keyStore + "/wso2carbon.jks");
System.setProperty("Security.KeyStore.Password", "wso2carbon");
}
}
我将该服务上传到wso2as-5.2.1中,并使用SOAPUI调用该服务
请求返回错误消息“无法借用TCP客户端”
我进行了调试,发现问题可能出在类“KeyStoreUtil”上
其中“filePath”以某种方式返回了“null”
static File filePath = new File("../../../repository/resources/security");
导致了这条线路的故障
DataPublisher dataPublisher = new DataPublisher(PROTOCOL + CEPHOST + ":" + CEPPORT, CEPUSERNAME, CEPPASSWORD);
我想如果我用“CARBON_HOME”的值来确定重点商店的位置会更好
所以我的问题是:
如何在Java代码中获得“CARBON_HOME”的值
也就是说。如果你再多想一想:
该服务将被多次调用;而“setTrustStoreParams”和“setKeyReparms”只需在服务器/服务启动时执行一次
那么,有没有更好的方法将“setTrustStoreParams”和“setKeyReparms”从服务代码中删除,或者实现为可配置项
请告知
谢谢
所以我的问题是:
如何在Java代码中获得“CARBON_HOME”的值
您应该像下面一样使用属性carbon.home
,它将检索WSO2产品的主目录
System.getProperty("carbon.home");