Post data on Web using C++ Script - c++

I am using TestComplete 7. In this for configuration I have to post XML on web at specified IP and port address. I am using C++ Scripting language. How can I do this? or if there is other way to do same using interface and without scripting??

Looks like you need something like this:
XmlHttpRequest = new ActiveXObject("MSXML2.XMLHTTP.3.0");
XmlHttpRequest.open("POST", "http://camera.ip/configuration_page", false);
XmlHttpRequest.send("<?xml version="1.0" ?> <Config> <Video_Input_Source>IP CAM 3</Video_Input_Source> </Config>");
This is JScript. This code will work in a C++Script TC project.
But there may be problems with the "new ActiveXObject" statement in a C++ application if you put the code there. So, you will need to modify the code to use a different way to create the same "MSXML2.XMLHTTP.3.0" object in your C++ app. The idea remains the same.

Related

Accessing Sqlite Database from Windows Forms Application in C++

I am new to C++ (was previously into Java) and I am trying to find my way around it for the past few days. I am having a Sqlite DB in my local Machine which I am trying to access in order to display the results of a query on a Windows Application Form using DataGridView.
I was able to locate a good place to start here but later discovered that this was more concentrated towards SQL server and not SQLite and the code failed when I tried to replace this part of code
String^ connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
with this
String^ connectionString = "Data Source=C:\\data\\test.db"
to point to my local Sqlite DB (test.db).
Upon more digging I found that I was able to find C# examples for linking SQLite DB to Windows Form Application here. Next I tried to convert the C# code provided into a C++ one but failed.
I have been looking all around for simple C++ examples which would help me understand how to link a Sqlite DB to a Windows Form Application but am not able to do so yet.
I would appreciate it greatly if anyone could point me to one such example.
To access SQLite DB from managed code use System.Data.SQLite library. It's a managed library supported by SQLite Development Team and you can use it with managed C++ also. Here is the sample:
using namespace System::Data::SQLite;
using namespace System::Text;
void Test()
{
SQLiteConnection ^db = gcnew SQLiteConnection();
try
{
db->ConnectionString = "Data Source=C:\\data\\test.db";
db->Open();
// Do the job here
db->Close();
}
finally
{
delete (IDisposable^)db;
}
}

How can I create a JSON webservice to store and retrieve data from a simple properties file?

How can I create a Java or Javascript JSON webservice to retrieve data from a simple properties file? My intention is to uses this as a global property storage for a Jenkins instance that runs many Unit tests. The master property file also needs to be capable of being manually edited and stored in source control.
I am just wondering what method people would recommend that would be the easiest for a junior level programmer like me. I need read capability at miniumum but, and if its not too hard, write capability also. Therefore, that means it is not required to be REST.
If something like this already exists in Java or Groovy, a link to that resource would be appreciated. I am a SoapUI expert but I am unsure if a mock service could do this sort of thing.
I found something like this in Ruby but I could not get it to work as I am not a Ruby programmer at all.
There are a multitude of Java REST frameworks, but I'm most familiar with Jersey so here's a Groovy script that gives a simple read capability to a properties file.
#Grapes([
#Grab(group='org.glassfish.jersey.containers', module='jersey-container-grizzly2-http', version='2.0'),
#Grab(group='org.glassfish.jersey.core', module='jersey-server', version='2.0'),
#Grab(group='org.glassfish.jersey.media', module='jersey-media-json-jackson', version='2.0')
])
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory
import org.glassfish.jersey.jackson.JacksonFeature
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
#Path("properties")
class PropertiesResource {
#GET
#Produces("application/json")
Properties get() {
new File("test.properties").withReader { Reader reader ->
Properties p = new Properties()
p.load(reader)
return p
}
}
}
def rc = new org.glassfish.jersey.server.ResourceConfig(PropertiesResource, JacksonFeature);
GrizzlyHttpServerFactory.createHttpServer('http://localhost:8080/'.toURI(), rc).start()
System.console().readLine("Press any key to exit...")
Unfortunately, since Jersey uses the 3.1 version of the asm library, there are conflicts with Groovy's 4.0 version of asm unless you run the script using the groovy-all embeddable jar (it won't work by just calling groovy on the command-line and passing the script). I also had to supply an Apache Ivy dependency. (Hopefully the Groovy team will resolve these in the next release--the asm one in particular has caused me grief in the past.) So you can call it like this (supply the full paths to the classpath jars):
java -cp ivy-2.2.0.jar:groovy-all-2.1.6.jar groovy.lang.GroovyShell restProperties.groovy
All you have to do is create a properties file named test.properties, then copy the above script into a file named restProperties.groovy, then run via the above command line. Then you can run the following in Unix to try it out.
curl http://localhost:8080/properties
And it will return a JSON map of your properties file.

WinRT and missing Web API models for Amazon API access

