How to run gSOAP code generator without internet connection? - c++

I am trying to generate code using wsdl2h/soap2cpp for the onvif media WSDL http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl. This wsdl have some dependencies.
Reading the gSOAP FAQ http://www.cs.fsu.edu/~engelen/soapfaq.html, I finally extract the needed namespaces in following typemap.dat
trt = "http://www.onvif.org/ver10/media/wsdl"
tt = "http://www.onvif.org/ver10/schema"
wsnt = "http://docs.oasis-open.org/wsn/b-2"
wsrfbf = "http://docs.oasis-open.org/wsrf/bf-2"
wstop = "http://docs.oasis-open.org/wsn/t-1"
xop="http://www.w3.org/2004/08/xop/include"
wsa5 = <http://www.w3.org/2005/08/addressing>
With this mapping the gSOAP code generator run correctly :
wsdl2h media.wsdl
soapcpp2 -2ix media.h -I /usr/share/gsoap/import
But this need to have an internet connection. I would like to build with files that are stored locally.
In the wsdl2h help there is an option that looks interesting :
-i don't import (advanced option)
So I download what was downloaded by wsdl2h :
http://www.onvif.org/onvif/ver10/schema/onvif.xsd
http://docs.oasis-open.org/wsn/b-2.xsd
http://www.w3.org/2004/08/xop/include
http://docs.oasis-open.org/wsrf/bf-2.xsd
http://docs.oasis-open.org/wsn/t-1.xsd
And next run
wsdl2h -im media.wsdl onvif.xsd b-2.xsd include bf-2.xsd t-1.xsd
soapcpp2 -2ix media.h -I /usr/share/gsoap/import
But this fails with this kind of output :
** The gSOAP code generator for C and C++, soapcpp2 release 2.8.7
** Copyright (C) 2000-2011, Robert van Engelen, Genivia Inc.
** All Rights Reserved. This product is provided "as is", without any warranty.
** The soapcpp2 tool is released under one of the following two licenses:
** GPL or the commercial license by Genivia Inc.
media.h(164): syntax error
media.h(163): Syntax error: declaration expected
media.h(173): syntax error
...
In media.h the code reference strucure coming from ws-addressing. Next I tried different things importing more xsd but I did not find a way to resolve the missing dependencies.
Perhaps this is not the proper way to build from local file. Anyway I would like to avoid any modification in the wsdls and xsd files. An alternative could be a catalog to map the remote url to local url (like Apache CXF) but I did not find anything like this in gSOAP documentation.
Thanks for sharing your experiences.

I found only partial documentation of the typemap.dat format from gSOAP site http://www.cs.fsu.edu/~engelen/soapdoc2.html. However I noticed that some namespace definition use <url> instead of "url".
After some tries, this give a solution to the problem, defining namespace enclosed inside <>.
So I modified the typemap.dat like this :
trt=<http://www.onvif.org/ver10/media/wsdl>
tt=<http://www.onvif.org/ver10/schema>
wsnt=<http://docs.oasis-open.org/wsn/b-2>
wsrfbf=<http://docs.oasis-open.org/wsrf/bf-2>
wstop=<http://docs.oasis-open.org/wsn/t-1>
xop=<http://www.w3.org/2004/08/xop/include>
wsa5=<http://www.w3.org/2005/08/addressing>
Then it is possible to generate code from the media.wsdl without connecting to internet :
wsdl2h media.wsdl onvif.xsd b-2.xsd include bf-2.xsd t-1.xsd
soapcpp2 -2ix media.h -I /usr/share/gsoap/import

Related

I can't knit my rmarkdown files - pandoc error

