I have generate a swagger client api with:
java -jar swagger-codegen-2.2.3/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://localhost:8080/myproject/services/service0/swagger.json -l java -o client/myproject/java
But swagger-codegen rename methods with same names despite the fact that they are in different java clases. Is there any option to solve that issue?
The renaming of method will not affect the URL path and you should be able to make the REST call with the generated UI .
Even i don't know the reason why Swagger code gen works that way .
But i also feel that our API consumers doesn't have to know the method which are called either . So generated UI should be good to go
Related
Currently I am trying to POC OpenTelemetry for a web project (war)
and upon reading lots of different documentations I still don't have a proper grasp on some issues, wonder if someone could help pointing out in right direction?
Basically:
1) Is it possible to have OpenTelemetry without any exporter?
I have used the config to do this (OTEL_TRACES_EXPORTER=none, OTEL_METRICS_EXPORTER=none). Would not having any exporter "work"?
2) Do I need to have a span processor in the SdkTracerProvider for Otel to work?
When building the SdkTracerProvider, I wonder if I MUST set a spanProcessor (like BatchSpanProcessor with LoggingSpanExporter) or if since I don't want to use a exporter, just not set a spanProcessor?
To be honest what I am trying to achieve is:
NOT to use the agent
NOT to use a collector (gateway/local)
NOT to use a exporter
ONLY In logs (logback) populate spanId and traceId (configured currently with %X{trace_id} and %X{span_id}, but not being populated at the moment, so wonder if have to include also code wise manually in every Log)
Not sure if this is something that is possible.
I'm able to achieve what you are trying to achieve using below command and latest java agent and Log4j.
I'm not seeing any export error and can see trace-id and span id in logs.
java -javaagent:opentelemetry-javaagent.jar \
-Dotel.traces.exporter=none \
-Dotel.metrics.exporter=none \
-Dotel.resource.attributes=service.name=Test-service \
-jar spring-app-0.0.1-SNAPSHOT.jar
Followed Document available here.
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/logger-mdc-instrumentation.md
I'm not sure of MDC part whether it works with manual instrumentation as in the above doc it is mentioned about java agent.
I'm able to make transactions in Ethereum using Java and Web3j.
Now I would like to be able to interact with a smart contract. But since i'm having problems building the wrapper, I would like to know if i can do it by sending data in the transaction. And if so, how is it done?
Try these command to build the wrapper:
solc YourSmartContract.sol --bin --abi --optimize -o ./
web3j solidity generate YourSmartContract.bin YourSmartContract.abi -o /path/to/yourSrc/main/java -p your.application.id
Then it will generate a Java file, and you can call the methods from it to interact with your smart contract.
I have no trouble reading files of different types using GDAL's Java bindings (version 2.2.1) via the org.gdal.ogr.ogr.OpenShared(filePath) method to create a DataSource. If I want to create a SQLite file from a DataSource, however, how would I do it?
Looking in the JavaDocs, I've found some ExportTo methods on the Geometry object that you can use to manually build GeoJSON, WKT, KML and others: http://gdal.org/java/org/gdal/ogr/Geometry.html
There doesn't seem to be anything in the Driver class that would let you use them to export a DataSource however.
Using ogr2ogr it would be as simple as running the following:
ogr2ogr -f "SQLite" ./output.sqlite3 ./input.geojson
And there is this technique for running ogr2ogr from within Java, but I would have assumed there'd be something native in the Java bindings.
I've accepted that the best way to do this is to simply include the ogr2ogr.java file from the GitHub repo in my project and wrap it in a function that makes it cleaner to access. It is almost a direct port of the original C++ GDAL file.
The one change I made was to rename the ogr2ogr main function to execute so that it didn't confuse application when I ran it.
So, my JAVA application is connected to different WebServices that were developed inhouse and all 3 of them are packaged under org.tempuri
This is the default namespace I believe and when the wizard creates the Java packages it places them under org.tempuri..
I wanted to change them to give them meaningful names but then my app exploded :(
Can I just go into the .wsdl and change the namespace and repackage it all? Or some way that I can change package "org.tempuri" to "com.abc.ws.imageservices"
I would do a trial and error on my free time, but it would take me a couple of days since the job has other priorities..., so I'm hoping that an answer is faster.
You should look into wsimport.
Wsimport will allow you to import directly from a WSDL and one of the parameters in the output project.
wsimport -p com.abc.ws.imageservices -d src/ -wsdllocation http://my.wsdl.com/location?WSDL
If you're using RAD or WID, yes.. it can be done really fast if you refactor the namespace (which would change the WSDL) and then you just have to regen.
I read Runtime.getRuntime().exec("perl script.pl") is an option, but is this the best way to do it?
I'll need an answer from that script, so I'll have to read the script's return in some cases, although I might read it from a text file on other cases.
Anyway, is exec() a good way of calling a Perl Script from Java? I should note, I'm working on a Java Web Application, so security is an issue here.
You can use Runtime.getRuntime().exec() or use the Process API.
The Process API allows you to get the output of the script, so you can have both communicate.
exitValue() and getInputStream() seems to be what you need.
This outlines how to do it fairly elegantly, though it may be more effort than it's worth:
http://search.cpan.org/~nwclark/perl-5.8.9/jpl/docs/Tutorial.pod
Overview:
Well-supported by JPL, but it is a complicated process:
The JPL preprocessor parses the .jpl file and generates C code wrappers for Perl methods. It also generates Java and Perl source files.
The C compiler compiles the wrapper and links it to the libPerlInterpreter.so shared library, producing a shared library for the wrapper.
The Java compiler compiles the Java source file, which uses native methods to load the wrapper.
The wrapper connects the Java code to the Perl code in the Perl source file.
Fortunately, a generic Makefile.PL simplifies the process. This is a Perl script that generates a Makefile for you.
exec() is likely the best option and you can catch it's return value with exitValue(). You might also be interested in Inline::Java.
-John
keep in mind, whatever file the Perl script create, it is created in the Java working folder. just refer to that file as './myPerlCreatedFile.ext'