I was working with porting the sample from the link below to a Windows 8 Metro styled app
http://aws.amazon.com/code/Product-Advertising-API/2480
Looks like many features from the web model are removed (or moved) in WinRT:
HttpUtility.UrlEncode
HttpUtility.UrlDecode
HMAC / HMACSHA256
to name a few. Are there alternatives to these on WInRT? I looked online and there's very little insight.
Theres source code for URLDecode here, and looks like Uri.EscapeDataString can be used for Encode.
http://www.koders.com/csharp/fid1A50096D8FA38302680B0EEDAC5B1CE1AEA855D0.aspx?s=%22Lawrence+Pit%22
copy the source code over, change the GetChars function to this
static char [] GetChars (MemoryStream b, Encoding e)
{
return e.GetChars (b.ToArray(), 0, (int) b.Length);
}
I had to use the code snippet from here to properly hash encrypt the string
http://channel9.msdn.com/Forums/TechOff/Porting-to-WinRT/4df7586e1ef5400682eda00f0143b610
Use methods from the WebUtility class instead:
System.Net.WebUtility.UrlEncode(string);
System.Net.WebUtility.UrlDecode(string);

Get fd or handle from socket object

I want to create a native (c++) module for node.js which is able to send sockets to another node process, which is completely unrelated to the current process. To do so, I tought of using the ancillary library, which has a really, really easy API for this. The problem I have to solve now is how I can get the fd or the handle of a socket object of node.js.
There's a TCPWrap class in tcp_wrap.cc & tcp_wrap.h, which has a property called handle_, which holds a uv_tcp_t object from libuv, but that property is private. Also I can't #include because it's just a module of node.js an not directly in node.js itself. I don't know if it's a good idea to copy the source files to my module just to get the that class...
Have you any ides how I could do it?
I doesn't have to run on winows, tough.
Thanks!
I finally found a way to do it. You can find the node module here:
https://github.com/VanCoding/node-ancillary
I've just taken the headers "tcp_wrap.h","stream_wrap.h" and "handle_wrap.h" and then included "tcp_wrap.h".
I could then get the object the following way:
TCPWrap* wrap = static_cast<TCPWrap*>(args[0]->ToObject()->GetPointerFromInternalField(0));
StreamWrap* s = (StreamWrap*)wrap;
The following code then gives access to the file descriptor
s->GetStream()->fd

Autogenerate Stub code in C++ to access a webservice?

I'm chancing my arm with this question.
I'm looking for a tool which will avoid doing a lot of coding by autogenerating much of the code to access a webservice.
I'm trying to help out someone who uses a 4GL system which doesn't support webservices. However they can access a win32 dll - which looks like being the easiest solution. All they need to do is occasionally call a function on a web service and get a result back.
Its been a loooong time since I wrote any C++ and my attempts at doing this have just exposed how rusty I am.
I've played around with the gsoap2 toolkit and MS's svcutil.exe tool for auto generating code.
They do what they are supposed to do but, unlike the add reference tool in visual studio with vb.net or c#.net, these toolkits don't generate a stub access class that I managed to find.
Instead they generate individual function calls for each method and you have to pass them httpcontexts and a whole load of other stuff - something I don't really want to have to learn how to do for a one off.
What I want to do is mechanical:
Take the wsdl definition
AutoGenerate the Webservice access code (done - gsoap2)
Write/generate a small stub to open the webservice and authenticate using basic authentication and to return an instance of the webservice instance class.
publish as a dll
The idea being to have a single dll with a single function like
getws(username, password, url)
which will return an object which exposes the methods of the webservices - a stub, nothing clever.
I know I'm clutching at straws here but does anyone know of a tool/way to avoid all the mechanical work and to end up with a simple class which I can modify to add authentication.
The webservice has around 30 methods - and I have to expose them all, each has a collection of parameters. Writing a stub class to call the functions generated by gsoap2 would be a lot of typing and a nightmare to get to work/debug. Theres got to be a better way.
What I want to do is the equivalent of the .net code below - VS autogenerates the WS code. All I have to do is expose it in my class.
Private Shared oWs As WS.publicws = Nothing
Public Shared Function GetWS(ByVal Username As String, ByVal password As String, ByVal URL As String) As WS.publicws
Dim oBinding As New ServiceModel.BasicHttpBinding
If Not oWs Is Nothing Then Return oWs
Dim oEndPoint As New ServiceModel.EndpointAddress(URL)
oBinding.Security.Mode = ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly
oBinding.Security.Transport.Realm = ServiceModel.HttpClientCredentialType.Basic
oWS = New WS.publicws (oBinding, oEndPoint)
oWS.ClientCredentials.UserName.UserName = username
oWS.ClientCredentials.UserName.Password = password
Using scope = New ServiceModel.OperationContextScope(oWs.InnerChannel)
ServiceModel.OperationContext.Current.OutgoingMessageProperties(System.ServiceModel.Channels.HttpRequestMessageProperty.Name) = httpRequestProperty
End Using
Return oWs
End Function