My university provided laptop was recently replaced and now when I try to knit my Rmd files if get the following error:
pandoc.exe: \\: openBinaryFile: invalid argument (Invalid argument)
Error: pandoc document conversion failed with error 1
Execution halted
These files used to knit perfectly on my old laptop and all of the code blocks within the file still run without errors.
The pandoc_available() function returns TRUE
The answers to similar questions that I have searched suggest it is something to do with the file paths but I am not familiar enough with this to make sense of what I should do. I tried mapping a network drive (Z:) to the folder where the Rmd file is stored and then changing the working directory in RStudio to that drive but it hasn't helped (and now I don't know how to change it back to ~ or what that referred to in the first place)
I have also tried downloading the latest version of Pandoc and a search on Windows Explorer shows that has installed in my user directory but I also have a version in C:\Program Files\RStudio\bin. That has also not helped.
I'm not sure if this is relevant but here is the information on the R version that I am running:
R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
Can you tell me what other information is required to diagnose the problem and I will edit to include.
I am sorry this question is so poorly specified and would appreciate any help to improve it.
**** UPDATE ****
I have found that if I
(i) specify that I want a .md file in the YAML header,
(ii) create an .md file by knitting the markdown file,
(iii) copy that .md file manually to the Pandoc directory
(iv) run pandoc.exe -s -o test.knit.md test.html from the MSDOS command prompt within the Pandoc directory,
then I can create the html output file.
However, changing the working directory for RStudio to the Pandoc directory and running
x <- rmarkdown::render("test.Rmd", run_pandoc = FALSE, clean = FALSE)
knit_meta <- attr(x, "knit_meta")
rmarkdown::render( input = 'test.knit.md' , knit_meta = knit_meta )
as per https://stackoverflow.com/questions/38908766/how-to-generate-an-md-file-from-a-rmarkdown-file-containing-an-htmlwidget gives the same error as shown in my original post.
Does this prompt any thoughts that might lead to a solution to my problem?
The university IT people were able to solve my problem by uninstalling R and RStudio from the network drive and installing it on the C: drive and I am now able to knit successfully.

API build fails in WSO2 API Microgateway 3.1.0

