forked from github/OPC_Client
调整依赖 更换日志组件
This commit is contained in:
@@ -6,11 +6,6 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.kohsuke.jinterop</groupId>
|
||||
<artifactId>j-interop</artifactId>
|
||||
@@ -22,5 +17,41 @@
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 使用maven-jar-plugin和maven-dependency-plugin插件打包 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>com.freud.opc.utgard.cases.OPCTest2</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.freud.dcom.utgard.cases;
|
||||
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.common.JISystem;
|
||||
import org.jinterop.dcom.core.IJIComObject;
|
||||
import org.jinterop.dcom.core.JIClsid;
|
||||
import org.jinterop.dcom.core.JIComServer;
|
||||
import org.jinterop.dcom.core.JISession;
|
||||
import org.openscada.opc.dcom.da.OPCSERVERSTATUS;
|
||||
import org.openscada.opc.dcom.da.impl.OPCServer;
|
||||
|
||||
/**
|
||||
* 获取Server的Status信息 中文
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class DCOMTest1 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
JISystem.setAutoRegisteration(true);
|
||||
|
||||
JISession _session = JISession.createSession(
|
||||
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
|
||||
getEntryValue(CONFIG_PASSWORD));
|
||||
|
||||
final JIComServer comServer = new JIComServer(
|
||||
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
|
||||
getEntryValue(CONFIG_HOST), _session);
|
||||
|
||||
final IJIComObject serverObject = comServer.createInstance();
|
||||
|
||||
OPCServer server = new OPCServer(serverObject);
|
||||
|
||||
dumpServerStatus(server);
|
||||
|
||||
}
|
||||
|
||||
public static void dumpServerStatus(final OPCServer server)
|
||||
throws JIException {
|
||||
|
||||
final OPCSERVERSTATUS status = server.getStatus();
|
||||
|
||||
System.out.println("===== SERVER STATUS ======");
|
||||
System.out.println("State: " + status.getServerState().toString());
|
||||
System.out.println("Vendor: " + status.getVendorInfo());
|
||||
System.out.println(String.format("Version: %d.%d.%d",
|
||||
status.getMajorVersion(), status.getMinorVersion(),
|
||||
status.getBuildNumber()));
|
||||
System.out.println("Groups: " + status.getGroupCount());
|
||||
System.out.println("Bandwidth: " + status.getBandWidth());
|
||||
System.out.println(String.format("Start Time: %tc", status
|
||||
.getStartTime().asCalendar()));
|
||||
System.out.println(String.format("Current Time: %tc", status
|
||||
.getCurrentTime().asCalendar()));
|
||||
System.out.println(String.format("Last Update Time: %tc", status
|
||||
.getLastUpdateTime().asCalendar()));
|
||||
System.out.println("===== SERVER STATUS ======");
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
package com.freud.dcom.utgard.cases;
|
||||
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.common.JISystem;
|
||||
import org.jinterop.dcom.core.IJIComObject;
|
||||
import org.jinterop.dcom.core.JIClsid;
|
||||
import org.jinterop.dcom.core.JIComServer;
|
||||
import org.jinterop.dcom.core.JISession;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
import org.openscada.opc.dcom.da.OPCBROWSEDIRECTION;
|
||||
import org.openscada.opc.dcom.da.OPCBROWSETYPE;
|
||||
import org.openscada.opc.dcom.da.OPCNAMESPACETYPE;
|
||||
import org.openscada.opc.dcom.da.impl.OPCBrowseServerAddressSpace;
|
||||
import org.openscada.opc.dcom.da.impl.OPCServer;
|
||||
|
||||
/**
|
||||
* 遍历OPC连接下的所有Group和Item
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class DCOMTest2 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JISystem.setAutoRegisteration(true);
|
||||
|
||||
/**
|
||||
* Session获取
|
||||
*/
|
||||
JISession _session = JISession.createSession(
|
||||
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
|
||||
getEntryValue(CONFIG_PASSWORD));
|
||||
|
||||
final JIComServer comServer = new JIComServer(
|
||||
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
|
||||
getEntryValue(CONFIG_HOST), _session);
|
||||
|
||||
final IJIComObject serverObject = comServer.createInstance();
|
||||
|
||||
OPCServer server = new OPCServer(serverObject);
|
||||
final OPCBrowseServerAddressSpace serverBrowser = server.getBrowser();
|
||||
|
||||
/**
|
||||
* Flat形式获取所有Item信息
|
||||
*/
|
||||
browseFlat(serverBrowser);
|
||||
|
||||
/**
|
||||
* 获取所有的Group和Item信息
|
||||
*/
|
||||
browseTree(serverBrowser);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tree形式获取所有Group和Item的信息
|
||||
*/
|
||||
private static void browseTree(final OPCBrowseServerAddressSpace browser)
|
||||
throws IllegalArgumentException, UnknownHostException, JIException {
|
||||
System.out.println("Showing hierarchial address space");
|
||||
System.out.println(String.format("Organization: %s",
|
||||
browser.queryOrganization()));
|
||||
|
||||
if (!browser.queryOrganization().equals(
|
||||
OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
browser.changePosition(null, OPCBROWSEDIRECTION.OPC_BROWSE_TO);
|
||||
browseTree(browser, 0);
|
||||
}
|
||||
|
||||
private static String printTab(int level) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < level; i++) {
|
||||
sb.append("\t");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void browseTree(final OPCBrowseServerAddressSpace browser,
|
||||
final int level) throws JIException, IllegalArgumentException,
|
||||
UnknownHostException {
|
||||
|
||||
for (final String item : browser.browse(OPCBROWSETYPE.OPC_LEAF, "", 0,
|
||||
JIVariant.VT_EMPTY).asCollection()) {
|
||||
|
||||
System.out.println(printTab(level) + "Leaf: " + item + "\tName: "
|
||||
+ browser.getItemID(item));
|
||||
}
|
||||
|
||||
for (final String item : browser.browse(OPCBROWSETYPE.OPC_BRANCH, "",
|
||||
0, JIVariant.VT_EMPTY).asCollection()) {
|
||||
System.out.println(printTab(level) + "Branch: " + item);
|
||||
browser.changePosition(item, OPCBROWSEDIRECTION.OPC_BROWSE_DOWN);
|
||||
browseTree(browser, level + 1);
|
||||
browser.changePosition(null, OPCBROWSEDIRECTION.OPC_BROWSE_UP);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flat形式获取Item的信息
|
||||
*/
|
||||
private static void browseFlat(final OPCBrowseServerAddressSpace browser)
|
||||
throws JIException, IllegalArgumentException, UnknownHostException {
|
||||
|
||||
System.out.println(String.format("Organization: %s",
|
||||
browser.queryOrganization()));
|
||||
|
||||
browser.changePosition(null, OPCBROWSEDIRECTION.OPC_BROWSE_TO);
|
||||
|
||||
System.out.println("Showing flat address space");
|
||||
for (final String id : browser.browse(OPCBROWSETYPE.OPC_FLAT, "", 0,
|
||||
JIVariant.VT_EMPTY).asCollection()) {
|
||||
System.out.println("Item: " + id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package com.freud.dcom.utgard.cases;
|
||||
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.common.JISystem;
|
||||
import org.jinterop.dcom.core.IJIComObject;
|
||||
import org.jinterop.dcom.core.JIClsid;
|
||||
import org.jinterop.dcom.core.JIComServer;
|
||||
import org.jinterop.dcom.core.JISession;
|
||||
import org.openscada.opc.dcom.da.OPCENUMSCOPE;
|
||||
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
|
||||
import org.openscada.opc.dcom.da.impl.OPCServer;
|
||||
|
||||
/**
|
||||
* 通过Scope遍历OPC连接下的所有Group信息
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class DCOMTest3 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JISystem.setAutoRegisteration(true);
|
||||
|
||||
/**
|
||||
* Session获取
|
||||
*/
|
||||
JISession _session = JISession.createSession(
|
||||
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
|
||||
getEntryValue(CONFIG_PASSWORD));
|
||||
|
||||
final JIComServer comServer = new JIComServer(
|
||||
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
|
||||
getEntryValue(CONFIG_HOST), _session);
|
||||
|
||||
final IJIComObject serverObject = comServer.createInstance();
|
||||
|
||||
OPCServer server = new OPCServer(serverObject);
|
||||
|
||||
/**
|
||||
* 添加一个Group的信息
|
||||
*/
|
||||
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
|
||||
0.0f, 1033);
|
||||
|
||||
enumerateGroups(server, OPCENUMSCOPE.OPC_ENUM_PUBLIC);
|
||||
enumerateGroups(server, OPCENUMSCOPE.OPC_ENUM_PRIVATE);
|
||||
enumerateGroups(server, OPCENUMSCOPE.OPC_ENUM_ALL);
|
||||
|
||||
// clean up
|
||||
server.removeGroup(group, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过Scope查找并遍历Groups的信息
|
||||
*
|
||||
* @param server
|
||||
* @param scope
|
||||
* @throws IllegalArgumentException
|
||||
* @throws UnknownHostException
|
||||
* @throws JIException JIException
|
||||
*/
|
||||
public static void enumerateGroups(final OPCServer server,
|
||||
final OPCENUMSCOPE scope) throws IllegalArgumentException,
|
||||
UnknownHostException, JIException {
|
||||
System.out.println("Enum Groups: " + scope.toString());
|
||||
|
||||
for (final String group : server.getGroups(scope).asCollection()) {
|
||||
System.out.println("Group: " + group);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
package com.freud.dcom.utgard.cases;
|
||||
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.common.JISystem;
|
||||
import org.jinterop.dcom.core.IJIComObject;
|
||||
import org.jinterop.dcom.core.JIClsid;
|
||||
import org.jinterop.dcom.core.JIComServer;
|
||||
import org.jinterop.dcom.core.JISession;
|
||||
import org.openscada.opc.dcom.common.EventHandler;
|
||||
import org.openscada.opc.dcom.common.KeyedResult;
|
||||
import org.openscada.opc.dcom.common.KeyedResultSet;
|
||||
import org.openscada.opc.dcom.common.Result;
|
||||
import org.openscada.opc.dcom.common.ResultSet;
|
||||
import org.openscada.opc.dcom.common.impl.OPCCommon;
|
||||
import org.openscada.opc.dcom.da.OPCDATASOURCE;
|
||||
import org.openscada.opc.dcom.da.OPCITEMDEF;
|
||||
import org.openscada.opc.dcom.da.OPCITEMRESULT;
|
||||
import org.openscada.opc.dcom.da.OPCITEMSTATE;
|
||||
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
|
||||
import org.openscada.opc.dcom.da.impl.OPCItemMgt;
|
||||
import org.openscada.opc.dcom.da.impl.OPCServer;
|
||||
import org.openscada.opc.dcom.da.impl.OPCSyncIO;
|
||||
|
||||
/**
|
||||
* 同步读取Item
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class DCOMTest4 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JISystem.setAutoRegisteration(true);
|
||||
|
||||
/**
|
||||
* Session获取
|
||||
*/
|
||||
JISession _session = JISession.createSession(
|
||||
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
|
||||
getEntryValue(CONFIG_PASSWORD));
|
||||
|
||||
final JIComServer comServer = new JIComServer(
|
||||
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
|
||||
getEntryValue(CONFIG_HOST), _session);
|
||||
|
||||
final IJIComObject serverObject = comServer.createInstance();
|
||||
|
||||
OPCServer server = new OPCServer(serverObject);
|
||||
|
||||
/**
|
||||
* 添加一个Group的信息
|
||||
*/
|
||||
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
|
||||
0.0f, 1033);
|
||||
|
||||
testItems(server, group, new String[] { "Saw-toothed Waves.Int2",
|
||||
"Saw-toothed Waves.test2" });
|
||||
|
||||
// clean up
|
||||
server.removeGroup(group, true);
|
||||
}
|
||||
|
||||
private static void showError(final OPCCommon common, final int errorCode)
|
||||
throws JIException {
|
||||
System.out.println(String.format("Error (%X): '%s'", errorCode,
|
||||
common.getErrorString(errorCode, 1033)));
|
||||
}
|
||||
|
||||
private static void showError(final OPCServer server, final int errorCode)
|
||||
throws JIException {
|
||||
showError(server.getCommon(), errorCode);
|
||||
}
|
||||
|
||||
private static boolean dumpOPCITEMRESULT(
|
||||
final KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result) {
|
||||
int failed = 0;
|
||||
for (final KeyedResult<OPCITEMDEF, OPCITEMRESULT> resultEntry : result) {
|
||||
System.out.println("==================================");
|
||||
System.out.println(String.format("Item: '%s' ", resultEntry
|
||||
.getKey().getItemID()));
|
||||
|
||||
System.out.println(String.format("Error Code: %08x",
|
||||
resultEntry.getErrorCode()));
|
||||
if (!resultEntry.isFailed()) {
|
||||
System.out.println(String.format("Server Handle: %08X",
|
||||
resultEntry.getValue().getServerHandle()));
|
||||
System.out.println(String.format("Data Type: %d", resultEntry
|
||||
.getValue().getCanonicalDataType()));
|
||||
System.out.println(String.format("Access Rights: %d",
|
||||
resultEntry.getValue().getAccessRights()));
|
||||
System.out.println(String.format("Reserved: %d", resultEntry
|
||||
.getValue().getReserved()));
|
||||
} else {
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
return failed == 0;
|
||||
}
|
||||
|
||||
private static void testItems(final OPCServer server,
|
||||
final OPCGroupStateMgt group, final String... itemIDs)
|
||||
throws IllegalArgumentException, UnknownHostException, JIException {
|
||||
|
||||
final OPCItemMgt itemManagement = group.getItemManagement();
|
||||
final List<OPCITEMDEF> items = new ArrayList<OPCITEMDEF>(itemIDs.length);
|
||||
for (final String id : itemIDs) {
|
||||
final OPCITEMDEF item = new OPCITEMDEF();
|
||||
item.setItemID(id);
|
||||
item.setClientHandle(new Random().nextInt());
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
final OPCITEMDEF[] itemArray = items.toArray(new OPCITEMDEF[0]);
|
||||
|
||||
System.out.println("Validate");
|
||||
KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result = itemManagement
|
||||
.validate(itemArray);
|
||||
if (!dumpOPCITEMRESULT(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// now add them to the group
|
||||
System.out.println("Add");
|
||||
result = itemManagement.add(itemArray);
|
||||
if (!dumpOPCITEMRESULT(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the server handle array
|
||||
final Integer[] serverHandles = new Integer[itemArray.length];
|
||||
for (int i = 0; i < itemArray.length; i++) {
|
||||
serverHandles[i] = new Integer(result.get(i).getValue()
|
||||
.getServerHandle());
|
||||
}
|
||||
|
||||
// set them active
|
||||
System.out.println("Activate");
|
||||
final ResultSet<Integer> resultSet = itemManagement.setActiveState(
|
||||
true, serverHandles);
|
||||
for (final Result<Integer> resultEntry : resultSet) {
|
||||
System.out.println(String.format("Item: %08X, Error: %08X",
|
||||
resultEntry.getValue(), resultEntry.getErrorCode()));
|
||||
}
|
||||
|
||||
// set client handles
|
||||
System.out.println("Set client handles");
|
||||
final Integer[] clientHandles = new Integer[serverHandles.length];
|
||||
for (int i = 0; i < serverHandles.length; i++) {
|
||||
clientHandles[i] = i;
|
||||
}
|
||||
itemManagement.setClientHandles(serverHandles, clientHandles);
|
||||
|
||||
System.out.println("Create async IO 2.0 object");
|
||||
// OPCAsyncIO2 asyncIO2 = group.getAsyncIO2 ();
|
||||
// connect handler
|
||||
|
||||
System.out.println("attach");
|
||||
final EventHandler eventHandler = group.attach(new DumpDataCallback());
|
||||
|
||||
// sleep
|
||||
try {
|
||||
System.out.println("Waiting...");
|
||||
Thread.sleep(10 * 1000);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
eventHandler.detach();
|
||||
|
||||
// sync IO - read
|
||||
final OPCSyncIO syncIO = group.getSyncIO();
|
||||
// OPCAsyncIO2 asyncIO2 = group.getAsyncIO2 ();
|
||||
/*
|
||||
* System.out.println ( "attach..enable" ); asyncIO2.setEnable ( true );
|
||||
* System.out.println ( "attach..refresh" ); asyncIO2.refresh (
|
||||
* (short)1, 1 );
|
||||
*/
|
||||
|
||||
final KeyedResultSet<Integer, OPCITEMSTATE> itemState = syncIO.read(
|
||||
OPCDATASOURCE.OPC_DS_DEVICE, serverHandles);
|
||||
for (final KeyedResult<Integer, OPCITEMSTATE> itemStateEntry : itemState) {
|
||||
final int errorCode = itemStateEntry.getErrorCode();
|
||||
System.out
|
||||
.println(String
|
||||
.format("Server ID: %08X, Value: %s, Timestamp: %d/%d (%Tc), Quality: %d, Error: %08X",
|
||||
itemStateEntry.getKey(), itemStateEntry
|
||||
.getValue().getValue(),
|
||||
itemStateEntry.getValue().getTimestamp()
|
||||
.getHigh(),
|
||||
itemStateEntry.getValue().getTimestamp()
|
||||
.getLow(), itemStateEntry
|
||||
.getValue().getTimestamp()
|
||||
.asCalendar(), itemStateEntry
|
||||
.getValue().getQuality(), errorCode));
|
||||
if (errorCode != 0) {
|
||||
showError(server, errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
// set them inactive
|
||||
System.out.println("In-Active");
|
||||
itemManagement.setActiveState(false, serverHandles);
|
||||
|
||||
// finally remove them again
|
||||
System.out.println("Remove");
|
||||
itemManagement.remove(serverHandles);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package com.freud.dcom.utgard.cases;
|
||||
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.common.JISystem;
|
||||
import org.jinterop.dcom.core.IJIComObject;
|
||||
import org.jinterop.dcom.core.JIClsid;
|
||||
import org.jinterop.dcom.core.JIComServer;
|
||||
import org.jinterop.dcom.core.JISession;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
import org.openscada.opc.dcom.common.KeyedResult;
|
||||
import org.openscada.opc.dcom.common.KeyedResultSet;
|
||||
import org.openscada.opc.dcom.da.PropertyDescription;
|
||||
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
|
||||
import org.openscada.opc.dcom.da.impl.OPCItemProperties;
|
||||
import org.openscada.opc.dcom.da.impl.OPCServer;
|
||||
|
||||
/**
|
||||
* 获取指定Item的Properties
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class DCOMTest5 {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(DCOMTest5.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JISystem.setAutoRegisteration(true);
|
||||
|
||||
/**
|
||||
* Session获取
|
||||
*/
|
||||
JISession _session = JISession.createSession(
|
||||
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
|
||||
getEntryValue(CONFIG_PASSWORD));
|
||||
|
||||
final JIComServer comServer = new JIComServer(
|
||||
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
|
||||
getEntryValue(CONFIG_HOST), _session);
|
||||
|
||||
final IJIComObject serverObject = comServer.createInstance();
|
||||
|
||||
OPCServer server = new OPCServer(serverObject);
|
||||
|
||||
/**
|
||||
* 添加一个Group的信息
|
||||
*/
|
||||
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
|
||||
0.0f, 1033);
|
||||
|
||||
final OPCItemProperties itemProperties = server
|
||||
.getItemPropertiesService();
|
||||
dumpItemProperties(itemProperties, "Saw-toothed Waves.Int");
|
||||
|
||||
// clean up
|
||||
server.removeGroup(group, true);
|
||||
LOGGER.info("test");
|
||||
}
|
||||
|
||||
public static void dumpItemProperties(
|
||||
final OPCItemProperties itemProperties, final String itemID)
|
||||
throws JIException {
|
||||
final Collection<PropertyDescription> properties = itemProperties
|
||||
.queryAvailableProperties(itemID);
|
||||
final int[] ids = new int[properties.size()];
|
||||
|
||||
System.out.println(String.format("Item Properties for '%s' (count:%d)",
|
||||
itemID, properties.size()));
|
||||
|
||||
int i = 0;
|
||||
for (final PropertyDescription pd : properties) {
|
||||
ids[i] = pd.getId();
|
||||
System.out.println("ID: " + pd.getId());
|
||||
System.out.println("Description: " + pd.getDescription());
|
||||
System.out.println("Variable Type: " + pd.getVarType());
|
||||
i++;
|
||||
}
|
||||
|
||||
System.out.println("Lookup");
|
||||
dumpItemPropertiesLookup(itemProperties, itemID, ids);
|
||||
|
||||
System.out.println("Query");
|
||||
dumpItemProperties2(itemProperties, itemID, ids);
|
||||
}
|
||||
|
||||
public static void dumpItemProperties2(
|
||||
final OPCItemProperties itemProperties, final String itemID,
|
||||
final int... ids) throws JIException {
|
||||
final KeyedResultSet<Integer, JIVariant> values = itemProperties
|
||||
.getItemProperties(itemID, ids);
|
||||
for (final KeyedResult<Integer, JIVariant> entry : values) {
|
||||
System.out.println(String.format(
|
||||
"ID: %d, Value: %s, Error Code: %08x", entry.getKey(),
|
||||
entry.getValue().toString(), entry.getErrorCode()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void dumpItemPropertiesLookup(
|
||||
final OPCItemProperties itemProperties, final String itemID,
|
||||
final int... ids) throws JIException {
|
||||
final KeyedResultSet<Integer, String> values = itemProperties
|
||||
.lookupItemIDs(itemID, ids);
|
||||
for (final KeyedResult<Integer, String> entry : values) {
|
||||
System.out.println(String.format(
|
||||
"ID: %d, Item ID: %s, Error Code: %08x", entry.getKey(),
|
||||
entry.getValue(), entry.getErrorCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.freud.dcom.utgard.cases;
|
||||
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.common.JISystem;
|
||||
import org.jinterop.dcom.core.IJIComObject;
|
||||
import org.jinterop.dcom.core.JIClsid;
|
||||
import org.jinterop.dcom.core.JIComServer;
|
||||
import org.jinterop.dcom.core.JISession;
|
||||
import org.openscada.opc.dcom.da.IORequest;
|
||||
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
|
||||
import org.openscada.opc.dcom.da.impl.OPCItemIO;
|
||||
import org.openscada.opc.dcom.da.impl.OPCServer;
|
||||
|
||||
/**
|
||||
* Query指定的Item
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class DCOMTest6 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JISystem.setAutoRegisteration(true);
|
||||
|
||||
/**
|
||||
* Session获取
|
||||
*/
|
||||
JISession _session = JISession.createSession(
|
||||
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
|
||||
getEntryValue(CONFIG_PASSWORD));
|
||||
|
||||
final JIComServer comServer = new JIComServer(
|
||||
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
|
||||
getEntryValue(CONFIG_HOST), _session);
|
||||
|
||||
final IJIComObject serverObject = comServer.createInstance();
|
||||
|
||||
OPCServer server = new OPCServer(serverObject);
|
||||
|
||||
/**
|
||||
* 添加一个Group的信息
|
||||
*/
|
||||
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
|
||||
0.0f, 1033);
|
||||
|
||||
final OPCItemIO itemIO = server.getItemIOService();
|
||||
queryItems(itemIO, "Saw-toothed Waves.Int1");
|
||||
|
||||
// clean up
|
||||
server.removeGroup(group, true);
|
||||
}
|
||||
|
||||
public static void queryItems(final OPCItemIO itemIO, final String... items)
|
||||
throws JIException {
|
||||
final IORequest[] requests = new IORequest[items.length];
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
requests[i] = new IORequest(items[i], 0);
|
||||
}
|
||||
|
||||
itemIO.read(requests);
|
||||
}
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
package com.freud.dcom.utgard.cases;
|
||||
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.common.JISystem;
|
||||
import org.jinterop.dcom.core.IJIComObject;
|
||||
import org.jinterop.dcom.core.JIClsid;
|
||||
import org.jinterop.dcom.core.JIComServer;
|
||||
import org.jinterop.dcom.core.JISession;
|
||||
import org.openscada.opc.dcom.common.EventHandler;
|
||||
import org.openscada.opc.dcom.common.KeyedResult;
|
||||
import org.openscada.opc.dcom.common.KeyedResultSet;
|
||||
import org.openscada.opc.dcom.common.Result;
|
||||
import org.openscada.opc.dcom.common.ResultSet;
|
||||
import org.openscada.opc.dcom.common.impl.OPCCommon;
|
||||
import org.openscada.opc.dcom.da.OPCDATASOURCE;
|
||||
import org.openscada.opc.dcom.da.OPCITEMDEF;
|
||||
import org.openscada.opc.dcom.da.OPCITEMRESULT;
|
||||
import org.openscada.opc.dcom.da.impl.OPCAsyncIO2;
|
||||
import org.openscada.opc.dcom.da.impl.OPCAsyncIO2.AsyncResult;
|
||||
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
|
||||
import org.openscada.opc.dcom.da.impl.OPCItemMgt;
|
||||
import org.openscada.opc.dcom.da.impl.OPCServer;
|
||||
|
||||
/**
|
||||
* 异步读取Item
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class DCOMTest7 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
JISystem.setAutoRegisteration(true);
|
||||
|
||||
/**
|
||||
* Session获取
|
||||
*/
|
||||
JISession _session = JISession.createSession(
|
||||
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
|
||||
getEntryValue(CONFIG_PASSWORD));
|
||||
|
||||
final JIComServer comServer = new JIComServer(
|
||||
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
|
||||
getEntryValue(CONFIG_HOST), _session);
|
||||
|
||||
final IJIComObject serverObject = comServer.createInstance();
|
||||
|
||||
OPCServer server = new OPCServer(serverObject);
|
||||
|
||||
/**
|
||||
* 添加一个Group的信息
|
||||
*/
|
||||
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
|
||||
0.0f, 1033);
|
||||
|
||||
testItems(group, new String[] { "Saw-toothed Waves.Int2" });
|
||||
|
||||
// clean up
|
||||
server.removeGroup(group, true);
|
||||
|
||||
}
|
||||
|
||||
public static void testItems(final OPCGroupStateMgt group,
|
||||
final String... itemIDs) throws IllegalArgumentException,
|
||||
UnknownHostException, JIException {
|
||||
final OPCItemMgt itemManagement = group.getItemManagement();
|
||||
final List<OPCITEMDEF> items = new ArrayList<OPCITEMDEF>(itemIDs.length);
|
||||
for (final String id : itemIDs) {
|
||||
final OPCITEMDEF item = new OPCITEMDEF();
|
||||
item.setItemID(id);
|
||||
item.setClientHandle(new Random().nextInt());
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
final OPCITEMDEF[] itemArray = items.toArray(new OPCITEMDEF[0]);
|
||||
|
||||
System.out.println("Validate");
|
||||
KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result = itemManagement
|
||||
.validate(itemArray);
|
||||
if (!dumpOPCITEMRESULT(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// now add them to the group
|
||||
System.out.println("Add");
|
||||
result = itemManagement.add(itemArray);
|
||||
if (!dumpOPCITEMRESULT(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the server handle array
|
||||
final Integer[] serverHandles = new Integer[itemArray.length];
|
||||
for (int i = 0; i < itemArray.length; i++) {
|
||||
serverHandles[i] = new Integer(result.get(i).getValue()
|
||||
.getServerHandle());
|
||||
}
|
||||
|
||||
// set them active
|
||||
System.out.println("Activate");
|
||||
final ResultSet<Integer> resultSet = itemManagement.setActiveState(
|
||||
true, serverHandles);
|
||||
for (final Result<Integer> resultEntry : resultSet) {
|
||||
System.out.println(String.format("Item: %08X, Error: %08X",
|
||||
resultEntry.getValue(), resultEntry.getErrorCode()));
|
||||
}
|
||||
|
||||
// set client handles
|
||||
System.out.println("Set client handles");
|
||||
final Integer[] clientHandles = new Integer[serverHandles.length];
|
||||
for (int i = 0; i < serverHandles.length; i++) {
|
||||
clientHandles[i] = i;
|
||||
}
|
||||
itemManagement.setClientHandles(serverHandles, clientHandles);
|
||||
|
||||
System.out.println("Create async IO 2.0 object");
|
||||
final OPCAsyncIO2 asyncIO2 = group.getAsyncIO2();
|
||||
|
||||
// connect handler
|
||||
System.out.println("attach");
|
||||
final EventHandler eventHandler = group.attach(new DumpDataCallback());
|
||||
|
||||
System.out.println("attach..enable");
|
||||
asyncIO2.setEnable(true);
|
||||
|
||||
System.out.println("attach..refresh");
|
||||
final int cancelId = asyncIO2.refresh(OPCDATASOURCE.OPC_DS_DEVICE, 1);
|
||||
System.out.println("Cancel ID: " + cancelId);
|
||||
|
||||
System.out.println("attach..read");
|
||||
final AsyncResult asyncResult = asyncIO2.read(2, serverHandles);
|
||||
System.out.println(String.format("attach..read..cancelId: %08X",
|
||||
asyncResult.getCancelId()));
|
||||
|
||||
// sleep
|
||||
try {
|
||||
System.out.println("Waiting...");
|
||||
Thread.sleep(10 * 1000);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Detaching");
|
||||
eventHandler.detach();
|
||||
|
||||
// set them inactive
|
||||
System.out.println("In-Active");
|
||||
itemManagement.setActiveState(false, serverHandles);
|
||||
|
||||
// finally remove them again
|
||||
System.out.println("Remove");
|
||||
itemManagement.remove(serverHandles);
|
||||
}
|
||||
|
||||
public static void showError(final OPCCommon common, final int errorCode)
|
||||
throws JIException {
|
||||
System.out.println(String.format("Error (%X): '%s'", errorCode,
|
||||
common.getErrorString(errorCode, 1033)));
|
||||
}
|
||||
|
||||
public static void showError(final OPCServer server, final int errorCode)
|
||||
throws JIException {
|
||||
showError(server.getCommon(), errorCode);
|
||||
}
|
||||
|
||||
public static boolean dumpOPCITEMRESULT(
|
||||
final KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result) {
|
||||
int failed = 0;
|
||||
for (final KeyedResult<OPCITEMDEF, OPCITEMRESULT> resultEntry : result) {
|
||||
System.out.println("==================================");
|
||||
System.out.println(String.format("Item: '%s' ", resultEntry
|
||||
.getKey().getItemID()));
|
||||
|
||||
System.out.println(String.format("Error Code: %08x",
|
||||
resultEntry.getErrorCode()));
|
||||
if (!resultEntry.isFailed()) {
|
||||
System.out.println(String.format("Server Handle: %08X",
|
||||
resultEntry.getValue().getServerHandle()));
|
||||
System.out.println(String.format("Data Type: %d", resultEntry
|
||||
.getValue().getCanonicalDataType()));
|
||||
System.out.println(String.format("Access Rights: %d",
|
||||
resultEntry.getValue().getAccessRights()));
|
||||
System.out.println(String.format("Reserved: %d", resultEntry
|
||||
.getValue().getReserved()));
|
||||
} else {
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
return failed == 0;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package com.freud.dcom.utgard.cases;
|
||||
|
||||
import org.openscada.opc.dcom.common.KeyedResult;
|
||||
import org.openscada.opc.dcom.common.KeyedResultSet;
|
||||
import org.openscada.opc.dcom.common.ResultSet;
|
||||
import org.openscada.opc.dcom.da.IOPCDataCallback;
|
||||
import org.openscada.opc.dcom.da.ValueData;
|
||||
|
||||
public class DumpDataCallback implements IOPCDataCallback {
|
||||
|
||||
public void cancelComplete(final int transactionId,
|
||||
final int serverGroupHandle) {
|
||||
System.out.println(String.format("cancelComplete: %08X, Group: %08X",
|
||||
transactionId, serverGroupHandle));
|
||||
}
|
||||
|
||||
public void dataChange(final int transactionId,
|
||||
final int serverGroupHandle, final int masterQuality,
|
||||
final int masterErrorCode,
|
||||
final KeyedResultSet<Integer, ValueData> result) {
|
||||
|
||||
System.out.println(String.format(
|
||||
"dataChange: %d, Group: %08X, MasterQ: %d, Error: %d",
|
||||
transactionId, serverGroupHandle, masterQuality,
|
||||
masterErrorCode));
|
||||
|
||||
for (final KeyedResult<Integer, ValueData> entry : result) {
|
||||
System.out.println(String.format(
|
||||
"%08X - Error: %08X, Quality: %d, %Tc - %s",
|
||||
entry.getKey(), entry.getErrorCode(), entry.getValue()
|
||||
.getQuality(), entry.getValue().getTimestamp(),
|
||||
entry.getValue().getValue().toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void readComplete(final int transactionId,
|
||||
final int serverGroupHandle, final int masterQuality,
|
||||
final int masterErrorCode,
|
||||
final KeyedResultSet<Integer, ValueData> result) {
|
||||
System.out.println(String.format(
|
||||
"readComplete: %d, Group: %08X, MasterQ: %d, Error: %d",
|
||||
transactionId, serverGroupHandle, masterQuality,
|
||||
masterErrorCode));
|
||||
|
||||
for (final KeyedResult<Integer, ValueData> entry : result) {
|
||||
System.out.println(String.format(
|
||||
"%08X - Error: %08X, Quality: %d, %Tc - %s",
|
||||
entry.getKey(), entry.getErrorCode(), entry.getValue()
|
||||
.getQuality(), entry.getValue().getTimestamp(),
|
||||
entry.getValue().getValue().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void writeComplete(final int transactionId,
|
||||
final int serverGroupHandle, final int masterErrorCode,
|
||||
final ResultSet<Integer> result) {
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.freud.opc.utgard;
|
||||
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
|
||||
/**
|
||||
* 配置文件工具类
|
||||
*
|
||||
@@ -21,7 +21,7 @@ public final class BaseConfiguration {
|
||||
public final static String CONFIG_HOST = "host";
|
||||
public final static String CONFIG_DOMAIN = "domain";
|
||||
public final static String CONFIG_CLSID = "clsid";
|
||||
public final static String CONFIG_PROGID = "progid";
|
||||
// public final static String CONFIG_PROGID = "progid";
|
||||
|
||||
private final static String CONFIG_FILE_NAME = "config.properties";
|
||||
|
||||
@@ -66,12 +66,12 @@ public final class BaseConfiguration {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static ConnectionInformation getPROGIDConnectionInfomation() {
|
||||
ci.setClsid(null);
|
||||
getConnectionInfomation();
|
||||
ci.setProgId(prop.getProperty(CONFIG_PROGID));
|
||||
return ci;
|
||||
}
|
||||
// public static ConnectionInformation getPROGIDConnectionInfomation() {
|
||||
// ci.setClsid(null);
|
||||
// getConnectionInfomation();
|
||||
// ci.setProgId(prop.getProperty(CONFIG_PROGID));
|
||||
// return ci;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获得基础的连接信息
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.freud.opc.utgard.cases;
|
||||
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
|
||||
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.openscada.opc.dcom.list.ClassDetails;
|
||||
import org.openscada.opc.lib.list.Categories;
|
||||
import org.openscada.opc.lib.list.Category;
|
||||
import org.openscada.opc.lib.list.ServerList;
|
||||
|
||||
/**
|
||||
* Get all the opc connection info from Server
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class OPCTest1 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ServerList serverList = new ServerList(getEntryValue(CONFIG_HOST),
|
||||
getEntryValue(CONFIG_USERNAME), getEntryValue(CONFIG_PASSWORD),
|
||||
getEntryValue(CONFIG_DOMAIN));
|
||||
|
||||
/** According the progid get the clsid, then get the classdetail */
|
||||
// final String cls = serverList
|
||||
// .getClsIdFromProgId("Matrikon.OPC.Simulation.1");
|
||||
//
|
||||
// ClassDetails cd = serverList.getDetails(cls);
|
||||
//
|
||||
// if (cd != null) {
|
||||
// System.out.println(cd.getProgId() + "=" + cd.getDescription());
|
||||
// }
|
||||
|
||||
Collection<ClassDetails> classDetails = serverList
|
||||
.listServersWithDetails(new Category[] {
|
||||
Categories.OPCDAServer10, Categories.OPCDAServer20,
|
||||
Categories.OPCDAServer30 }, new Category[] {});
|
||||
|
||||
for (ClassDetails cds : classDetails) {
|
||||
System.out.println(cds.getProgId() + "=" + cds.getDescription());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.freud.opc.utgard.cases;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
import com.freud.opc.utgard.BaseConfiguration;
|
||||
|
||||
/**
|
||||
* 同步读取某个点位的值
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class OPCTest3 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Server server = new Server(
|
||||
BaseConfiguration.getCLSIDConnectionInfomation(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
server.connect();
|
||||
|
||||
Group group = server.addGroup();
|
||||
Item item = group.addItem("Random.Real5");
|
||||
|
||||
Map<String, Item> items = group.addItems("Random.Real1",
|
||||
"Random.Real2", "Random.Real3", "Random.Real4");
|
||||
|
||||
dumpItem(item);
|
||||
|
||||
for (Entry<String, Item> temp : items.entrySet()) {
|
||||
dumpItem(temp.getValue());
|
||||
}
|
||||
|
||||
server.dispose();
|
||||
}
|
||||
|
||||
private static void dumpItem(Item item) throws JIException {
|
||||
System.out.println("[" + (++count) + "],ItemName:[" + item.getId()
|
||||
+ "],value:" + item.read(false).getValue());
|
||||
}
|
||||
|
||||
private static int count;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.freud.opc.utgard.cases;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.openscada.opc.lib.da.AccessBase;
|
||||
import org.openscada.opc.lib.da.DataCallback;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.openscada.opc.lib.da.SyncAccess;
|
||||
|
||||
import com.freud.opc.utgard.BaseConfiguration;
|
||||
|
||||
/**
|
||||
* 异步读取点位的信息,读取某个点的变化值
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class OPCTest4 {
|
||||
|
||||
/** 间隔时间 */
|
||||
private static final int PERIOD = 100;
|
||||
|
||||
/** 休眠时间 */
|
||||
private static final int SLEEP = 2000;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Server server = new Server(
|
||||
BaseConfiguration.getCLSIDConnectionInfomation(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
server.connect();
|
||||
|
||||
/**
|
||||
* 其中100单位为毫秒,为每次从OPC获取刷新的间隔时间
|
||||
*/
|
||||
AccessBase access = new SyncAccess(server, PERIOD);
|
||||
|
||||
/**
|
||||
* 定时每隔间隔时间获取一次值
|
||||
*/
|
||||
access.addItem("Random.Real5", new DataCallback() {
|
||||
private int i;
|
||||
|
||||
public void changed(Item item, ItemState itemstate) {
|
||||
System.out.println("[" + (++i) + "],ItemName:[" + item.getId()
|
||||
+ "],value:" + itemstate.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
/** 开始监听 */
|
||||
access.bind();
|
||||
|
||||
/** 当前线程休眠时间单位:毫秒 */
|
||||
Thread.sleep(SLEEP);
|
||||
/** 监听 结束 */
|
||||
access.unbind();
|
||||
|
||||
server.dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package com.freud.opc.utgard.cases;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.openscada.opc.lib.da.AccessBase;
|
||||
import org.openscada.opc.lib.da.Async20Access;
|
||||
import org.openscada.opc.lib.da.DataCallback;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
import com.freud.opc.utgard.BaseConfiguration;
|
||||
|
||||
/**
|
||||
* 异步Access,订阅读取点位的值,并且只有值有变化的时候才会触发CallBack函数
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class OPCTest5 {
|
||||
|
||||
/** 间隔时间 */
|
||||
private static final int PERIOD = 100;
|
||||
|
||||
/** 休眠时间 */
|
||||
private static final int SLEEP = 2000;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Server server = new Server(
|
||||
BaseConfiguration.getCLSIDConnectionInfomation(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
server.connect();
|
||||
|
||||
/**
|
||||
* 其中100单位为毫秒,为每次从OPC获取刷新的间隔时间
|
||||
*/
|
||||
AccessBase access = new Async20Access(server, PERIOD, false);
|
||||
|
||||
/**
|
||||
* 只有Item的值有变化的时候才会触发CallBack函数
|
||||
*/
|
||||
access.addItem("Random.Real5", new DataCallback() {
|
||||
|
||||
private int count;
|
||||
|
||||
public void changed(Item item, ItemState itemstate) {
|
||||
System.out.println("[" + (++count) + "],ItemName:["
|
||||
+ item.getId() + "],value:" + itemstate.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
/** 开始监听 */
|
||||
access.bind();
|
||||
|
||||
/** 当前线程休眠时间单位:毫秒 */
|
||||
Thread.sleep(SLEEP);
|
||||
/** 监听 结束 */
|
||||
access.unbind();
|
||||
|
||||
server.dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.freud.opc.utgard.cases;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.openscada.opc.lib.da.AccessBase;
|
||||
import org.openscada.opc.lib.da.AutoReconnectController;
|
||||
import org.openscada.opc.lib.da.DataCallback;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.openscada.opc.lib.da.SyncAccess;
|
||||
|
||||
import com.freud.opc.utgard.BaseConfiguration;
|
||||
|
||||
/**
|
||||
* 如果Connection Break掉了,会自动重新连接
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class OPCTest6 {
|
||||
|
||||
/** 间隔时间 */
|
||||
private static final int PERIOD = 100;
|
||||
|
||||
/** 休眠时间 */
|
||||
private static final int SLEEP = 2000;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Server server = new Server(
|
||||
BaseConfiguration.getCLSIDConnectionInfomation(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
AutoReconnectController controller = new AutoReconnectController(server);
|
||||
|
||||
controller.connect();
|
||||
|
||||
/**
|
||||
* 其中100单位为毫秒,为每次从OPC获取刷新的间隔时间
|
||||
*/
|
||||
AccessBase access = new SyncAccess(server, PERIOD);
|
||||
|
||||
/**
|
||||
* 定时每隔间隔时间获取一次值
|
||||
*/
|
||||
access.addItem("Random.Real5", new DataCallback() {
|
||||
private int i;
|
||||
|
||||
public void changed(Item item, ItemState itemstate) {
|
||||
System.out.println("[" + (++i) + "],ItemName:[" + item.getId()
|
||||
+ "],value:" + itemstate.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
/** 开始监听 */
|
||||
access.bind();
|
||||
|
||||
/** 当前线程休眠时间单位:毫秒 */
|
||||
Thread.sleep(SLEEP);
|
||||
/** 监听结束 */
|
||||
access.unbind();
|
||||
|
||||
controller.disconnect();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.freud.opc.utgard.cases;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.core.JIArray;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
import com.freud.opc.utgard.BaseConfiguration;
|
||||
|
||||
/**
|
||||
* 同步写入某个点位的值
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
public class OPCTest7 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Server server = new Server(
|
||||
BaseConfiguration.getCLSIDConnectionInfomation(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
server.connect();
|
||||
|
||||
Group group = server.addGroup();
|
||||
Item item = group.addItem("Square Waves.Real4");
|
||||
|
||||
/** 构造写入数据 */
|
||||
final Float[] integerData = new Float[] { 1202f, 1203f, 1204f };
|
||||
final JIArray array = new JIArray(integerData, false);
|
||||
final JIVariant value = new JIVariant(array);
|
||||
|
||||
/** 同步写入 */
|
||||
item.write(value);
|
||||
Thread.sleep(2000);
|
||||
|
||||
/** Dump出item的值 */
|
||||
dumpItem(item);
|
||||
|
||||
server.dispose();
|
||||
|
||||
}
|
||||
|
||||
private static void dumpItem(Item item) throws JIException {
|
||||
System.out.println("[" + (++count) + "],ItemName:[" + item.getId()
|
||||
+ "],value:" + item.read(true).getValue());
|
||||
}
|
||||
|
||||
private static int count;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.freud.opc.utgard.cases;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.core.JIArray;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
import com.freud.opc.utgard.BaseConfiguration;
|
||||
|
||||
/**
|
||||
* 异步写入
|
||||
*
|
||||
* @author Freud
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class OPCTest8 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
final Server server = new Server(
|
||||
BaseConfiguration.getCLSIDConnectionInfomation(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
server.connect();
|
||||
|
||||
/** 构造写入数据 */
|
||||
final Float[] integerData = new Float[] { 1202f, 1203f, 1204f };
|
||||
final JIArray array = new JIArray(integerData, false);
|
||||
final JIVariant value = new JIVariant(array);
|
||||
|
||||
final Item item = server.addGroup().addItem("Square Waves.Real4");
|
||||
|
||||
/** 同步写入 */
|
||||
item.write(value);
|
||||
Thread.sleep(2000);
|
||||
|
||||
/** Dump出item的值 */
|
||||
dumpItem(item);
|
||||
|
||||
server.dispose();
|
||||
|
||||
}
|
||||
|
||||
private static void dumpItem(Item item) throws JIException {
|
||||
System.out.println("[" + (++count) + "],ItemName:[" + item.getId()
|
||||
+ "],value:" + item.read(true).getValue());
|
||||
}
|
||||
|
||||
private static int count;
|
||||
}
|
||||
@@ -0,0 +1,927 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Beijing Shuto Technology Co,. Ltd. All rights reserved.
|
||||
*/
|
||||
|
||||
package org.jinterop.dcom.core;
|
||||
|
||||
import org.jinterop.dcom.common.*;
|
||||
import org.jinterop.dcom.impls.JIObjectFactory;
|
||||
import org.jinterop.dcom.impls.automation.IJIDispatch;
|
||||
import org.jinterop.dcom.transport.JIComEndpoint;
|
||||
import org.jinterop.dcom.transport.JIComTransportFactory;
|
||||
import org.jinterop.winreg.IJIWinReg;
|
||||
import org.jinterop.winreg.JIPolicyHandle;
|
||||
import org.jinterop.winreg.JIWinRegFactory;
|
||||
import rpc.Endpoint;
|
||||
import rpc.FaultException;
|
||||
import rpc.Stub;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
/** Startup class representing a COM Server.
|
||||
* <p>
|
||||
* Sample Usage :-
|
||||
* <br>
|
||||
* <code>
|
||||
*
|
||||
* {@link JISession} session = JISession.createSession("DOMAIN","USERNAME","PASSWORD"); <br>
|
||||
* JIComServer excelServer = new JIComServer(JIProgId.valueOf("Excel.Application"),address,session); <br>
|
||||
* IJIComObject comObject = excelServer.createInstance(); <br>
|
||||
* //Obtaining the IJIDispatch (if supported) <br>
|
||||
* {@link IJIDispatch} dispatch = (IJIDispatch){@link JIObjectFactory}.narrowObject(comObject.queryInterface(IJIDispatch.IID)); <br>
|
||||
* </code>
|
||||
*
|
||||
* <p>Each instance of this class is associated with a single session only.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public final class JIComServer extends Stub {
|
||||
|
||||
private static Properties defaults = new Properties();
|
||||
static {
|
||||
|
||||
defaults.put("rpc.ntlm.lanManagerKey","false");
|
||||
defaults.put("rpc.ntlm.sign","false");
|
||||
defaults.put("rpc.ntlm.seal","false");
|
||||
defaults.put("rpc.ntlm.keyExchange","false");
|
||||
defaults.put("rpc.connectionContext","rpc.security.ntlm.NtlmConnectionContext");
|
||||
defaults.put("rpc.socketTimeout", new Integer(0).toString());
|
||||
// rpc.connectionContext = rpc.security.ntlm.NtlmConnectionContext
|
||||
// rpc.ntlm.sign = false
|
||||
// rpc.ntlm.seal = false
|
||||
// rpc.ntlm.keyExchange = false
|
||||
|
||||
}
|
||||
|
||||
//private String address = null;
|
||||
private JIRemActivation remoteActivation = null;
|
||||
private JIOxidResolver oxidResolver = null;
|
||||
private String clsid = null;
|
||||
private String syntax = null;
|
||||
private JISession session = null;
|
||||
private boolean serverInstantiated = false;
|
||||
private String remunknownIPID = null;
|
||||
private final Object mutex = new Object();
|
||||
private boolean timeoutModifiedfrom0 = false;
|
||||
private JIInterfacePointer interfacePtrCtor = null;
|
||||
|
||||
private JIComServer(){}
|
||||
|
||||
/**<p> Instantiates a JIComServer represented by the interfacePointer param. There are cases where a COM server may hand down a
|
||||
* reference to a different COM server(which may or may not be on the same machine) and we would like to hook in between.
|
||||
* The <code>IJIComObject</code> interface is usable only in the context of the current JIComServer, but when the interfacePointer
|
||||
* is of a completely different COM server, the JIObjectFactory APIs will not work. The reason is the interface pointer passed to those
|
||||
* APIs expects to belong only to a single and same COM server (say 'A'). If by any chance, that COM server passes a reference to you
|
||||
* of another COM server (say 'B') on a different machine, the <code>IJIComObject</code> so returned from <code>JIObjectFactory</code> APIs
|
||||
* will result in "Method not found" Exceptions (or others) since the pointer returned via that will always place calls to 'A' instead of 'B'.
|
||||
* Under such scenarios you must use this API. This is not a usual case and for reasons related to nature of DCOM, will be very well documented
|
||||
* in the Developers guide of your COM server.
|
||||
*
|
||||
* <p>The DCOM specs refer to this as the "middleman" case. (Section 3.3.1) </p>
|
||||
* </p>
|
||||
* @param session Please use a new session and not an already bounded one. The <code>JISession.createSession(JISession)</code> can be used to create a new session.
|
||||
* @param interfacePointer reference to a different COM server pointer.
|
||||
* @param ipAddress Can be <code>null</code>. Sometimes there are many adapters (virtual as well) on the Target machine to which this interface pointer belongs,
|
||||
* which may get sent as part of the interface pointer and consequently this call will fail since it is a possibility that IP is not reachable via this machine.
|
||||
* The developer can send in the valid IP and if found in the interface pointer list will be used to talk to the target machine, overriding the other IP addresses present in the interface pointer.
|
||||
* If this IP is not found then the "machine name" binding will be used. If this param is <code>null</code> then the first binding obtained from the interface pointer is used.
|
||||
*/
|
||||
JIComServer(JISession session, JIInterfacePointer interfacePointer,String ipAddress) throws JIException
|
||||
{
|
||||
super();
|
||||
|
||||
if (interfacePointer == null || session == null)
|
||||
{
|
||||
throw new IllegalArgumentException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_ILLEGAL_ARGUMENTS));
|
||||
}
|
||||
|
||||
if (session.getStub() != null)
|
||||
{
|
||||
throw new JIException(JIErrorCodes.JI_SESSION_ALREADY_ESTABLISHED);
|
||||
}
|
||||
|
||||
if (JISystem.getLogger().isLoggable(Level.INFO))
|
||||
{
|
||||
JISystem.internal_dumpMap();
|
||||
}
|
||||
|
||||
super.setTransportFactory(JIComTransportFactory.getSingleTon());
|
||||
//now read the session and prepare information for the stub.
|
||||
super.setProperties(new Properties(defaults));
|
||||
super.getProperties().setProperty("rpc.security.username", session.getUserName());
|
||||
super.getProperties().setProperty("rpc.security.password", session.getPassword());
|
||||
super.getProperties().setProperty("rpc.ntlm.domain", session.getDomain());
|
||||
super.getProperties().setProperty("rpc.socketTimeout", new Integer(session.getGlobalSocketTimeout()).toString());
|
||||
|
||||
JIStringBinding[] addressBindings = interfacePointer.getStringBindings().getStringBindings();
|
||||
|
||||
int i = 0;
|
||||
JIStringBinding binding = null;
|
||||
JIStringBinding nameBinding = null;
|
||||
String targetAddress = ipAddress == null ? "" : ipAddress.trim();
|
||||
|
||||
// if (!targetAddress.equals(""))
|
||||
{
|
||||
//now we choose, otherwise the first one we get.
|
||||
while(i < addressBindings.length)
|
||||
{
|
||||
binding = addressBindings[i];
|
||||
if (binding.getTowerId() != 0x07) //this means, even though I asked for TCPIP something else was supplied, noticed this in win2k.
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
//get the one with IP address
|
||||
int index = binding.getNetworkAddress().indexOf(".");
|
||||
if (index != -1)
|
||||
{
|
||||
try{
|
||||
|
||||
if (binding.getNetworkAddress().equalsIgnoreCase(targetAddress))
|
||||
{
|
||||
nameBinding = null;
|
||||
break;
|
||||
}
|
||||
|
||||
//now check for the one with port
|
||||
index = binding.getNetworkAddress().indexOf("[");//this contains the port
|
||||
if (index != -1 && binding.getNetworkAddress().substring(0,index).equalsIgnoreCase(targetAddress))
|
||||
{
|
||||
nameBinding = null;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}catch(NumberFormatException e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//can only come for the name, saving it incase nothing matches the target address
|
||||
nameBinding = binding;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
binding = nameBinding == null ? binding : nameBinding;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// //Just pick up the first one.
|
||||
// binding = addressBindings[0];
|
||||
// }
|
||||
|
||||
|
||||
//will use this last binding .
|
||||
//and currently only TCPIP is supported.
|
||||
String address = binding.getNetworkAddress();
|
||||
if (address.indexOf("[") == -1 )//this does not contain the port
|
||||
{
|
||||
String ipAddr = JISystem.getIPForHostName(address); //to use the binding supplied by the user.
|
||||
if (ipAddr != null)
|
||||
{
|
||||
address = ipAddr;
|
||||
}
|
||||
//use 135
|
||||
address = address + "[135]";
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = address.indexOf("[");
|
||||
String hostname = binding.getNetworkAddress().substring(0,index);
|
||||
String ipAddr = JISystem.getIPForHostName(hostname); //to use the binding supplied by the user.
|
||||
if (ipAddr != null)
|
||||
{
|
||||
address = ipAddr + address.substring(index);
|
||||
}
|
||||
}
|
||||
super.setAddress("ncacn_ip_tcp:" + address);
|
||||
this.session = session;
|
||||
this.session.setTargetServer(getAddress().substring(getAddress().indexOf(":") + 1,getAddress().indexOf("[")));
|
||||
oxidResolver = new JIOxidResolver(((JIStdObjRef)interfacePointer.getObjectReference(JIInterfacePointer.OBJREF_STANDARD)).getOxid());
|
||||
try {
|
||||
|
||||
syntax = "99fcfec4-5260-101b-bbcb-00aa0021347a:0.0";
|
||||
attach();
|
||||
//first send an AlterContext to the IID of the IOxidResolver
|
||||
getEndpoint().getSyntax().setUuid(new rpc.core.UUID("99fcfec4-5260-101b-bbcb-00aa0021347a"));
|
||||
getEndpoint().getSyntax().setVersion(0,0);
|
||||
((JIComEndpoint)getEndpoint()).rebindEndPoint();
|
||||
|
||||
call(Endpoint.IDEMPOTENT,oxidResolver);
|
||||
}catch(FaultException e)
|
||||
{
|
||||
throw new JIException(e.status,e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
|
||||
}catch (JIRuntimeException e1)
|
||||
{
|
||||
throw new JIException(e1);
|
||||
}
|
||||
|
||||
// Now will setup syntax for IRemUnknown and the address.
|
||||
//syntax = "00000143-0000-0000-c000-000000000046:0.0";
|
||||
syntax = interfacePointer.getIID() + ":0.0";
|
||||
|
||||
//now for the new ip and the port.
|
||||
|
||||
JIStringBinding[] bindings = oxidResolver.getOxidBindings().getStringBindings();
|
||||
|
||||
binding = null;
|
||||
nameBinding = null;
|
||||
i = 0;
|
||||
// if (!targetAddress.equals(""))
|
||||
{
|
||||
//now we choose, otherwise the first one we get.
|
||||
while(i < bindings.length)
|
||||
{
|
||||
binding = bindings[i];
|
||||
if (binding.getTowerId() != 0x07) //this means, even though I asked for TCPIP something else was supplied, noticed this in win2k.
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
//get the one with IP address
|
||||
int index = binding.getNetworkAddress().indexOf(".");
|
||||
if (index != -1)
|
||||
{
|
||||
try{
|
||||
|
||||
if (binding.getNetworkAddress().equalsIgnoreCase(targetAddress))
|
||||
{
|
||||
nameBinding = null;
|
||||
break;
|
||||
}
|
||||
|
||||
//now check for the one with port
|
||||
index = binding.getNetworkAddress().indexOf("[");//this contains the port
|
||||
if (index != -1 && binding.getNetworkAddress().substring(0,index).equalsIgnoreCase(targetAddress))
|
||||
{
|
||||
nameBinding = null;
|
||||
break;
|
||||
}
|
||||
}catch(NumberFormatException e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//can only come for the name, saving it incase nothing matches the target address
|
||||
nameBinding = binding;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
binding = nameBinding == null ? binding : nameBinding;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// //Just pick up the first one.
|
||||
// binding = bindings[0];
|
||||
// }
|
||||
|
||||
|
||||
//now set the NTLMv2 Session Security.
|
||||
if (session.isSessionSecurityEnabled())
|
||||
{
|
||||
super.getProperties().setProperty("rpc.ntlm.seal", "true");
|
||||
super.getProperties().setProperty("rpc.ntlm.sign", "true");
|
||||
super.getProperties().setProperty("rpc.ntlm.keyExchange", "true");
|
||||
super.getProperties().setProperty("rpc.ntlm.keyLength", "128");
|
||||
super.getProperties().setProperty("rpc.ntlm.ntlm2", "true");
|
||||
}
|
||||
|
||||
address = binding.getNetworkAddress(); //this will always have the port.
|
||||
int index = address.indexOf("[");
|
||||
String hostname = binding.getNetworkAddress().substring(0,index);
|
||||
String ipAddr = JISystem.getIPForHostName(hostname); //to use the binding supplied by the user.
|
||||
if (ipAddr != null)
|
||||
{
|
||||
address = ipAddr + address.substring(index);
|
||||
}
|
||||
|
||||
//and currently only TCPIP is supported.
|
||||
setAddress("ncacn_ip_tcp:" + address);
|
||||
remunknownIPID = oxidResolver.getIPID();
|
||||
interfacePtrCtor = interfacePointer;
|
||||
this.session.setStub(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**<p><code>JIProgId</code> based constructor with the host machine for COM server being <i>LOCALHOST</i>.
|
||||
*
|
||||
* @param progId user-friendly string such as "Excel.Application" , "TestCOMServer.Test123" etc.
|
||||
* @param session session to be associated with.
|
||||
* @throws JIException will <i>also</i> get thrown in case the <code>session</code> is associated with another server already.
|
||||
* @throws IllegalArgumentException raised when either <code>progId</code> or <code>session</code> is <code>null</code>.
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
public JIComServer(JIProgId progId,JISession session) throws JIException, UnknownHostException
|
||||
{
|
||||
this(progId,InetAddress.getLocalHost().getHostAddress(),session);
|
||||
}
|
||||
|
||||
/** <p><code>{@link JIClsid}</code> based constructor with the host machine for COM server being <i>LOCALHOST</i>.
|
||||
*
|
||||
* @param clsid 128 bit string such as "00024500-0000-0000-C000-000000000046".
|
||||
* @param session session to be associated with.
|
||||
* @throws JIException will <i>also</i> get thrown in case the <code>session</code> is associated with another server already.
|
||||
* @throws IllegalArgumentException raised when either <code>clsid</code> or <code>session</code> is <code>null</code>.
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
public JIComServer(JIClsid clsid,JISession session) throws IllegalArgumentException,JIException, UnknownHostException
|
||||
{
|
||||
this(clsid,InetAddress.getLocalHost().getHostAddress(),session);
|
||||
}
|
||||
|
||||
/**<p>Refer {@link #JIComServer(JIProgId, JISession)} for details.
|
||||
*
|
||||
* @param progId user-friendly string such as "Excel.Application" , "TestCOMServer.Test123" etc.
|
||||
* @param address address of the host where the <code>COM</code> object resides.This should be in the IEEE IP format (e.g. 192.168.170.6) or a resolvable HostName.
|
||||
* @param session session to be associated with.
|
||||
* @throws JIException will <i>also</i> get thrown in case the <code>session</code> is associated with another server already.
|
||||
* @throws IllegalArgumentException raised when any of the parameters is <code>null</code>.
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
public JIComServer(JIProgId progId,String address, JISession session) throws JIException, UnknownHostException
|
||||
{
|
||||
super();
|
||||
|
||||
if (progId == null || address == null || session == null)
|
||||
{
|
||||
throw new IllegalArgumentException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_ILLEGAL_ARGUMENTS));
|
||||
}
|
||||
|
||||
if (session.getStub() != null)
|
||||
{
|
||||
throw new JIException(JIErrorCodes.JI_SESSION_ALREADY_ESTABLISHED);
|
||||
}
|
||||
|
||||
address = address.trim();
|
||||
address = InetAddress.getByName(address).getHostAddress();
|
||||
|
||||
progId.setSession(session);
|
||||
progId.setServer(address);
|
||||
address = "ncacn_ip_tcp:"+address+"[135]";
|
||||
JIClsid clsid = progId.getCorrespondingCLSID();
|
||||
initialise(clsid,address,session);
|
||||
}
|
||||
|
||||
/** <p>Refer {@link #JIComServer(JIClsid, JISession)} for details.
|
||||
*
|
||||
*
|
||||
* @param clsid 128 bit string such as "00024500-0000-0000-C000-000000000046".
|
||||
* @param address address of the host where the <code>COM</code> object resides.This should be in the IEEE IP format (e.g. 192.168.170.6) or a resolvable HostName.
|
||||
* @param session session to be associated with.
|
||||
* @throws JIException will <i>also</i> get thrown in case the <code>session</code> is associated with another server already.
|
||||
* @throws IllegalArgumentException raised when any of the parameters is <code>null</code>.
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
public JIComServer(JIClsid clsid,String address, JISession session) throws JIException, UnknownHostException
|
||||
{
|
||||
super();
|
||||
|
||||
if (clsid == null || address == null || session == null)
|
||||
{
|
||||
throw new IllegalArgumentException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_ILLEGAL_ARGUMENTS));
|
||||
}
|
||||
|
||||
if (session.getStub() != null)
|
||||
{
|
||||
throw new JIException(JIErrorCodes.JI_SESSION_ALREADY_ESTABLISHED);
|
||||
}
|
||||
|
||||
if(address.indexOf('[') < 0) {
|
||||
address = address.trim();
|
||||
//address = address.replace(' ','');
|
||||
address = "ncacn_ip_tcp:" + InetAddress.getByName(address).getHostAddress() + "[135]";
|
||||
} else {
|
||||
address = "ncacn_ip_tcp:" + address;
|
||||
}
|
||||
System.out.println("clsid = " + clsid + ", address = " + address + ", session = " + session);
|
||||
initialise(clsid,address,session);
|
||||
}
|
||||
|
||||
private void initialise(JIClsid clsid,String address, JISession session) throws JIException
|
||||
{
|
||||
super.setTransportFactory(JIComTransportFactory.getSingleTon());
|
||||
//now read the session and prepare information for the stub.
|
||||
super.setProperties(new Properties(defaults));
|
||||
super.getProperties().setProperty("rpc.security.username", session.getUserName());
|
||||
super.getProperties().setProperty("rpc.security.password", session.getPassword());
|
||||
super.getProperties().setProperty("rpc.ntlm.domain", session.getDomain());
|
||||
super.getProperties().setProperty("rpc.socketTimeout", new Integer(session.getGlobalSocketTimeout()).toString());
|
||||
super.setAddress(address);
|
||||
// if (session.isSessionSecurityEnabled())
|
||||
// {
|
||||
// super.getProperties().setProperty("rpc.ntlm.seal", "true");
|
||||
// super.getProperties().setProperty("rpc.ntlm.sign", "true");
|
||||
// super.getProperties().setProperty("rpc.ntlm.keyExchange", "true");
|
||||
// super.getProperties().setProperty("rpc.ntlm.keyLength", "128");
|
||||
// super.getProperties().setProperty("rpc.ntlm.ntlm2", "true");
|
||||
// }
|
||||
|
||||
if (JISystem.getLogger().isLoggable(Level.INFO))
|
||||
{
|
||||
JISystem.internal_dumpMap();
|
||||
}
|
||||
|
||||
this.clsid = clsid.getCLSID().toUpperCase();
|
||||
this.session = session;
|
||||
this.session.setTargetServer(address.substring(address.indexOf(":") + 1,address.indexOf("[")));
|
||||
try{
|
||||
init();
|
||||
}catch(JIException e)
|
||||
{
|
||||
if (e.getErrorCode() == 0x80040154)
|
||||
{
|
||||
if (JISystem.getLogger().isLoggable(Level.WARNING))
|
||||
{
|
||||
JISystem.getLogger().warning("Got the class not registered exception , will attempt setting entries based on status flags...");
|
||||
}
|
||||
//try registering the dll\ocx on our own
|
||||
//check for clsid.autoregister flag
|
||||
//check for jisystem.autoregister flag.
|
||||
//jisystem takes precedence over clsid.
|
||||
|
||||
if (JISystem.isAutoRegistrationSet() || clsid.isAutoRegistrationSet())
|
||||
{
|
||||
|
||||
//first create the registry entries.
|
||||
try {
|
||||
IJIWinReg registry = null;
|
||||
registry = JIWinRegFactory.getSingleTon().getWinreg(new JIDefaultAuthInfoImpl(session.getDomain(),session.getUserName(),session.getPassword()),session.getTargetServer(),true);
|
||||
JIPolicyHandle hkcr = registry.winreg_OpenHKCR();
|
||||
JIPolicyHandle key = registry.winreg_CreateKey(hkcr,"CLSID\\{" + this.clsid + "}",IJIWinReg.REG_OPTION_NON_VOLATILE,IJIWinReg.KEY_ALL_ACCESS );
|
||||
registry.winreg_SetValue(key,"AppID",("{" + this.clsid + "}").getBytes(),false,false);
|
||||
registry.winreg_CloseKey(key);
|
||||
key = registry.winreg_CreateKey(hkcr,"AppID\\{" + this.clsid + "}",IJIWinReg.REG_OPTION_NON_VOLATILE,IJIWinReg.KEY_ALL_ACCESS );
|
||||
registry.winreg_SetValue(key,"DllSurrogate"," ".getBytes(),false,false);
|
||||
registry.winreg_CloseKey(key);
|
||||
registry.winreg_CloseKey(hkcr);
|
||||
registry.closeConnection();
|
||||
} catch (UnknownHostException e1) {
|
||||
//auto registration failed as well...
|
||||
JISystem.getLogger().throwing("JIComServer","initialise",e1);
|
||||
throw new JIException(JIErrorCodes.JI_WINREG_EXCEPTION3,e1);
|
||||
}
|
||||
//lets retry
|
||||
init();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.session.setStub(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void init () throws JIException
|
||||
{
|
||||
if (remoteActivation != null && remoteActivation.isActivationSuccessful())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boolean attachcomplete = false;
|
||||
try {
|
||||
syntax = "99fcfec4-5260-101b-bbcb-00aa0021347a:0.0";
|
||||
attach();
|
||||
// socket to COM server is established
|
||||
attachcomplete = true;
|
||||
//first send an AlterContext to the IID of the IOxidResolver
|
||||
getEndpoint().getSyntax().setUuid(new rpc.core.UUID("99fcfec4-5260-101b-bbcb-00aa0021347a"));
|
||||
getEndpoint().getSyntax().setVersion(0,0);
|
||||
((JIComEndpoint)getEndpoint()).rebindEndPoint();
|
||||
|
||||
//setup syntax for IRemoteActivation
|
||||
syntax = "4d9f4ab8-7d1c-11cf-861e-0020af6e7c57:0.0";
|
||||
getEndpoint().getSyntax().setUuid(new rpc.core.UUID("4d9f4ab8-7d1c-11cf-861e-0020af6e7c57"));
|
||||
getEndpoint().getSyntax().setVersion(0,0);
|
||||
((JIComEndpoint)getEndpoint()).rebindEndPoint();
|
||||
|
||||
remoteActivation = new JIRemActivation(clsid);
|
||||
call(Endpoint.IDEMPOTENT,remoteActivation);
|
||||
}catch(FaultException e)
|
||||
{
|
||||
remoteActivation = null;
|
||||
throw new JIException(e.status,e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
remoteActivation = null;
|
||||
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
|
||||
}catch (JIRuntimeException e1)
|
||||
{
|
||||
remoteActivation = null;
|
||||
throw new JIException(e1);
|
||||
}
|
||||
finally
|
||||
{
|
||||
//the only time remactivation will be null will be case of an exception.
|
||||
if (attachcomplete && remoteActivation == null)
|
||||
{
|
||||
try {
|
||||
detach();
|
||||
} catch (IOException e) {
|
||||
if (JISystem.getLogger().isLoggable(Level.WARNING))
|
||||
{
|
||||
JISystem.getLogger().warning("Unable to detach during init: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now will setup syntax for IRemUnknown and the address.
|
||||
syntax = "00000143-0000-0000-c000-000000000046:0.0";
|
||||
//now for the new ip and the port.
|
||||
|
||||
JIStringBinding[] bindings = remoteActivation.getDualStringArrayForOxid().getStringBindings();
|
||||
int i = 0;
|
||||
JIStringBinding binding = null;
|
||||
JIStringBinding nameBinding = null;
|
||||
String targetAddress = getAddress();
|
||||
targetAddress = targetAddress.substring(targetAddress.indexOf(':') + 1,targetAddress.indexOf('['));
|
||||
while(i < bindings.length)
|
||||
{
|
||||
binding = bindings[i];
|
||||
if (binding.getTowerId() != 0x07) //this means, even though I asked for TCPIP something else was supplied, noticed this in win2k.
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
//get the one with IP address
|
||||
int index = binding.getNetworkAddress().indexOf(".");
|
||||
if (index != -1)
|
||||
{
|
||||
try{
|
||||
//Integer.parseInt(binding.getNetworkAddress().substring(0,index));
|
||||
index = binding.getNetworkAddress().indexOf("[");//this contains the port
|
||||
if (index != -1 && binding.getNetworkAddress().substring(0,index).equalsIgnoreCase(targetAddress))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}catch(NumberFormatException e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//can only come for the name, saving it incase nothing matches the target address
|
||||
//then we are not sure which is the right IP and which might be virtual, refer to
|
||||
//issue faced by Igor.
|
||||
nameBinding = binding;
|
||||
index = binding.getNetworkAddress().indexOf("[");//this contains the port
|
||||
if (binding.getNetworkAddress().substring(0,index).equalsIgnoreCase(targetAddress))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (binding == null)
|
||||
{
|
||||
binding = nameBinding;
|
||||
}
|
||||
//will use this last binding .
|
||||
//and currently only TCPIP is supported.
|
||||
//now set the NTLMv2 Session Security.
|
||||
if (session.isSessionSecurityEnabled())
|
||||
{
|
||||
super.getProperties().setProperty("rpc.ntlm.seal", "true");
|
||||
super.getProperties().setProperty("rpc.ntlm.sign", "true");
|
||||
super.getProperties().setProperty("rpc.ntlm.keyExchange", "true");
|
||||
super.getProperties().setProperty("rpc.ntlm.keyLength", "128");
|
||||
super.getProperties().setProperty("rpc.ntlm.ntlm2", "true");
|
||||
}
|
||||
|
||||
String address = binding.getNetworkAddress(); //this will always have the port.
|
||||
int index = address.indexOf("[");
|
||||
String hostname = binding.getNetworkAddress().substring(0,index);
|
||||
String ipAddr = JISystem.getIPForHostName(hostname); //to use the binding supplied by the user.
|
||||
if (ipAddr != null)
|
||||
{
|
||||
address = ipAddr + address.substring(index);
|
||||
}
|
||||
|
||||
//and currently only TCPIP is supported.
|
||||
setAddress("ncacn_ip_tcp:" + address);
|
||||
// setAddress("ncacn_ip_tcp:" + binding.getNetworkAddress());
|
||||
remunknownIPID = remoteActivation.getIPID();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Will give a call to IRemUnknown for the passed IID.
|
||||
IJIComObject getInterface(String iid,String ipidOfTheTargetUnknown) throws JIException
|
||||
{
|
||||
IJIComObject retval = null;
|
||||
//this is still essentially serial, since all threads will have to wait for mutex before
|
||||
//entering addToSession.
|
||||
synchronized (mutex) {
|
||||
//now also set the Object ID for IRemUnknown call this will be the IPID of the returned JIRemActivation
|
||||
setObject(remunknownIPID);
|
||||
//setObject(ipid);
|
||||
|
||||
//JIRemUnknown reqUnknown = new JIRemUnknown(unknownIPID,iid,5);
|
||||
JIRemUnknown reqUnknown = new JIRemUnknown(ipidOfTheTargetUnknown,iid);
|
||||
try {
|
||||
call(Endpoint.IDEMPOTENT,reqUnknown);
|
||||
}catch(FaultException e)
|
||||
{
|
||||
throw new JIException(e.status,e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
|
||||
}catch (JIRuntimeException e1)
|
||||
{
|
||||
//remoteActivation = null;
|
||||
throw new JIException(e1);
|
||||
}
|
||||
|
||||
retval = JIFrameworkHelper.instantiateComObject(session, reqUnknown.getInterfacePointer());
|
||||
//increasing the reference count.
|
||||
retval.addRef();
|
||||
//for querying dispatch we can't send another call
|
||||
if (!iid.equalsIgnoreCase("00020400-0000-0000-c000-000000000046"))
|
||||
{
|
||||
boolean success = true;
|
||||
((JIComObjectImpl)retval).setIsDual(true);
|
||||
//now to check whether it supports IDispatch
|
||||
//IDispatch 00020400-0000-0000-c000-000000000046
|
||||
JIRemUnknown dispatch = new JIRemUnknown(retval.getIpid(),"00020400-0000-0000-c000-000000000046");
|
||||
try {
|
||||
call(Endpoint.IDEMPOTENT,dispatch);
|
||||
}catch(FaultException e)
|
||||
{
|
||||
throw new JIException(e.status,e);
|
||||
}catch (IOException e) {
|
||||
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
|
||||
}catch (JIRuntimeException e1)
|
||||
{
|
||||
//will eat this exception here.
|
||||
((JIComObjectImpl)retval).setIsDual(false);
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
//which means that IDispatch is supported
|
||||
session.releaseRef(dispatch.getInterfacePointer().getIPID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**Returns an <code>IJIComObject</code> representing the COM Server.
|
||||
*
|
||||
* @return
|
||||
* @throws JIException
|
||||
*/
|
||||
public IJIComObject createInstance() throws JIException
|
||||
{
|
||||
if (interfacePtrCtor != null)
|
||||
{
|
||||
throw new IllegalStateException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_WRONGCALLCREATEINSTANCE));
|
||||
}
|
||||
IJIComObject comObject = null;
|
||||
|
||||
//This method is still essentially serial, since all threads will have to stop at mutex and then
|
||||
//go to addToSession after it (since there is no condition).
|
||||
synchronized (mutex) {
|
||||
if (serverInstantiated)
|
||||
{
|
||||
throw new JIException(JIErrorCodes.JI_OBJECT_ALREADY_INSTANTIATED,(Throwable)null);
|
||||
}
|
||||
// JIStdObjRef objRef = (JIStdObjRef)(remoteActivation.getMInterfacePointer().getObjectReference(JIInterfacePointer.OBJREF_STANDARD));
|
||||
// comObject = getObject(objRef.getIpid(),IJIUnknown.IID);
|
||||
comObject = JIFrameworkHelper.instantiateComObject(session, remoteActivation.getMInterfacePointer());
|
||||
if (remoteActivation.isDual)
|
||||
{
|
||||
//IJIComObject comObject2 = getObject(remoteActivation.dispIpid,"00020400-0000-0000-c000-000000000046");
|
||||
//this will get garbage collected and then removed.
|
||||
//session.addToSession(comObject2,remoteActivation.dispOid);
|
||||
session.releaseRef(remoteActivation.dispIpid);
|
||||
remoteActivation.dispIpid = null;
|
||||
((JIComObjectImpl)comObject).setIsDual(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
((JIComObjectImpl)comObject).setIsDual(false);
|
||||
}
|
||||
//increasing the reference count.
|
||||
comObject.addRef();
|
||||
serverInstantiated = true;
|
||||
}
|
||||
|
||||
return comObject;
|
||||
}
|
||||
|
||||
/**Returns a <code>IJIComObject</code> representing the <code>COM</code> Server. To be used only with <code>JIComServer(JISession,JIInterfacePointer,String)</code> ctor,
|
||||
* otherwise use createInstance() instead.
|
||||
*
|
||||
* @return
|
||||
* @throws JIException
|
||||
*/
|
||||
IJIComObject getInstance() throws JIException
|
||||
{
|
||||
if (interfacePtrCtor == null)
|
||||
{
|
||||
throw new IllegalStateException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_WRONGCALLGETINSTANCE));
|
||||
}
|
||||
|
||||
IJIComObject comObject = null;
|
||||
//This method is still essentially serial, since all threads will have to stop at mutex and then
|
||||
//go to addToSession after it (since there is no condition).
|
||||
synchronized (mutex) {
|
||||
if (serverInstantiated)
|
||||
{
|
||||
throw new JIException(JIErrorCodes.JI_OBJECT_ALREADY_INSTANTIATED,(Throwable)null);
|
||||
}
|
||||
|
||||
// JIStdObjRef objRef = (JIStdObjRef)(interfacePtrCtor.getObjectReference(JIInterfacePointer.OBJREF_STANDARD));
|
||||
// comObject = getObject(objRef.getIpid(),interfacePtrCtor.getIID());
|
||||
comObject = JIFrameworkHelper.instantiateComObject(session,interfacePtrCtor);
|
||||
//increasing the reference count.
|
||||
comObject.addRef();
|
||||
serverInstantiated = true;
|
||||
}
|
||||
|
||||
return comObject;
|
||||
}
|
||||
|
||||
|
||||
protected String getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @exclude
|
||||
// * @return
|
||||
// */
|
||||
// String getIpid()
|
||||
// {
|
||||
// if (remoteActivation != null && remoteActivation.isActivationSuccessful())
|
||||
// {
|
||||
// return remoteActivation.getIPID();
|
||||
// }
|
||||
// else
|
||||
// return null;
|
||||
// }
|
||||
|
||||
/** Execute a Method on the COM Interface identified by the IID.
|
||||
*
|
||||
*
|
||||
* @exclude
|
||||
* @param obj
|
||||
* @param targetIID
|
||||
* @return
|
||||
* @throws JIException
|
||||
*/
|
||||
Object[] call(JICallBuilder obj,String targetIID) throws JIException
|
||||
{
|
||||
return call(obj, targetIID, session.getGlobalSocketTimeout());
|
||||
}
|
||||
|
||||
/** Execute a Method on the COM Interface identified by the IID
|
||||
*
|
||||
*
|
||||
* @exclude
|
||||
* @param obj
|
||||
* @param targetIID
|
||||
* @return
|
||||
* @throws JIException
|
||||
*/
|
||||
Object[] call(JICallBuilder obj,String targetIID, int socketTimeout) throws JIException
|
||||
{
|
||||
synchronized (mutex) {
|
||||
|
||||
if (session.isSessionInDestroy() && !obj.fromDestroySession)
|
||||
{
|
||||
throw new JIException(JIErrorCodes.JI_SESSION_DESTROYED);
|
||||
}
|
||||
|
||||
if (socketTimeout != 0)
|
||||
{
|
||||
setSocketTimeOut(socketTimeout);
|
||||
}
|
||||
else //for cases where it was something earlier, but is now being set to 0.
|
||||
{
|
||||
if (timeoutModifiedfrom0)
|
||||
{
|
||||
setSocketTimeOut(socketTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
attach();
|
||||
if (!getEndpoint().getSyntax().getUuid().toString().equalsIgnoreCase(targetIID))
|
||||
{
|
||||
//first send an AlterContext to the IID of the interface
|
||||
getEndpoint().getSyntax().setUuid(new rpc.core.UUID(targetIID));
|
||||
getEndpoint().getSyntax().setVersion(0,0);
|
||||
((JIComEndpoint)getEndpoint()).rebindEndPoint();
|
||||
}
|
||||
|
||||
setObject(obj.getParentIpid());
|
||||
call(Endpoint.IDEMPOTENT,obj);
|
||||
|
||||
}catch(FaultException e)
|
||||
{
|
||||
throw new JIException(e.status,e);
|
||||
}catch (IOException e) {
|
||||
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
|
||||
}catch (JIRuntimeException e1)
|
||||
{
|
||||
throw new JIException(e1);
|
||||
}
|
||||
|
||||
return obj.getResults();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @exclude
|
||||
* @return
|
||||
*/
|
||||
JIInterfacePointer getServerInterfacePointer()
|
||||
{
|
||||
//remoteactivation can be null only incase of OxidResolver ctor getting called.
|
||||
return remoteActivation == null ? interfacePtrCtor : remoteActivation.getMInterfacePointer();
|
||||
}
|
||||
|
||||
void addRef_ReleaseRef(JICallBuilder obj) throws JIException
|
||||
{
|
||||
synchronized (mutex) {
|
||||
|
||||
if (remunknownIPID == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//now also set the Object ID for IRemUnknown call this will be the IPID of the returned JIRemActivation or IOxidResolver
|
||||
obj.setParentIpid(remunknownIPID);
|
||||
obj.attachSession(session);
|
||||
try {
|
||||
call(obj,JIRemUnknown.IID_IUnknown);
|
||||
} catch (JIRuntimeException e1)
|
||||
{
|
||||
throw new JIException(e1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void closeStub()
|
||||
{
|
||||
try {
|
||||
detach();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void setSocketTimeOut(int timeout)
|
||||
{
|
||||
if (timeout == 0)
|
||||
{
|
||||
timeoutModifiedfrom0 = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
timeoutModifiedfrom0 = true;
|
||||
}
|
||||
|
||||
getProperties().setProperty("rpc.socketTimeout", new Integer(timeout).toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
host=10.1.5.123
|
||||
domain=
|
||||
username=Freud
|
||||
password=
|
||||
clsid=F8582CF2-88FB-11D0-B850-00C0F0104305
|
||||
progid=
|
||||
@@ -0,0 +1,7 @@
|
||||
host=192.168.200.248[5150]
|
||||
domain=
|
||||
username=administrator
|
||||
password=befar111
|
||||
clsid=2C44004E-4C35-4b99-91C9-1DF6A623DF27
|
||||
#progid==Kepware.KEPServerEX.V6
|
||||
|
||||
@@ -6,16 +6,6 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.kohsuke.jinterop</groupId>
|
||||
|
||||
@@ -5,16 +5,6 @@
|
||||
<artifactId>org.openscada.opc.dcom</artifactId>
|
||||
<version>0.0.2</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.kohsuke.jinterop</groupId>
|
||||
|
||||
@@ -4,18 +4,13 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openscada.utgard</groupId>
|
||||
<artifactId>org.openscada.opc.lib</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.1.2</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
Reference in New Issue
Block a user