protoc-gen-grpc-swift: Plugin killed by signal 9 - swift

I run the following command
protoc ./Sources/Protos/echo.proto \
--proto_path=./Sources/Protos/ \
--plugin=/usr/local/bin/protoc-gen-swift \
--swift_opt=Visibility=Public \
--swift_out=Sources/Protos/ \
--plugin=/usr/local/bin/protoc-gen-grpc-swift \
--grpc-swift_opt=Visibility=Public,AsyncClient=True,AsyncServer=True \
--grpc-swift_out=./Sources/Protos/
The protocol is:
syntax = "proto3";
package echo;
service EchoService {
rpc echo(EchoRequest) returns (EchoResponse);
}
message EchoRequest {
string contents = 1;
}
message EchoResponse {
string contents = 1;
}
And receive the error:
--grpc-swift_out: protoc-gen-grpc-swift: Plugin killed by signal 9.
I am running tag 1.7.1-async-await.2.
This was generating the output files under 1.8.1 but I would like the async-await version. This fails even if the async flags are False. I have verified that the plugins in /usr/local/bin are the ones generated by make plugins in 1.7.1-async-await.2.

Related

MultiPart PUT request not working in spring boot

I have the following curl request
curl -X PUT http://localhost:50005/did:corda:tcn:77ccbf5e-4ddd-4092-b813-ac06084a3eb0 -H 'content-type:multipart/form-data' -F 'instruction=hgfhhf'
I am trying to read the instruction in my spring boot controller as seen below
#PutMapping(value = "{id}",
produces = arrayOf(MediaType.APPLICATION_JSON_VALUE),
consumes = arrayOf(MediaType.MULTIPART_FORM_DATA_VALUE))
fun createID(#PathVariable(value = "id") id: String,
#RequestParam("instruction") instruction: String ) : ResponseEntity<Any?>
But the code above returns
"status":400,"error":"Bad Request","exception":"org.springframework.web.multipart.support.MissingServletRequestPartException","message":"Required request part 'instruction' is not present"
remove unused:
consumes = arrayOf(MediaType.MULTIPART_FORM_DATA_VALUE)
you have missed request param instruction (in reqeust), try this:
curl -X PUT -G 'http://localhost:50005/did:corda:tcn:77ccbf5e-4ddd-4092-b813-ac06084a3eb0' -d 'instruction=hgfhhf'
also take a look at CURL Command Line URL Parameters

Can't find mongoc.h

I can't find mongoc.h after installing Mongodb and C driver on Ubuntu 16.04.
sudo apt-get install mongodb
sudo apt-get install libmongoc-1.0-0
sudo apt-get install libbson-1.0
This is the error I get:
gcc -o mtest mtest.c -I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0 -lmongoc-1.0 -lbson-1.0
mtest.c:1:20: fatal error: mongoc.h: No such file or directory
compilation terminated.
I checked the disk and can not find the file. Tips appreciated.
If you have installed via apt-get, then the packages almost certainly don't install to /usr/local, but to plain old /usr. What happens if you run
gcc -o mtest mtest.c -I/usr/include/libbson-1.0 -I/usr/include/libmongoc-1.0 -lmongoc-1.0 -lbson-1.0
P.S. The right way to pick up these paths is by using pkg-config instead of hard coding them, please see http://mongoc.org/libmongoc/current/tutorial.html#pkg-config
I faced the same problem, then instead installing the packages for the libraries I followed the steps below (for Ubuntu), according with this link for libmongoc :
1 - Check if you have cmake installed, if not:
$ sudo apt-get install cmake
2 - to download, build sources and install libraries:
$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.14.0/mongo-c-driver-1.14.0.tar.gz
$ tar xzf mongo-c-driver-1.14.0.tar.gz
$ cd mongo-c-driver-1.14.0
$ mkdir cmake-build
$ cd cmake-build
$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
3 - to Test, edit a file and save as hello_mongo.c:
#include <mongoc/mongoc.h>
int main (int argc, char *argv[])
{
const char *uri_string = "mongodb://localhost:27017";
mongoc_uri_t *uri;
mongoc_client_t *client;
mongoc_database_t *database;
mongoc_collection_t *collection;
enter code here`bson_t *command, reply, *insert;
bson_error_t error;
char *str;
bool retval;
/*
* Required to initialize libmongoc's internals
*/
mongoc_init ();
/*
* Optionally get MongoDB URI from command line
*/
if (argc > 1) {
uri_string = argv[1];
}
/*
* Safely create a MongoDB URI object from the given string
*/
uri = mongoc_uri_new_with_error (uri_string, &error);
if (!uri) {
fprintf (stderr,
"failed to parse URI: %s\n"
"error message: %s\n",
uri_string,
error.message);
return EXIT_FAILURE;
}
/*
* Create a new client instance
*/
client = mongoc_client_new_from_uri (uri);
if (!client) {
return EXIT_FAILURE;
}
/*
* Register the application name so we can track it in the profile logs
* on the server. This can also be done from the URI (see other examples).
*/
mongoc_client_set_appname (client, "connect-example");
/*
* Get a handle on the database "db_name" and collection "coll_name"
*/
database = mongoc_client_get_database (client, "db_name");
collection = mongoc_client_get_collection (client, "db_name", "coll_name");
/*
* Do work. This example pings the database, prints the result as JSON and
* performs an insert
*/
command = BCON_NEW ("ping", BCON_INT32 (1));
retval = mongoc_client_command_simple (
client, "admin", command, NULL, &reply, &error);
if (!retval) {
fprintf (stderr, "%s\n", error.message);
return EXIT_FAILURE;
}
str = bson_as_json (&reply, NULL);
printf ("%s\n", str);
insert = BCON_NEW ("hello", BCON_UTF8 ("world"));
if (!mongoc_collection_insert_one (collection, insert, NULL, NULL, &error)) {
fprintf (stderr, "%s\n", error.message);
}
bson_destroy (insert);
bson_destroy (&reply);
bson_destroy (command);
bson_free (str);
/*
* Release our handles and clean up libmongoc
*/
mongoc_collection_destroy (collection);
mongoc_database_destroy (database);
mongoc_uri_destroy (uri);
mongoc_client_destroy (client);
mongoc_cleanup ();
return EXIT_SUCCESS;
}
4 - to compile and run the C program:
$ gcc -o hello_mongoc hello_mongoc.c -I/usr/local/include/libbson-1.0
-/usr/local/include/libmongoc-1.0 -lmongoc-1.0 -lbson-1.0
$ ./hello_mongoc
If you're working with the raspberrypi 3, you're problaby using mongodb 2.4.14 and then libraries libbson and libmongoc must be version 1.7.0.. look these: libmongoc and libbson.

Creating command line strings with groovy for cURL - cURL ignores options

I need help figuring out why the last two parameters of my cURL query are ignored.
Please refrain on comment on how this is not the best way to do a rest call. I KNOW. This is going to be a kind of fall back method / work around for another issue.
I manyl handle my rest-work with the wslite (1.1.2) API.
Now let me explain what i do:
I am using the groovy shell executor to make a command line call for a rest service via cURL.
I have built a little class to build the query string and handle the command line:
class Curl {
def static getUserLogin(){
def url = '"https://some-login.someSystem-dev.someHost.com/someResource.beyond.foobar/login/LoginAUser '
def requestFilePath = '-d #temp/LoginPayload.json '
def heads = "-H 'Content-Type: application/json' -H 'Accept: text/plain' "
def params = '-k -v' //-k = ignore unsecure -v = more verbose output
def fullurl = url+requestFilePath+heads+params
return ex(fullurl)
}
/**
*
* #param _command The command you want to execute on your shell.
* #param _workingDir Optional: You may specify the directory where the command will be executed. Default is user dir.
* #return Exit value for the process. 0 = normal termination.
*/
def static ex(String _command, File _workingDir = new File(System.properties.'user.dir')) {
println "Executing command> $_command \n"
def process = new ProcessBuilder(addShellPrefix(_command))
.directory(_workingDir)
.redirectErrorStream(true)
.start()
process.inputStream.eachLine {println it}
process.waitFor();
return process.exitValue().value
}
private static addShellPrefix(String _command) {
def commandArray = new String[2]
commandArray[0] = "curl "
commandArray[1] = _command
return commandArray
}
}
Curl.getUserLogin() //to execute
I hope the code is self-explenatory enough. It all works fine with simple URLs respectively with less parameters.
Executing this will yield the following response (excerpt from the full debug output):
Executing command>
"https://some-login.someSystem-dev.someHost.com/someResource.beyond.foobar/login/LoginAUser"
-d #temp/LoginPayload.json -H 'Content-Type: application/json' -H 'Accept: text/plain' -k -v
% Total % Received % Xferd Average Speed Time Time Time
Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:--
--:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 curl: (60) SSL certificate problem: self signed certificate in certificate chain More details here:
http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a
"bundle" of Certificate Authority (CA) public keys (CA certs). If the
default bundle file isn't adequate, you can specify an alternate file
using the --cacert option. If this HTTPS server uses a certificate
signed by a CA represented in the bundle, the certificate
verification probably failed due to a problem with the certificate
(it might be expired, or the name might not match the domain name in
the URL). If you'd like to turn off curl's verification of the
certificate, use the -k (or --insecure) option.
Now, as you can see I have attached the required option "-k" to the query string but somehow it is ignored. Using this string directly in the windows command line tool (if you try this make sure you escape potential double quotes) works perfectly fine though.
Any ideas why this happens or how I could accquire more debug information?
Thx in advance!
UPDATE:
Solution:
Passing ever option as a single argument (via a list) fixed the issue.
New Issue:
After that i wante curl to output the response to a file using '-o C:\Temp\response.txt' to the argument list. This works fine when used from a command line tool. Executing it from the groovy script results in:
curl: (23) Failed writing body (0 != 386)
I can get around this by just writing the stream to a file. What is really bugging me is that fact that the response does not seem to contain any information in the body. Executing the curl command from windows command line tool returns me a pretty long token as expected.
Andy ideas?
If you use ProcessBuilder, you have to give each parameter as own argument. You give two arguments to the constructor, the program name and the remaining parameters which are taken as one argument, just like if you put quotes around the whole string in the command line. Make fullurl a list instead where each parameter is its own list element and it should work as expected. You can and should leave out any other quoting like you have around the URL though.
Your code can be greatly improved. You shouldn't concatenate the command parts into a single String, just use a List.
Also, the _ prefix on variables is commonly used for private fields or just internals, not method parameters which are clearly not internals.
Using String arrays in Groovy is quite strange, you should definitely learn some Groovy!
Anyways, here's a better version of this code:
def static getUserLogin() {
def url = '"https://some-login.someSystem-dev.someHost.com/someResource.beyond.foobar/login/LoginAUser'
def requestFilePath = '-d #temp/LoginPayload.json'
def heads = "-H 'Content-Type: application/json' -H 'Accept: text/plain' "
def insecure = '-k'
def verbose = '-v'
return ex( [ url, requestFilePath, heads, insecure, verbose ] )
}
/**
*
* #param commands The command + args you want to execute on your shell.
* #param _workingDir Optional: You may specify the directory where the command will be executed. Default is user dir.
* #return Exit value for the process. 0 = normal termination.
*/
static ex( List<String> commands, File _workingDir = new File( System.properties.'user.dir' ) ) {
println "Executing command> $commands \n"
def process = new ProcessBuilder( addShellPrefix( commands ) )
.directory( _workingDir )
.inheritIO()
.start()
process.waitFor()
return process.exitValue().value
}
private static addShellPrefix( List<String> commands ) {
[ 'curl' ] + commands
}

Download file using Wget yammer export data

I create console application that export data from yammer to local using wget
third party tool
and this is the reference
https://developer.yammer.com/docs/data-export-api
the function that execute script:
internal static bool ExecuteScript()
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
Process p = new Process();
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
p = Process.Start(startInfo);
p.StandardInput.WriteLine("wget -O export.zip -t 1 --header \"Authorization: Bearer %Token%\" -ca-certificate cacert.pem https://www.yammer.com/api/v1/export?since=2016-02-09T00:00:00z");
p.StandardInput.WriteLine(#"exit");
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
p.WaitForExit();
p.Close();
Console.WriteLine("Error:" + error);
return true;
}
catch (Exception ex)
{
throw ex;
}
}
i replace %Token% with my token
but when run the code it cut off download and create export.zip file 0KB
it's not download complete file
it show this message in console
Console application output
although i take this script in batch file and run it from cmd in same path it download complete file
notes:
1- I add Wget path to Path Environment
2- I'm using windows 10
3- I'm using VS 2013
i discover the issue
p.StandardInput.WriteLine("wget -O export.zip -t 1 --header \"Authorization: Bearer <Access Token>\" --ca-certificate=cacert.pem cacert.pem https://www.yammer.com/api/v1/export?since=2016-02-09T00:00:00z");

Unable to upload file via REST request in GRAILS

I am trying to upload a file via REST using GRAILS
curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token: d5d7aef8-3964-311b-8b64-4a7a82c52323" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "file1=myfile.jpg" -F "fname=swateek" -F "lname=jena" 'http://localhost:8081/sampleFileREST/document/upload'
Here's how my controller looks like:
class DocumentController extends RestfulController<Document> {
static responseFormats = ['json', 'xml']
def upload() {
def fileLocation="<xml>empty</xml>"
def file = request.getParameter('file1')
def f1 = request.getParameter('fname')
def f2 = "<abc>"+request.getParameter('lname')+"</abc>"
def params = "gf"
if(file.empty) {
fileLocation = "<xml>"+"File cannot be empty"+"</xml><allprm>"+params+"</allprm>"
} else {
def documentInstance = new Document()
documentInstance.filename = file.originalFilename
documentInstance.fullPath = grailsApplication.config.uploadFolder + documentInstance.filename
file.transferTo(new File(documentInstance.fullPath))
documentInstance.save()
fileLocation = "<xml>"+documentInstance.fullPath+"</xml>"
}
/* return "File uploaded to: "+documentInstance.fullPath */
render(text: fileLocation, contentType: "text/xml", encoding: "UTF-8")
}
}
I am able to access the parameters of the request, anything except the file I am sending in the request.
Unable to figure out what's wrong here.
UPDATE
I had used .getParameter() to fetch a file. That's incorrect, the correct way is as below:
request.getFile('<filename>') // without the <>
This might raise an error in IntelliJ as "Symbol Not Found" or "Cannot Resolve Method", please follow the procedure in the answer below.
Damn the IDE that I was using, IntelliJ.
Also, this piece of code while getting the file:
def file = request.getParameter('file1')
should be replaced as
def file = request.getFile('file1')
Now previously, when I was using the request.getFile() method I was getting an "Symbol Not Found" error and it was failing to execute the request.
Solution:
Open IntelliJ
Click on "File"
Find the option "Invalidate Caches/Restart" and wait for IntelliJ to come back again.
If this doesn't work, the other way is mentioned in this answer:
IntelliJ IDEA JDK configuration on Mac OS