I have created Java RESTFUL web services using Apache karaf, I am using swagger for API documentation.All Annotation are applied and its running successfully on single OSGI bundle with the general swagger configuration(Swagger core and annotation jar) with apache karaf on standalone mode.
Issue :- While running swagger on multiple OSGI bundles, it is catching the result generated while hitting "/api-docs" on the very first WSDL and returns the same for other WSDL's as well.
Description:-
Let us consider if i have two web services exposed as below
1) "http:/localhost:8181/cxf/abc?_wadl"
2) "http:/localhost:8181/cxf/xyz?_wadl"
Both the web services are exposed on two different OSGI bundles and all the configuration are written in respective "bluprint.xml" files.Swagger core and swagger-annotation dependencies are located in each project's pom.xml.
When i run swagger api on first WSDL ie "http:/localhost:8181/cxf/abc/api-docs"
it returns the result successfully but on hitting swagger on second WSDL ie.
"http:/localhost:8181/cxf/xyz/api-docs"
it returned the same result which was initially produced by the first WSDL. It cached the first WSDL json and always return the same(some where it cached my initial json result).
My Questions:-
1 - Is there any other way to run swagger API on Multiple OSGI bundles using Apache Karaf ?
2 - Is there any way, We can permanently disable the caching using karaf/swagger Configuration ?
3 - Is there any method to clear swagger cache( which got created when i made a hit to http:/localhost:8181/cxf/abc/api-docs) when hitting swagger for next OSGI bundles("http:/localhost:8181/cxf/xyz/api-docs"), So it rescans the API Annotations and does't return me the cached result.
Note : - i have implemented the swagger API on OSGI bundles using :- https://github.com/ddragosd/jax-rs-on-karaf
You can try to run your service using CXF and the CXF Swaggger feature.
Related
I have a question regarding the WSO2 ESB callout mediator using an individual Axis2 configuration file. I would like to have the individual Axis2 configuration to be deployed using a carbon application. Unfortunately the callout mediator doesn't seem to be able to read the Axis2 configuration from the registry. I'm getting an error that the file axis2_blocking_client_proxy.xml can't be resolved when I deploy the carbon application that contains the mediation with my callout mediator.
The deployment works when I Quote a relative file path that points to the configuration file. Does anybody know if there is a way to tweak carbon application files so that distinct resources will be written to a dedicated directory on the WSO2 ESB Server?
Best regards,
Heiko
AFAIU, your requirement is to deploy an axis2 configuration file using a CAR (carbon application) file. This is not a recommended approach. If you need to deploy a configuration file in to the ESB, you can deploy that during the server creation time. CAR files are used to deploy the actual implementation code rather than the static configuration files.
How to consume Web service suing Apache CXF client API.
I have generated the client Code using eclispe but I didn't found any document specifying how to use that generated code in my web application.
How to configure CXF? I am using tomcat to run my java web appliation.
How to use the generated code?
Do I need to add anyhting in my my web.xml?
I have downloaded CXF binaries from apache CXF website but don't know which libraries are needed. I am affraid i may end up adding all the jars.
I am using Tomcat 7, Java 1.6 and plane jsp/Servlet for my application
I am new to web services.
Thanks in advance
One sample code that may help.
URL wsdlurl=SOAPWebServiceTransport.class.getClassLoader().
getResource("my.wsdl");
// MyService will be one of the service class that you have generated (with different name ofcourse)and which must be extending Service class
//getOnlineServicePort will be a method (with different name ofcourse) in your service class which will give you the interface referrer using which you'll call the webservice method
OnlinePort service= new MyService(wsdlurl).getOnlineServicePort();
Client proxy = ClientProxy.getClient(service);
//configure security user name password as required
//Add interceptors if needed
//Now you can directly call the webservice methods using the service object
service.method(parameter)
you can also refer to some example one is here
I'm embedding Jetty 9.1 from within a Java application. I'm configuring everything programmatically; I am not using web.xml or Spring or anything else. I have Wicket mapped to /* and a RestEASY JAX-RS API mapped to /rest/*. That's all working fine.
I wanted to add HTTP authentication, so I added the following (based upon as much Jetty documentation as I find):
HashLoginService loginService = new HashLoginService();
loginService.setName("My Realm");
loginService.setConfig("src/main/resources/realm.properties");
server.addBean(loginService);
I added a user with a role of admin to realm.properties. Then I tried to configure my REST service, putting the following annotation on my main JAX-RS resource:
#RolesAllowed({ "admin" })
Then I added the following annotation to my main Wicket page:
#AuthorizeInstantiation("admin")
None of these changes made any difference; I can still use my browser to navigate to my REST API and Wicket pages.
I'm guessing I need to turn on DIGEST authentication in Jetty. But how do I do that programmatically, without a web.xml file? What else do I need to do?
Another answer to a similar question, providing a link to a sample webapp, helped me immensely and got me up and running.
In Jetty v7, you chain the handlers together:
server.setHandler(securityHandler);
securityHandler.setHandler(resourceHandler);
Works on my machine! (tm)
I'm refering to the following article
http://wso2.com/library/articles/2010/10/using-xacml-fine-grained-authorization-wso2-platform/
I would like to use the sample echoService from the WSO2 AS over a secured proxy in WSO2 ESB in combination with the Identity Server for fine-grained authorization. All the settings mentioned on this page seem to work, however I am stuck concerning the client part. I use NetBeans and the given client code, but the .jars in the classpath there have older versions then the ones in the current version of WSO2 IS, so I started to exchange them manually. Now I get some exceptions like
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.xml.security.transforms.Transform.init()V
and I am stuck again. I just want to test the echoService in this constellation and send some string over the ESB via IS and receive the response(if I have the appropriate role) from the AS, is there not another client or how could I test it else?
Thank you!
I can suggest you 3 options:
Use SoapUI to test the service which is the easiest way to test a web service.
Generate the stub for the service and have stub as the dependency in your client. You can use the WSDL2Java tool that ship with AS. Loging to AS --> Tools in left pane --> WSDL2Java --> Provide the wsdl URL and generate the stub jar.
Generate correct dependency libs. Go to [IS-Home]/bin folder, and issue that command "ant" to run the build.xml, this will copy all required libs to [IS-HOME]/repository/lib/ folder. Have them in your class path.
I have developed a REST web application using apache cxf library. I am able to access them using a browser and test. I want to write unit tests for the services.
I tried testing it using embedded Jetty server with cxf.
After starting the Jetty server, I am getting a proxy using WebClient API of cxf. The relevant code is
WebClient client = WebClient.create(ENDPOINT_ADDRESS);
client.accept("text/xml");
client.path("/studyservice/topimstudydetails");
client.replaceQuery("pnlId=3&lclId=30&indId=442&maxImStudies=99&rName=DEV");
TopIMStudyDetailsResponse resp = client.get(TopIMStudyDetailsResponse.class);
assertEquals(resp.getStatus().getReturnCode(),0);
The call to the service is successful as I can see the logs, but I'm get a null pointer where the service is trying to make a dao call. The dao is declared as a dependency for the service. How can we get a proxy with all the dependencies injected ?
May be you'll find the following posts helpful:
http://tarlogonjava.blogspot.co.il/2011/12/running-integration-test-using-with.html
http://tarlogonjava.blogspot.co.il/2011/12/running-integration-tests-using-with.html
The second post is about replacing the data source with a special in-memory data source for tests.