Working with mongodb from Java - java

I have launch mongodb server:
[demas#arch.local.net][~]% mongod --dbpatmongod --dbpath /home/demas/temp/
Mon Apr 19 09:44:18 Mongo DB : starting : pid = 4538 port = 27017 dbpath = /home/demas/temp/ master = 0 slave = 0 32-bit
** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
** see http://blog.mongodb.org/post/137788967/32-bit-limitations for more
Mon Apr 19 09:44:18 db version v1.4.0, pdfile version 4.5
Mon Apr 19 09:44:18 git version: nogitversion
Mon Apr 19 09:44:18 sys info: Linux arch.local.net 2.6.33-ARCH #1 SMP PREEMPT Mon Apr 5 05:57:38 UTC 2010 i686 BOOST_LIB_VERSION=1_41
Mon Apr 19 09:44:18 waiting for connections on port 27017
Mon Apr 19 09:44:18 web admin interface listening on port 28017
I have created documents by console client:
[demas#arch.local.net][~]% mongo
MongoDB shell version: 1.4.0
url: test
connecting to: test
type "help" for help
> db.some.find();
{ "_id" : ObjectId("4bcbef3c3be43e9b7e04ef3d"), "name" : "mongo" }
{ "_id" : ObjectId("4bcbef423be43e9b7e04ef3e"), "x" : 3 }
Now I am trying to work with MongoDb from Java:
import com.mongodb.*;
import java.net.UnknownHostException;
public class test1 {
public static void main(String[] args) {
System.out.println("Start");
try {
Mongo m = new Mongo("localhost", 27017);
DB db = m.getDB("test");
DBCollection coll = db.getCollection("some");
coll.insert(makeDocument(10, "James", "male"));
System.out.println("Finish");
}
catch (UnknownHostException ex) {
ex.printStackTrace();
}
catch (MongoException ex) {
ex.printStackTrace();
}
}
public static BasicDBObject makeDocument(int id, String name, String gender) {
BasicDBObject doc = new BasicDBObject();
doc.put("id", id);
doc.put("name", name);
doc.put("gender", gender);
return doc;
}
}
But execution stops on line coll.insert():
[demas#arch.local.net][~/dev/study/java/mongodb]% javac test1.java
[demas#arch.local.net][~/dev/study/java/mongodb]% java test1
Start
There are not messages from mogodb server regarding accepted connection. Why?

Hm...
If I change the line:
Mongo m = new Mongo("localhost", 27017);
to:
Mongo m = new Mongo();
all works fine.

Check your /etc/hosts file to make sure that localhost resolves to 127.0.0.1.
Typically, it will contain a line like:
127.0.0.1 localhost.localdomain localhost

Try to change localhost to 127.0.0.1. May be it will be ok.

Related

Error in creating remedy ticket using java

i need a Java class to submit tickets to BMC Remedy's but i was getting error could anyone please help me how to resolve that error.
Find the below code:
public class RemedyCreateTicket {
public static void main(String args[]) {
ARServerUser arsServer = new ARServerUser();
Entry args1 = new Entry();
Entry incidentID;
String arForm = "HPD:IncidentInterface_Create";
String arForm1 = "HPD:IncidentInterface";
String IntEntryID = "";
String inciID = "";
try {
//Create Ticket Part
String strLastName = "radadiya";
String strFirstName ="pragnesh";
args1.put(new Integer("1000000076"),new Value("CREATE")); //ticket_action
args1.put(new Integer("1000000018"),new Value(strLastName)); //contact user first_name
args1.put(new Integer("1000000019"),new Value(strFirstName)); //contact user last_name
args1.put(new Integer("7"), new Value("1")); //ticket status
args1.put(new Integer("1000000099"),new Value("3")); //service type
//args1.put(new Integer("1000000163"),new Value("4000")); //impact
args1.put(new Integer("1000000162"),new Value("4000")); //urgency
args1.put(new Integer("1000000000"),new Value("Remedy 7.5 java api test")); //description
args1.put(new Integer("1000000215"),new Value("10000"));
arsServer.setServer("localhost");
arsServer.setUser("pragnesh");
arsServer.setPassword("password");
arsServer.setPort(3389);
arsServer.login();
//arsServer.setPort(3389);
IntEntryID = arsServer.createEntry(arForm, args1);
System.out.println("intEntryID="+IntEntryID);
int[] entryField = {1000000161};
incidentID = arsServer.getEntry(arForm,IntEntryID,entryField);
if(incidentID!=null){
System.out.println(incidentID);
}
System.out.println("------------");
for (Object o : incidentID.entrySet()) {
Map.Entry e = (Map.Entry) o;
System.out.println(e.getKey() + " => " + e.getValue().getClass() + " " + e.getValue());
if(e.getKey().toString().equalsIgnoreCase("1000000161")){
inciID=e.getValue().toString();
}
}
System.out.println("IncidentID = " + inciID);
arsServer.logout();
} catch (ARException e) {
e.printStackTrace();
arsServer.logout();
}
}
}
Here is the stacktrace:
Jun 20, 2017 4:11:55 PM java.util.prefs.WindowsPreferences openKey
WARNING: Could not open windows registry node Software\JavaSoft\Prefs at root 0x80000002. Windows RegOpenKey(...) returned error code 2.
Jun 20, 2017 4:11:55 PM java.util.prefs.WindowsPreferences closeKey
WARNING: Could not close windows registry node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCloseKey(...) returned error code 6.
**ERROR (91): RPC call failed; localhost:3389 Connection reset**
at com.bmc.arsys.apitransport.ApiProxyJRpcBase.convertException(ApiProxyJRpcBase.java:643)
at com.bmc.arsys.api.ProxyJRpc.getRpcClient(ProxyJRpc.java:135)
at com.bmc.arsys.api.ProxyJRpc.<init>(ProxyJRpc.java:67)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.bmc.arsys.apitransport.connection.ApiProxyFactory.createProxyInstance(ApiProxyFactory.java:89)
at com.bmc.arsys.apitransport.connection.ApiProxyFactory.createProxy(ApiProxyFactory.java:160)
at com.bmc.arsys.api.ProxyManager.createProxy(ProxyManager.java:602)
at com.bmc.arsys.api.ProxyPool.createProxy(ProxyPool.java:106)
at com.bmc.arsys.apitransport.connection.ApiProxyPool.get(ApiProxyPool.java:192)
at com.bmc.arsys.apitransport.connection.ApiProxyManager.getProxy(ApiProxyManager.java:210)
at com.bmc.arsys.api.PoolingProxyManager.getProxy(PoolingProxyManager.java:93)
at com.bmc.arsys.apitransport.connection.ApiProxyManager.getProxy(ApiProxyManager.java:164)
at com.bmc.arsys.api.ARServerUser.verifyUser(ARServerUser.java:1085)
at com.bmc.arsys.api.ARServerUser.login(ARServerUser.java:412)
at Remedi.RemedyCreateTicket.main(RemedyCreateTicket.java:46)
Thanks in advance.
This is old but for anyone looking at it after; the code looks fine. ARERROR 91 is typically a networking issue. Port 3389 is the default for Remote Desktop. Therefore, I wonder if you are tunneling to localhost and trying to connect to the Windows machine that you RDP to? Instead of the TCP port the AR Server is actually running on and let in through the Windows firewall?

Esper rules for different users

I recently started programming with Esper and I have a smart wearable that sends pedometer data to my laptop. I then process this data using esper. But suppose I have multiple smart wearables with each an unique MAC address. I use time windows and my question is how can I change my rule file so that the rules only fire for events with the same macaddress and take appropiate action based on this MAC address. My initialization and rule are:
Configuration cepConfig = new Configuration();
cepConfig.addEventType("Steps", Steps.class.getName());
// We setup the engine
EPServiceProvider cep = EPServiceProviderManager.getProvider("myCEPEngine", cepConfig);
EPRuntime cepRT = cep.getEPRuntime();
// We register an EPL statement
EPAdministrator cepSteps1 = cep.getEPAdministrator();
EPStatement cepStatementSteps1 = cepSteps1.createEPL("select * from "
+ "Steps().win:time(1 hour) "
+ "group by macAddress "
+ "having sum(max(steps)-min(steps)) < 100");
cepStatementSteps1.addListener(new rule1Listener());
My Steps class has the following fields:
double steps;
String stepsTimestamp;
String macAddress;
And this is how I insert the events:
Steps steps0 = new Steps(0, new Date(timeStamp).toString(), "K5E45H778");
cepRT.sendEvent(steps0);
Steps steps00 = new Steps(0, new Date(timeStamp).toString(), "LD24ESF74");
cepRT.sendEvent(steps00);
Steps steps1 = new Steps(25, new Date(timeStamp).toString(), "K5E45H778");
cepRT.sendEvent(steps1);
Steps steps2 = new Steps(50, new Date(timeStamp).toString(), "LD24ESF74");
cepRT.sendEvent(steps2);
Steps steps3 = new Steps(55, new Date(timeStamp).toString(), "K5E45H778");
cepRT.sendEvent(steps3);
Steps steps4 = new Steps(105, new Date(timeStamp).toString(), "LD24ESF74");
cepRT.sendEvent(steps4);
Steps steps5 = new Steps(75, new Date(timeStamp).toString(), "K5E45H778");
cepRT.sendEvent(steps5);
Steps steps6 = new Steps(110, new Date(timeStamp).toString(), "K5E45H778");
cepRT.sendEvent(steps6);
This is my output:
Sending tick: Steps: 0.0 Timestamp: Mon Mar 14 18:13:23 CET 2016 Mac Address: K5E45H778
->Rule 1 fired: K5E45H778
Sending tick: Steps: 0.0 Timestamp: Mon Mar 14 18:18:23 CET 2016 Mac Address: LD24ESF7474
->Rule 1 fired: LD24ESF7474
Sending tick: Steps: 25.0 Timestamp: Mon Mar 14 18:23:23 CET 2016 Mac Address: K5E45H778
->Rule 1 fired: K5E45H778
Sending tick: Steps: 105.0 Timestamp: Mon Mar 14 18:28:23 CET 2016 Mac Address: LD24ESF7474
Sending tick: Steps: 55.0 Timestamp: Mon Mar 14 18:33:23 CET 2016 Mac Address: K5E45H778
->Rule 1 fired: K5E45H778
Sending tick: Steps: 75.0 Timestamp: Mon Mar 14 18:38:23 CET 2016 Mac Address: K5E45H778
Sending tick: Steps: 110.0 Timestamp: Mon Mar 14 18:43:23 CET 2016 Mac Address: K5E45H778
Why doesn't the rule fire for the one but last event of 75 steps?
The SQL-standard "group by" clause is for aggregation per group. Thus just adding "group by macAddress" should get it done.

Java UDF Date Regex Extractor for Pig?

I am trying to create a UDF for importing into Pig that matches a Regex pattern on a date. The Regex has been tested and works accordingly, but I am having trouble with the following code:
package com.date.format;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
public class DATERANGE extends EvalFunc<String> {
#Override
public String exec(Tuple arg0) throws IOException {
try
{
String pattern = "(Oct\\W(?:1[5-9]|2[0-3])\\W(?:(?:0?9|10):\\d{2}:\\d{2}|11:00:00))";
Pattern pat = Pattern.compile(pattern);
Matcher match = pat.matcher((String) arg0.get(0));
if(match.find())
{
return match.group(0);
}
else return "none";
}
catch(Exception e)
{
throw new IOException("Caught exception processing input row ", e);
}
}
}
After compiling the above java code and exporting it as a jar and running it inside Hadoop using the following Pig script:
register 'DATEFormat.jar';
ld = LOAD 'dates/date_data_three' AS (date:chararray);
loop = foreach ld generate com.date.format.DATERANGE(date) as d:chararray;
dump loop;
I get the following error:
ERROR 2078: Caught error from UDF: com.date.format.DATERANGE [Caught exception
processing input row ]
org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator
for alias loop
at org.apache.pig.PigServer.openIterator(PigServer.java:912)
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:752)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:372)
at org.apache.pig.tools.grunt.GruntParser.loadScript(GruntParser.java:566)
at org.apache.pig.tools.grunt.GruntParser.processScript(GruntParser.java:513)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.
Script(PigScriptParser.java:1014)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:550)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:228)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:203)
at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:66)
at org.apache.pig.Main.run(Main.java:542)
at org.apache.pig.Main.main(Main.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
Caused by: org.apache.pig.PigException: ERROR 1002: Unable to store alias loop
at org.apache.pig.PigServer.storeEx(PigServer.java:1015)
at org.apache.pig.PigServer.store(PigServer.java:974)
at org.apache.pig.PigServer.openIterator(PigServer.java:887)
... 16 more
The data file contains dates as shown below:
Wed Oct 15 09:26:09 BST 2014
Wed Oct 15 19:26:09 BST 2014
Wed Oct 18 08:26:09 BST 2014
Wed Oct 23 10:26:09 BST 2014
Sun Oct 05 09:26:09 BST 2014
Wed Nov 20 19:26:09 BST 2014
Does anybody know the correct way to implement a Java UDF for Pig that would work with the Regex I have provided?
Thanks
I recommend you to use REGEX_EXTRACT build-in command, this will be very easy instead of writing UDF.
ld = LOAD 'input.txt' AS (date:chararray);
loop = foreach ld generate REGEX_EXTRACT(date,'(Oct\\W(?:1[5-9]|2[0-3])\\W(?:(?:0?9|10):\\d{2}:\\d{2}|11:00:00))',1) as d:chararray;
C = FILTER loop by d is not null;
D = FOREACH C GENERATE $0;
DUMP D;
Output:
(Oct 15 09:26:09)
(Oct 23 10:26:09)
Your Regex UDF also working fine for me. i just copied your input and java code and executed locally. It works perfectly. Please see the below output that i got from your UDF code. I guess you may need to check your classpath are properly set or not.
(Oct 15 09:26:09)
(none)
(none)
(Oct 23 10:26:09)
(none)
(none)
Even better, you could use ToDate:
load your data into filtered_raw_financings_csvs with close_date as a chararray:
financings_csvs = FOREACH filtered_raw_financings_csvs
GENERATE name,
city,
state,
(close_date==''?NULL:ToDate(close_date, 'dd-MMM-yy')) AS close_date
;
Build your date format string as described here:
http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
This snippet is shown in context here:
http://nathan.vertile.com/blog/2015/04/17/handling-dates-in-hadoop-pig/

Ice4J: Ice State Failed on 4G network

Does anyone know how to do the TURN portion of Ice4j? I've managed to code it so that it works when the phone is on WiFi, but not when its on the mobile network.
I'm sending agent info via TCP and then building the connection manually instead of using a signalling process. The TCP connection already works fine, so I don't think its the TCP issue. Maybe I'm building the agent wrong?
I know that you're supposed to use a TURN server if STUN doesn't work, and I provided a large list of public TURN servers, but I might be missing something. Maybe the packets aren't being sent out properly?
Error: (Mostly Failed to send ALLOCATE-REQUEST(0X3))
Sep 11, 2014 3:36:09 PM org.ice4j.ice.Agent createMediaStream
INFO: Create media stream for data
Sep 11, 2014 3:36:09 PM org.ice4j.ice.Agent createComponent
INFO: Create component data.1
Sep 11, 2014 3:36:09 PM org.ice4j.ice.Agent gatherCandidates
INFO: Gather candidates for component data.1
Sep 11, 2014 3:36:09 PM org.ice4j.ice.harvest.HostCandidateHarvester harvest
INFO: End candidate harvest within 160 ms, for org.ice4j.ice.harvest.HostCandidateHarvester, component: 1
Sep 11, 2014 3:36:09 PM org.ice4j.ice.harvest.StunCandidateHarvest sendRequest
INFO: Failed to send ALLOCATE-REQUEST(0x3)[attrib.count=3 len=32 tranID=0x9909DC6648016A67FDD4B2D8] through /192.168.0.8:5001/udp to stun2.l.google.com:19302:5001/udp
Sep 11, 2014 3:36:12 PM org.ice4j.ice.ConnectivityCheckClient processTimeout
INFO: timeout for pair: /fe80:0:0:0:c8ce:5a17:c339:cc40%4:5001/udp -> /fe80:0:0:0:14e8:f3ff:fef3:6a21:6001/udp (data.1), failing.
Sep 11, 2014 3:36:12 PM org.ice4j.ice.ConnectivityCheckClient processTimeout
INFO: timeout for pair: /fe80:0:0:0:380d:2a4c:b350:eea8%8:5001/udp -> /fe80:0:0:0:14e8:f3ff:fef3:6a21:6001/udp (data.1), failing.
Sep 11, 2014 3:36:12 PM org.ice4j.ice.ConnectivityCheckClient processTimeout
INFO: timeout for pair: /192.168.0.8:5001/udp -> /100.64.74.58:6001/udp (data.1), failing.
Sep 11, 2014 3:36:12 PM org.ice4j.ice.ConnectivityCheckClient processTimeout
INFO: timeout for pair: /192.168.0.8:5001/udp -> /100.64.74.58:6001/udp (data.1), failing.
Sep 11, 2014 3:36:12 PM org.ice4j.ice.ConnectivityCheckClient updateCheckListAndTimerStates
INFO: CheckList will failed in a few seconds if nosucceeded checks come
Sep 11, 2014 3:36:17 PM org.ice4j.ice.ConnectivityCheckClient$1 run
INFO: CheckList for stream data FAILED
Sep 11, 2014 3:36:17 PM org.ice4j.ice.Agent checkListStatesUpdated
INFO: ICE state is FAILED
Script (Both the server and the client sides have similar codes to this one):
Agent agent = new Agent();
agent.setControlling(false);
StunCandidateHarvester stunHarv = new StunCandidateHarvester(new TransportAddress("sip-communicator.net", port, Transport.UDP));
StunCandidateHarvester stun6Harv = new StunCandidateHarvester(new TransportAddress("ipv6.sip-communicator.net", port, Transport.UDP));
agent.addCandidateHarvester(stunHarv);
agent.addCandidateHarvester(stun6Harv);
String[] hostnames = new String[] { "130.79.90.150",
"2001:660:4701:1001:230:5ff:fe1a:805f",
"jitsi.org",
"numb.viagenie.ca",
"stun01.sipphone.com",
"stun.ekiga.net",
"stun.fwdnet.net",
"stun.ideasip.com",
"stun.iptel.org",
"stun.rixtelecom.se",
"stun.schlund.de",
"stun.l.google.com:19302",
"stun1.l.google.com:19302",
"stun2.l.google.com:19302",
"stun3.l.google.com:19302",
"stun4.l.google.com:19302",
"stunserver.org",
"stun.softjoys.com",
"stun.voiparound.com",
"stun.voipbuster.com",
"stun.voipstunt.com",
"stun.voxgratia.org",
"stun.xten.com",};
LongTermCredential longTermCredential = new LongTermCredential("guest", "anon");
for (String hostname : hostnames)
agent.addCandidateHarvester(new TurnCandidateHarvester(new TransportAddress(hostname, port, Transport.UDP), longTermCredential));
//Build a stream for agent
IceMediaStream stream = agent.createMediaStream("data");
try {
Component c = agent.createComponent(stream, Transport.UDP, port, port, port+100 );
String response = "";
List<LocalCandidate> remoteCandidates = c.getLocalCandidates();
for(Candidate<?> can : remoteCandidates) {
response += "||" + can.toString();
}
response = "Video||" + agent.getLocalUfrag() + "||" + agent.getLocalPassword() + "||" + c.getDefaultCandidate().toString() + response;
System.out.println("Server >>> " + response);
DataOutputStream outStream = new DataOutputStream(client.getOutputStream());
outStream.write(response.getBytes("UTF-8"));
outStream.flush();
List<IceMediaStream> streams = agent.getStreams();
for(IceMediaStream localStream : streams) {
List<Component> localComponents = localStream.getComponents();
for(Component localComponent : localComponents) {
for(int i = 3; i < info.length; i++) {
String[] detail = info[i].split(" "); //0: Foundation
//1: Component ID
//2: Transport
//3: Priority #
//4: Address (Needed with Port # to create Transport Address)
//5: Port # (Needed with Address to create Transport Address)
//6: -filler: "Type" is next field-
//7: Candidate Type
String[] foundation = detail[0].split(":"); //Turn "Candidate:#" -> "Candidate" and "#". We use "#"
localComponent.addRemoteCandidate(new RemoteCandidate(new TransportAddress(detail[4], Integer.valueOf(detail[5]), Transport.UDP), c, CandidateType.HOST_CANDIDATE, foundation[1], Long.valueOf(detail[3]), null));
}
String[] defaultDetail = info[3].split(" ");
String[] defaultFoundation = defaultDetail[0].split(":");
localComponent.setDefaultRemoteCandidate(new RemoteCandidate(new TransportAddress(defaultDetail[4], Integer.valueOf(defaultDetail[5]), Transport.UDP), c, CandidateType.HOST_CANDIDATE, defaultFoundation[1], Long.valueOf(defaultDetail[3]), null));
}
localStream.setRemoteUfrag(info[1]);
localStream.setRemotePassword(info[2]);
}
agent.startConnectivityEstablishment();
System.out.println("ICEServer <><><> Completed");
I realize now that your list of TURN servers seem to mostly actually be STUN servers (not sure about the first two). They should be added as STUN servers if anything:
agent.addCandidateHarvester(
new StunCandidateHarvester(
new TransportAddress(
InetAddress.getByName('stun.l.google.com'),
19302,
Transport.UDP)));

Can't open a dcom session with jinterop

I'm trying to use jinterop to run wmi queries on remote PCs, but I can't even start a dcom session. I know wmi is working because I can access it with powershell\wmic\vbscript without issues. Also, our windows clients have file sharing disabled.
Here is what I am trying:
import static org.jinterop.dcom.impls.JIObjectFactory.narrowObject;
import static org.jinterop.dcom.impls.automation.IJIDispatch.IID;
import java.net.UnknownHostException;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.jinterop.dcom.impls.automation.IJIDispatch;
import static org.jinterop.dcom.core.JIProgId.valueOf;
import org.jinterop.dcom.core.JIVariant;
import org.jinterop.dcom.core.JIString;
public class SimpleServiceManager {
public static void main(String[] args) {
String domain = "mydom";
String hostname = "remotepc";
String username = "myusername";
String password = "mypass";
JISession dcomSession = JISession.createSession(domain, username, password);
JIComServer comServer;
try {
comServer = new JIComServer(valueOf("WbemScripting.SWbemLocator"), hostname, dcomSession);
IJIDispatch wbemLocator = (IJIDispatch) narrowObject(comServer.createInstance().queryInterface(IID));
Object[] params = new Object[] {
new JIString(hostname),
new JIString("ROOT\\CIMV2"),
JIVariant.OPTIONAL_PARAM(),
JIVariant.OPTIONAL_PARAM(),
JIVariant.OPTIONAL_PARAM(),
JIVariant.OPTIONAL_PARAM(),
new Integer(0),
JIVariant.OPTIONAL_PARAM()
};
JIVariant results[] = wbemLocator.callMethodA("ConnectServer", params);
IJIDispatch wbemServices = (IJIDispatch) narrowObject(results[0].getObjectAsComObject());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Gives me this:
Apr 10, 2013 1:14:38 PM org.jinterop.dcom.common.JISystem logSystemPropertiesAndVersion
INFO: j-Interop Version = j-Interop 2.08
Apr 10, 2013 1:14:38 PM org.jinterop.dcom.common.JISystem logSystemPropertiesAndVersion
INFO: java.runtime.name = Java(TM) SE Runtime Environment
sun.boot.library.path = C:\Program Files\Java\jre7\bin
java.vm.version = 23.7-b01
java.vm.vendor = Oracle Corporation
java.vendor.url = http://java.oracle.com/
path.separator = ;
java.vm.name = Java HotSpot(TM) Client VM
file.encoding.pkg = sun.io
user.country = US
user.script =
sun.java.launcher = SUN_STANDARD
sun.os.patch.level = Service Pack 1
java.vm.specification.name = Java Virtual Machine Specification
user.dir = C:\Users\myusername\Google Drive\code\Workspaces\Eclipse IDE for Java Developers 422\Jinterop
java.runtime.version = 1.7.0_17-b02
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs = C:\Program Files\Java\jre7\lib\endorsed
os.arch = x86
java.io.tmpdir = C:\Users\myusername\AppData\Local\Temp\
line.separator =
java.vm.specification.vendor = Oracle Corporation
user.variant =
os.name = Windows 7
sun.jnu.encoding = Cp1252
java.library.path = C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;...
java.specification.name = Java Platform API Specification
java.class.version = 51.0
sun.management.compiler = HotSpot Client Compiler
os.version = 6.1
user.home = C:\Users\myusername
user.timezone = America/New_York
java.awt.printerjob = sun.awt.windows.WPrinterJob
file.encoding = Cp1252
java.specification.version = 1.7
java.class.path = C:\Users\myusername\Google Drive\code\Workspaces\Eclipse IDE for Java Developers 422\Jinterop\bin;C:\Users\myusername\Google Drive\code\Workspaces\Eclipse IDE for Java Developers 422\Jinterop\libs\j-interop.jar;C:\Users\myusername\Google Drive\code\Workspaces\Eclipse IDE for Java Developers 422\Jinterop\libs\j-interopdeps.jar;C:\Users\myusername\Google Drive\code\Workspaces\Eclipse IDE for Java Developers 422\Jinterop\libs\jcifs-1.2.19.jar
user.name = myusername
java.vm.specification.version = 1.7
sun.java.command = SimpleServiceManager
java.home = C:\Program Files\Java\jre7
sun.arch.data.model = 32
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.windows.WToolkit
java.vm.info = mixed mode, sharing
java.version = 1.7.0_17
java.ext.dirs = C:\Program Files\Java\jre7\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path = C:\Program Files\Java\jre7\lib\resources.jar;C:\Program Files\Java\jre7\lib\rt.jar;C:\Program Files\Java\jre7\lib\sunrsasign.jar;C:\Program Files\Java\jre7\lib\jsse.jar;C:\Program Files\Java\jre7\lib\jce.jar;C:\Program Files\Java\jre7\lib\charsets.jar;C:\Program Files\Java\jre7\lib\jfr.jar;C:\Program Files\Java\jre7\classes
java.vendor = Oracle Corporation
file.separator = \
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
sun.desktop = windows
sun.cpu.isalist = pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
Apr 10, 2013 1:14:38 PM org.jinterop.dcom.core.JIComOxidRuntime$ClientPingTimerTask run
INFO: Running ClientPingTimerTask !
Apr 10, 2013 1:14:38 PM org.jinterop.dcom.core.JISession createSession
INFO: Created Session: -1745354837
Apr 10, 2013 1:14:38 PM org.jinterop.dcom.core.JIComOxidRuntime$ServerPingTimerTask run
INFO: Running ServerPingTimerTask !
Apr 10, 2013 1:14:38 PM org.jinterop.dcom.core.JISession$Release_References_TimerTask run
INFO: Release_References_TimerTask:[RUN] Session: -1745354837 , listOfDeferencedIpids.size(): 0
Apr 10, 2013 1:14:38 PM org.jinterop.dcom.common.JISystem saveDBPathAndLoadFile
INFO: progIdVsClsidDB: {}
org.jinterop.dcom.common.JIException: Message not found for errorCode: 0xC0000034
at org.jinterop.winreg.smb.JIWinRegStub.winreg_OpenHKLM(JIWinRegStub.java:115)
at org.jinterop.dcom.core.JIProgId.getIdFromWinReg(JIProgId.java:130)
at org.jinterop.dcom.core.JIProgId.getCorrespondingCLSID(JIProgId.java:162)
at org.jinterop.dcom.core.JIComServer.<init>(JIComServer.java:413)
at SimpleServiceManager.main(SimpleServiceManager.java:25)
Caused by: jcifs.smb.SmbException: The system cannot find the file specified.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:522)
at jcifs.smb.SmbTransport.send(SmbTransport.java:622)
at jcifs.smb.SmbSession.send(SmbSession.java:239)
at jcifs.smb.SmbTree.send(SmbTree.java:109)
at jcifs.smb.SmbFile.send(SmbFile.java:718)
at jcifs.smb.SmbFile.open0(SmbFile.java:923)
at jcifs.smb.SmbFile.open(SmbFile.java:940)
at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142)
at jcifs.smb.TransactNamedPipeOutputStream.<init>(TransactNamedPipeOutputStream.java:32)
at jcifs.smb.SmbNamedPipe.getNamedPipeOutputStream(SmbNamedPipe.java:187)
at rpc.ncacn_np.RpcTransport.attach(RpcTransport.java:92)
at rpc.Stub.attach(Stub.java:106)
at rpc.Stub.call(Stub.java:110)
at org.jinterop.winreg.smb.JIWinRegStub.winreg_OpenHKLM(JIWinRegStub.java:113)
... 4 more
Why is a jcifs.smb.SmbException getting thrown? WMI does not use smb so why am I seeing this error? Does jinterop require clients to have windows file sharing enabled?
There is a discussion about this issue in this thread.
Quick summary:
First, make sure the Remote Registry service is enabled.
Second, make sure that no auto-registration is used by j-interop (otherwise you will run into Access Denied errors):
JISystem.setAutoRegisteration(false);
Third, be sure that the firewall is not interfering.
I am responding to your statement "I can't even start a dcom session" .Here is the code using j-interop to get the session.
try {
args[0] = "x.y.z.w";
String domain = "";//i am using it as blank
String username = "username";//user who logs in to the system as admin
String password = "password";// used by admin to login to windows pc
JISystem.getLogger().setLevel(Level.FINEST);
JISystem.setInBuiltLogHandler(false);
JISystem.setAutoRegisteration(true);
JISession session3 = JISession.createSession(domain,username,password);
session3.useSessionSecurity(true);
System.out.println(" session3 "+session3);
}catch(Exception e){
e.printStackTrace();
}
you will see the output
session3 org.jinterop.dcom.core.JISession#a46bc929

Categories

Resources