Can't open a dcom session with jinterop - java

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

Related

selenium raises InvalidArgumentException in version 91.0.4472.101 for any given url

Given:
from selenium import webdriver
import os
def setUp_Browser():
if 'nt' in os.name.lower():
# import psutil
# for proc in psutil.process_iter():
# if proc.name() == "chromedriver.exe":
# proc.kill()
time.sleep(1)
caps = webdriver.DesiredCapabilities.CHROME.copy()
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_argument('ignore-certificate-errors')
options.add_argument("--incognito")
caps['acceptInsecureCerts'] = True
import pathlib
projectDir = str(pathlib.Path(__file__).parent.absolute()) + "\\Resources\\Drivers\\"
executable_path = os.path.join(projectDir, "chromedriver.exe")
self.browser = webdriver.Chrome(executable_path=executable_path, options=options, desired_capabilities=caps)
time.sleep(3)
self.browser.get(url='www.google.ro')
self.browser.implicitly_wait(15)
time.sleep(4)
I cannot access any given url, it always raises an invalid arg exception after the latest driver update:
File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: chrome=91.0.4472.101)
Some more text so i can post the question...........
Adding http or https, and removing "www." from the url seems to work fime

Cucumber autotest cant find elements via Jenkins

have problems with my java tests on Cucumber when i run them via jenkins on remote host.
My code:
step:
Given open link from property "bla-blalink"
And type to input with name "UserName" property: "login" on "LoginPage"
element:
#NameOfElement("UserName")
#FindBy(id = "UserName")
public SelenideElement username;
step def:
#And("^type to input with name \"([^\"]*)\" property: \"([^\"]*)\" on \"([^\"]*)\"$")
public void typeToInputWithNamePropertyOn(String nameOfElement, String property, String page) throws InterruptedException, IOException {
sleep(5000);
Properties properties = new Properties();
try (FileReader fileReader = new FileReader(Constants.PROPERTY_PATH)) {
properties.load(fileReader);
}
if ("LoginPage".equals(page)) {
loginPage.get(nameOfElement).sendKeys(properties.getProperty(property));
} else if ("MainPage".equals(page)) {
mainPage.get(nameOfElement).sendKeys(properties.getProperty(property));
} else if ("ActionPage".equals(page)) {
actionPage.get(nameOfElement).sendKeys(properties.getProperty(property));
}
}
configure:
#BeforeClass
static public void setupTimeout() {
/////////////////////////////////for remote runs////////////////////////////////
// Configuration.remote = "http://10.52.185.105:4419/wd/hub";
// Configuration.browser = "chrome";
// DesiredCapabilities capabilities = new DesiredCapabilities();
// capabilities.setBrowserName("chrome");
// capabilities.setCapability(ACCEPT_SSL_CERTS, true);
// WebDriver wd = new RemoteWebDriver(new URL("http://10.52.185.105:4419/wd/hub"), capabilities);
// setWebDriver(wd);
///////////////////////////////////for local runs////////////////////////////
Configuration.timeout = 10000;
System.setProperty("webdriver.chrome.driver", "src/main/resources/webdrivers/chromedriver.exe");
Configuration.browser = "chrome";
What i tried:
it works locally
it works on remote machine(without jenkins)
change window size - doesnt help
change sleep on 35000ms - doesnt help
our jenkins
not started as a service, so i dont know how to allow to interact with elements
output:
T E S T S
Running ru.open.runners.BusinessPortalTest
июн 13, 2018 9:55:27 AM com.codeborne.selenide.impl.WebDriverThreadLocalContainer getWebDriver
INFO: No webdriver is bound to current thread: 1 - let's create new webdriver
Starting ChromeDriver 2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb) on port 5610
Only local connections are allowed.
июн 13, 2018 9:55:31 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
июн 13, 2018 9:55:33 AM com.codeborne.selenide.webdriver.WebDriverFactory logBrowserVersion
INFO: BrowserName=chrome Version=67.0.3396.87 Platform=XP
июн 13, 2018 9:55:33 AM com.codeborne.selenide.webdriver.WebDriverFactory createWebDriver
INFO: Selenide v. 4.11.4
июн 13, 2018 9:55:33 AM com.codeborne.selenide.webdriver.WebDriverFactory logSeleniumInfo
INFO: Selenium WebDriver v. 3.12.0 build time: 2018-05-08T14:04:26.12Z
июн 13, 2018 9:55:33 AM com.codeborne.selenide.impl.WebDriverThreadLocalContainer createDriver
INFO: Create webdriver in current thread 1: ChromeDriver -> ChromeDriver: chrome on XP (9879008c2825cc8b84a452e24010d66d)
Failed scenarios:
businessportaltest.feature:440 # Scenario: Change phone number
157222(verify ONLY with payment order)
1 Scenarios (1 failed)
29 Steps (1 failed, 27 skipped, 1 passed)
0m18.951s
java.lang.IllegalArgumentException: ERROR: there is no such element with name Имя пользователя at page ru.open.pageobjects.businessportal.LoginPage
at ru.open.pageobjects.AbstractPage.get(AbstractPage.java:27)
at ru.open.steps.MyStepdefs.typeToInputWithNamePropertyOn(MyStepdefs.java:63)
at ?.And type to input with name "Имя пользователя" property: "login" on "LoginPage"(businessportaltest.feature:443)
remote machine - windows server 2012R

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?

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)));

Working with mongodb from 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.

Categories

Resources