How to cache JAX-WS stub/port in Java? - caching

The use case is that the application (running on JBoss 5) must operate on very limited bandwidth. Currently every time we go to make a webservice call we request the wsdl and recreate the stub using JAX-WS. Each time the stub is created the wsdl and schema is redownloaded. Idealy the wsdl would never be downloaded since we already have a copy of the schema, but even caching would work. Bonus points if the cache is Serializable!
Is it possible to cache a JAX-WS stub/port?

Best answer found so far:
Tell the service to look at a local wsdl:
JAX-WS client : what's the correct path to access the local WSDL?
Change the endpoint on the fly:
JAX-WS Loading WSDL from jar
I don't see a way to cache, but using a local copy can be done as specified on this page on metro: Developing client application with locally packaged WSDL
(found on SO question : How to cache a WSDL with Java-WS)

I think we can cache stub using org.apache.commons.pool2.impl.GenericObject lirbrary.
Please see the below link for the same.
https://github.com/vikashnitk50/fasypay-webservice-client/tree/master/fasypay-webservice-client/src/main/java/com/fastpay/webservice/client

Related

How to use grpc with spring boot

I am new in grpc i don't know how to use it with spring boot but using the below link
https://github.com/saturnism/grpc-java-by-example/tree/master/simple-grpc-server
https://github.com/saturnism/grpc-java-by-example/tree/master/simple-grpc-client
note* : - first is for server project and second is for client project.
i have created a project on grpc with spring boot but i can'nt getting understand one thing in this that in grpc client project how can i use classes which are generated by protobuf in the project of grpc server. because it is not creating any proto file in grpc client project then how can i use the classes of grpc server project in grpc client project or can we create one project for grpc server and client instead of creating a diffrent project for both.
I have two queries to ask related to this question one:-
1. How to use classes of grpc generated by protobuf compiler in another project like if client and server are two different project and only server have proto generated files and client wants to use same classes.
How can i create all these thing in a single project means client and server in one project and then how can i run this project with step by step demo.
There are two ways you can do this:
Copy the .proto files between the two projects, and have each one generate their own copies of the generated code. This is probably the easiest, and allows you to avoid checking in the generated code into source control. The downside to this approach is that the .proto files can get out of date if you modify one and not the other.
Keep the .proto in the same repository of both the client and server, and make both depend on the generated code. This allows the proto to be modified for the client and server at the same time, but requires the code to live in the same repository (this is sometimes called the "Monorepo" approach). The downside to this is that the client and server repos may get too big, and need to be split up.
Google (the author of Protobuf) typically uses option #2, but many users of Protobuf prefer option 1. I would highly recommend regenerating the classes each time, and not check in the generated code. The ABI of Protobuf classes can change occasionally, and you would lose the backwards compatibility of Protobuf.
I have created a sample spring boot grpc application and posted in here
https://javabelazy.blogspot.com/
use the dependency net.devh.grpc-server-spring-boot-starter in your pom
create a protofile (sample service code)
service PingPongService {
rpc ping(PingRequest) returns (PongResponse) {
option (google.api.http) = { get: "/v1/grpc/{ping}" };
}
generate stubs for proto file using io.grpc:protoc-gen-grpc-java:1.30.0:exe
use nettyserver
set the port to 9090 (default) grpc.server.port=9090 in application properties
I have used https://github.com/yidongnan/grpc-spring-boot-starter recently. You will get most of the spring features along with grpc using this library.
There is yidongnan/grpc-spring-boot-starter (DOC) which implement springboot autoconfiguration starter for both client and server.
It implements #GrpcServer and #GrpcClient.
#GrpcService, which will add service to grpc server and start server automatically.
Annotation that marks gRPC services that should be registered with a gRPC server.
If spring-boot's auto configuration is used, then the server will be created
automatically. This annotation should only be added to implementations of
BindableService (GrpcService-ImplBase).
#GrpcClient, which will create channel and stub for client automatically
Example: #GrpcClient("myClient") <-> grpc.client.myClient.address=static://localhost:9090
nils server sample
nils client sample
Based on these samples, I also implement my simple server and client sample:
ppdouble/springboot-grpc-server-sample
ppdouble/springboot-grpc-client-sample
You can based on those samples implement your project or implement a new springboot autoconfiguration starter.

Create a web service client in Hybris

Im new in Hybris and I need to build a web service client that consumes a web service rest.
Someone have an example? or something that give me an idea, I dont know if is the same like build a web service client in spring.
Thank you.
For REST you can use the default Spring framework for rest client. See this tutorial. here You can create a new extension or use one of yours. See below for more info.
I used Apache Axis2 for consuming the WSDL (the web service). There are a lot of examples and tutorials on the internet for this. It can easily be integrated in Hybris.
The clearest solution is to create another extension using extgen
. Some tips here . You have to modify other the
extensioninfo.xml file of the other extension, where you want to use
the client. (more info in the link above).
The easiest solution is to just add the axis2 lib to the extension
you want to handle the client and use it there. If you want to play
around and test it as a prove of concept, you can do that. Later you
can move it to a separate extension.

JMeter - Test all APIs in the deployed war file

I want to do load testing of all APIs in the deployed war file of my Spring-boot project. Is it possible to configure JMeter to test all APIs in the war ? Or is there a way to programatically get all API names (RequestMapping) in the war file ?
If it is running API already (as you said it is deployed war file) you have to know the endpoints (in case you don't, you have to refer to documentation of API, if you are developer of that API you have to have documentation and of course know the endpoints, for documentation refer to here https://www.blazemeter.com/blog/how-to-automatically-document-api-endpoints-via-swagger as a starter)
When you find out the information about your endpoints (endpoints, authentication, expected body in case of post, accepted content type and etc) you can use JMetter UI and create your scenarios and also, you can refer to BlazeMeter and get much more help in real time.
Hope it answered your question and solved your problem

SOAP WS-Security Header not created when Axis2 Web Service is invoked from OSGi Client

We are using Axis2 and Rampart for SOAP web services. When a normal client invokes the stub, the SOAP message is properly created ( with WS-Security headers ) and serviced at the server. When we wrap the client ( along with the WS Stub and dependencies ) in a bundle and execute under OSGi ( Felix Karaf ) the header is not generated and this results in the Server returning a SoapFault.
The things that I have tried are
Confirmed that the mar file is being accessed and rampart is "engage"d in OSGi
Confirmed the version of all the jars being used
Checked the SOAP message that is sent - noticed two differences
the message from the standard client had the namespaces declared and abbreviated while the OSGI version had the namespaces in every node
the OSGI message did not have the WS-Security Header
I have used a composite OSGI bundle which includes all the dependent non-OSGI jar files within the one bundle.
Edit 1 - after further investigation through the axis2 / rampart code
I debugged the code side by side within OSGI and directly on JVM and noticed that the point of divergence is where axis engine while loading the "Security" handler invokes rampart and rampart goes with the default policy file instead of the mar file that was specified in "axis.repo.path". I was then looking at the loading of the policy by rampart - noticed it was not loading the configured policy but could not identify the issue.
Any insights would be appreciated.
Regards
Hari
I guess that ws-security is implemented using some kind of plugin mechanism in Axis. Probably this mechanism is not working in OSGi.
I suggest to try CXF instead. It works very well in OSGi.

In OSB when there are WSDL updates in the web service

In OSB when the webservice WSDL gets updated and the proxy service and business service has the old WSDL, does OSB generate an error if the WSDLs do not match?
It depends of the nature of changes that occurs in WSDL.
There are some changes that are tolerable such as adding a method. Other are not, such as removing a compulsory input parameter .
I advice you to use 'membrane' , it's nice tools that can help you to see if there is any bad regression in your WSDL document
http://www.membrane-soa.org/soa-model/
Refresh workspace and Reopen ProxyService.

Resources