我试图实现一个Axis2服务,该服务接收用户请求并将它们作为事件发布到CEP中,并使用(通过Axis2)。
我遵循了wso2cep-3.1.0/samples/producers/activity-monitor中提供的代码示例
请看下面的代码片段
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‘和'setKeyStoreParams’则只需要在服务器/服务启动时执行一次。
那么,是否有更好的方法将“setTrustStoreParams”和“setKeyStoreParams”从服务代码中删除,或者实现为可配置项?
请指教
谢谢
发布于 2015-09-02 02:37:49
所以我的问题是: 我如何才能在Java代码中获得'CARBON_HOME‘的值?
您应该使用属性carbon.home,如下所示,它将检索WSO2产品的主目录。
System.getProperty("carbon.home");https://stackoverflow.com/questions/32325533
复制相似问题