I am new to WSO2 microgateway and was following the steps given in the documentation : "https://docs.wso2.com/display/MG310/Quick+Start+Guide+-+Binary" for exposing the Petstore service via microgateway.
I was able to initialize the API using the swagger file as given in the steps. The Petstore project is also created under the project directory. But when i try to build the project as given in Step 1.2, it fails with an error as shown below. Need suggestions to resolve this issue.
In the ballerina-internal.log file, i get the below error.
[2020-07-16 21:13:19,009] SEVERE {b7a.log.crash} - Array index out of range: 0
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
at org.ballerinalang.nativeimpl.jvm.interop.JMethodResolver.validateArgumentTypes(JMethodResolver.java:194)
at org.ballerinalang.nativeimpl.jvm.interop.JMethodResolver.validateMethodSignature(JMethodResolver.java:148)
at org.ballerinalang.nativeimpl.jvm.interop.JMethodResolver.resolve(JMethodResolver.java:107)
at org.ballerinalang.nativeimpl.jvm.interop.JInteropMethodValidator.resolveJMethod(JInteropMethodValidator.java:74)
at org.ballerinalang.nativeimpl.jvm.interop.JInteropMethodValidator.validateAndGetJMethod(JInteropMethodValidator.java:61)
at ballerina.jvm.$value$InteropValidator.validateAndGetJMethod(interop.bal:90)
at ballerina.jvm.$value$InteropValidator.call(interop.bal)
at ballerina.compiler_backend_jvm.interop.interop_method_gen.createJMethodWrapper(interop/interop_method_gen.bal:136)
at ballerina.compiler_backend_jvm.interop.interop_method_gen.createJInteropFunctionWrapper(interop/interop_method_gen.bal:128)
at ballerina.compiler_backend_jvm.interop.external_method_gen.createExternalFunctionWrapper(interop/external_method_gen.bal:180)
at ballerina.compiler_backend_jvm.jvm_package_gen.generateClassNameMappings(jvm_package_gen.bal:477)
at ballerina.compiler_backend_jvm.jvm_package_gen.generatePackage(jvm_package_gen.bal:149)
at ballerina.compiler_backend_jvm.jvm_package_gen.generateDependencyList(jvm_package_gen.bal:120)
at ballerina.compiler_backend_jvm.jvm_package_gen.generatePackage(jvm_package_gen.bal:142)
at ballerina.compiler_backend_jvm.jvm_package_gen.generateDependencyList(jvm_package_gen.bal:120)
at ballerina.compiler_backend_jvm.jvm_package_gen.generatePackage(jvm_package_gen.bal:142)
at ballerina.compiler_backend_jvm.jvm_package_gen.generateDependencyList(jvm_package_gen.bal:120)
at ballerina.compiler_backend_jvm.jvm_package_gen.generatePackage(jvm_package_gen.bal:142)
at ballerina.compiler_backend_jvm.jvm_package_gen.generateDependencyList(jvm_package_gen.bal:120)
at ballerina.compiler_backend_jvm.jvm_package_gen.generatePackage(jvm_package_gen.bal:142)
at ballerina.compiler_backend_jvm.main.generateJarBinary(main.bal:86)
at ballerina.compiler_backend_jvm.main.main(main.bal:60)
at ballerina.compiler_backend_jvm.___init.$lambda$main$(compiler_backend_jvm)
at ballerina.compiler_backend_jvm.___init$$Lambda$11.000000001107AEE0.apply(Unknown Source)
at org.ballerinalang.jvm.scheduling.SchedulerItem.execute(Scheduler.java:426)
at org.ballerinalang.jvm.scheduling.Scheduler.run(Scheduler.java:218)
at org.ballerinalang.jvm.scheduling.Scheduler.runSafely(Scheduler.java:191)
at org.ballerinalang.jvm.scheduling.Scheduler$$Lambda$6.0000000010F6DAF0.run(Unknown Source)
at java.lang.Thread.run(Thread.java:813)
Looking at the responses in the comments it looks like the external jdk is not fully compatible with mgw. Not sure on the exact reason though. Here is a bit more background on what going on during the build command and a possible workaround to force mgw use internal jdk.
All mgw distributions (toolkit/runtime) including the binary distribution, contains a jdk internally which is fully compatible with the ballerina version used in the mgw. However during the execution of mgw toolkit command it checks for externally installed jdks (by looking at JAVA_HOME variable) and pick it as the jdk if a compatible version is found in the system. Otherwise it will use the internal jdk.
So to avoid mgw from picking up external jdk, we should set JAVA_HOME variable to "" or invalid location. To do that open micro-gw.bat (assume you are on windows) file in the <TOOLKIT_HOME>/bin directory and around line 55 after SET HOME_CACHE=%MICROGW_HOME%\lib\gateway-balo add SET JAVA_HOME= as command. After the change code block around above line will look like below.
.
.
.
SET PATH=%BALLERINA_HOME%\bin\;%PATH%
SET JAVA_PATH=%MICROGW_HOME%\lib\jdk8u202-b08-jre
SET HOME_CACHE=%MICROGW_HOME%\lib\gateway-balo
REM ******* Below is the line we added to reset the JAVA_HOME *******
SET JAVA_HOME=
REM Check JAVA availability
if EXIST "%JAVA_HOME%" (
ECHO JAVA_HOME: %JAVA_HOME%
.
.
.
Save the file and try the build command again. It should work.

How to I tell em++ to find WS2tcpip.h

Trying to make a whois tcp lookup that directly queries verisign via port 43. Got it to work in command line + visual studio community 2017.
When I try to use em++ to compile it, I get an error.
C:\Users\Samuel Walker\source\repos\Barebones_Client\Barebones_Client>em++ -O3 --emrun -s WASM=1 -o main.html main.cpp
main.cpp:3:10: fatal error: 'WS2tcpip.h' file not found
#include <WS2tcpip.h>
^~~~~~~~~~~~
1 error generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
I'm using WS2tcpip.h for the script. It's essential, but yeah still entirely new to C++ and following guides and snippets online. Is this a matter of somehow telling enscripten to know where windows header files are or am I completely off?
You cannot. WS2tcpip.h is part of the Windows API, which is not available in the browser.
You can make HTTP requests from JavaScript, but there are no generic sockets to be able to make requests using the WHOIS protocol. You will need to contact a web server that offers an API for making WHOIS requests. Also see this question and its answers:
Whois with JavaScript

Why does Visual Studio 2017 fail to generate REST API client for Swagger Petstore?

I'm playing around with using Swagger / OpenAPI docs/specs to generate REST API client code in C#, but I'm running into several problems.
Most notably - when trying to use the Swagger.io Petstore example as a starting point:
Using the VS 2017 Add > REST API client option in VS 2017, I don't get any code produced - instead an error is shown:
Generating client code and adding to project started
Generate client code for REST API with following parameters:
REST API Name: OpenApiClientClient, Base namespace: OpenApiClient, Metadata file path: C:\Users\Marc\AppData\Local\Temp\WebToolsAutoRest\OpenApiClientClient\201807162213351660\swagger.json
[Info]AutoRest Core 0.16.0.0
[Info]Initializing modeler.
[Info]Initializing modeler.
[Info]Parsing swagger json file.
[Info]Generating client model from swagger model.
[Fatal]Error generating client model: Collection format "multi" is not supported (in parameter 'status').
Exception: There was an error during code generation when trying to add a client for the REST API
Generating client code and adding to project failed
Adding REST API client for failed
So if the Swagger sample app isn't compatible - how will others be?? (and I tried a few others, all with the same results, unfortunately).
What's wrong here? Am I missing something, do I need to add some extra tooling to VS 2017 to make this work?
UPDATE:
OK, so I now tried to install Autorest using npm directly:
npm install -g autorest
This appears to work - no errors shown or anything.
But trying to run Autorest - with a set of command line parameters, or even just on its own - results in an error:
AutoRest -CodeGenerator CSharp -Modeler Swagger
-Input https://petstore.swagger.io/v2/swagger.json
-Namespace Services.UserServiceClient -OutputDirectory d:\projects
-AddCrendentials true
or just
AutoRest <kbd>Enter</kbd>
results in:
AutoRest code generation utility [version: 2.0.4280; node: v9.9.0]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
Failure:
Error: Unable to start AutoRest Core from C:\Users\Marc.autorest\#microsoft.azure_autorest-core#2.0.4280\node_modules\#microsoft.azure\autorest-core
Error: Unable to start AutoRest Core from C:\Users\Marc.autorest\#microsoft.azure_autorest-core#2.0.4280\node_modules\#microsoft.azure\autorest-core
at main (C:\Users\Marc\AppData\Roaming\npm\node_modules\autorest \dist\app.js:232:19)
at
Any further ideas?
Visual Studio 2017 is using a very old version of AutoRest. The issue you are seeing is this one which was fixed in AutoRest v. 1.0. As explained in the comments in that issue:
Are you referring to the autorest version that's built-into visual studio? -- That's incredibly old, and we didn't update that (we've changed the whole way autorest works).
You are going to need to install node and use autorest from the command line.
Looks like it's not possible to update AutoRest used by Visual Studio 2017, so you'll need to call AutoRest directly.
I also had this problem so I built a tool for it called REST API Client Code Generator. I worked in teams where we used tools like AutoRest, NSwag, and Swagger Codegen to generate our REST API Clients and it always annoyed me that the "Add New - REST API Client..." tooling in Visual Studio didn't always work and was very troublesome when it was time to re-generate the client
This would add the OpenAPI specification file (Swagger.json) to the project and set a custom tool so that every time changes are made to it the REST API Client code is re-generated. You can also right click on the Swagger.json file and switch code generators
I built the tool mainly for personal use and for use within my teams but if you find it useful and think it lacks something you really need then please reach out
Try running autorest --reset. This worked on windows with node v8.12.0. Prior to running that command I was getting the same error.

WS-Discovery & gSOAP set up in VS2013

My overarching goal is to create a small ONVIF client for getting camera information in either C or C++.
gSOAP seemed like a good candidate and first thing I wanted to achieve was to make a small console application which would list the addresses of a bunch of cameras I have on my network using WS-Discovery, something I've done before with a little .NET application.
The problem is I'm stumbling at the first hurdle and I'm a touch confused as to what I'm supposed to be doing. I started out by doing the following:
wsdl2h.exe -o WSDiscovery.h WS-Discovery.wsdl http://www.w3.org/2006/03/addressing/ws-addr.xsd
soapcpp2.exe -i -C -Iimport WSDiscovery.h -d output
,
I then made a project from the resulting soapC.cpp stdsoap2.cpp soapH.h soapStub.h. Adding in threads.h wsaapi.h wsddapi.h threads.c wsaapi.c wsddapi.c from gsoap
This doesn't compile however giving:
wsaapi.h(134): error C2061: syntax error : identifier 'wsa__FaultSubcodeValues'
I think I'm going very wrong here and I'm confused about exactly what a 'plugin' is in the context of gSOAP (my experience with external libraries like this is extremely limited and I have no real formal training in CS). Am I just supposed to be doing what I'm doing now with the wsdd files or are they supposed to be used as part of the soapcpp2.exe process? Am I actually supposed to be using wsdl2h.exe if I just want WS-Discovery?
I can't really make sense of the documentation and don't understand how I'm supposed to get this working. Some help would be greatly appreciated so I can crack on with the actual hard part!
I guess the problem is coming from usage of WS-Adressing plugins (wsaapi.h/.c) with http://www.w3.org/2006/03/addressing/ws-addr.xsd schema.
gSOAP contains the wsdl2h generated file that could be used by WS-discovery plugins (wsddapi.h/.c).
[GSOAP_DIR]/import/wsdd10.h for WS-Discovery 1.0 2005 that use WS-Adressing 2004/08
[GSOAP_DIR]/import/wsdd.h for WS-Discovery 1.1 2009 that use WS-Adressing 2005/08
As ONVIF use WS-Discovery 1.0 you could generate discovery implementation using :
soapcpp2 -Cx [GSOAP_DIR]/import/wsdd10.h -I [GSOAP_DIR]/import -d output
Next you should be able to build your project including wsddapi.c wsaapi.c soapClient.cpp soapC.cpp
You can find some of my experiments from github ws-discovery