How to secure a SOAP web service with WSS with CXF - java

My application has a SOAP web service implemented using Apache CXF. I'm not using Spring or EJB, it's just a simple web application deployed in an application container (Payara). The web service is configured through web.xml and sun-jaxws.xml and deployed automatically. It's completely written by source code with annotations (#WebService, #WebMethod, etc) without any pre-existing WSDL file.
I need to secure it with WS-Security but I can't find how...
The most promising solution is configuring an out interceptor as this page indicates, but I don't know how to get an instance of Server or Endpoint of my deployed WS. If I use the ServerFactoryBean class, I'm creating a new Server object, but will this help me if my WS is deployed by the container?
So, how can I obtain a org.apache.cxf.endpoint.Server? Other ways of adding security to my WS?

I haven't had to build a service yet, only a consumer but you may want to take a look at the Apache CXF examples available on github under the ws_security directory.
Apache CXF Examples Page
Apache CXF GitHub Examples Repo

Related

How can I use another rest client than jersey in an OSGi environment?

I am currently trying to deploy an application to Apache Felix that can access an external rest webservice. I am using jax-rs for that and Apache CXF as the rest client, so my code looks somehow like this:
ClientBuilder.newClient().target("http://my-endpoint.com/")
.path("path-to-api/")
.request(MediaType.APPLICATION_JSON_TYPE)
.get();
I have already deployed the Apache CXF rest client as an osgi bundle, but still I am getting the following exception: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder cannot be found. The application works in a unit test and also when I directly use the implementation org.apache.cxf.jaxrs.client.WebClient instead of the interface javax.ws.rs.client.Client. How can I use another rest client than jersey in an osgi environment?
I already found the solution by myself. The problem was that I used the dependency org.apache.aries.javax.jax.rs-api instead of javax.ws.rs-api.

What is the relationship between Apache Tomcat and Apache Axis2 in the context of RESTful API and WSO2

I know I want to build a RESTful api and use Angular on client side. I am choosing between server technologies. Apache Tomcat can do RESTful web services and could do for years now. I was wondering if Axis2 is meant to be replacement for Tomcat. Also I have been encouraged to incorporate WSO2 middleware which uses Axis2. Ideally I'd like to use REST on Axis2 and then WSO2 middleware.
What is the relationship between Apache Tomcat and Apache Axis2 in the context of RESTful API and WSO2? Does Axis2 run within Tomcat?
Apache tomcat is an application server whereas Axis 2 is a Web Services engine.
So no, Axis2 is not meant to be replacement for Tomcat. An application built with Axis2 can be deployed on Tomcat or any other compatible Application Server(AS).
So yes, Axis 2 can run within Tomcat.
WSO2 is irrelevant to your question. Middleware includes Web servers, application servers, content management systems, and similar tools that support application development and delivery.
For a quick description Apache Tomcat is a web server and more precisely a servlet container that allows you to handle HTTP resquest inside servlet.
Apache Axis 2 is a librairy that can handle web services (SOAP and RESTFull), it can run on a server such as Tomcat.
For REST API you can use WSO2 ESB or WSO2 API Management...also if you want to build a restful service you can create a webapp with JAX-RS and deploy it in WSO2 Application Server. As WSO2 Application server use Apache Tomcat you donĀ“t require an Apache Tomcat Server.

Developing Restful Web Service with JAX-WS/Axis2

I'm new with Restful Web Services and got some questions about some of the requirements needed to create one.
1) I got only Apache2 installed on machine and I can't install any EE Server. Is it possible in this circumstances create Restful Web Service? What is better in my case Axis2 or JAX-WS?
2) I want to make the content of some file accessible to Internet, so I need to create the function which is going to be called by client and return for example XML from file? Is there any way to share directly the files using URL mapping?
Thanks a lot!
1) you can't install any EE Server, OK. If you can install Apache Tomcat, use mod_jk so that Apache can redirect some requests to Tomcat. In this case you can use Apache Axis2, Apache CXF or METRO (mainly SOAP services) or Jersey (for RESTful services). On the other hand, if you can't install tomcat, try PHP with Zend Framework to develop web services;
2) with RESTful web services you can return any resource (a file content) to the user using XML or JSON.
Best regards,
Romualdo.

Apache CXF and Spring MVC

I have set up a CXF web service which works well. My service primarily loads data from an ftp to a db.
I would like to create a web interface through which the invoker can view the progress of their package. I thought it would be easy to integrate Spring MVC with CXF but there doesn't seem to be any good solution. I searched all over the net and could not find any thing simpler than this http://ayax79.wordpress.com/2009/02/19/making-spring-mvc-and-cxf-play-well-together/
The reason I would like to integrate Spring MVC with CXF and not create a stand alone web interface is because I have some custom Spring beans with in the CXF service which I can make use off to start and stop the process.
Is it that difficult to build an interface on CXF? Or am I just not thinking in the right direction?
The article you linked to has more to do with handling 1) web requests and 2) CXF requests within the same webapp, i.e. building a web application which can accept traditional http requests for MVC pages and also accept web service requests.
The author of that article seems to be pretty confused about Spring and how ApplicationContexts work, as the commenter Felix provides a good and simple solution for what the original author wants to accomplish (reuse the same bean definitions and instances within two contexts, having some URLs mapped to DispatcherServlet and other URLs mapped to a CXF dispatcher).
If you simply want your Spring MVC web application to be able to interact with and make requests to a CXF service, this is simple - you write code to consume the services as you would in any other type of application that interacted with a CXF/Soap/etc web service.
I'd recommend taking a look at the following sections in the Spring manual about access JAXRPC or JAXWS web services:
Accessing web services using JAX-RPC
Accessing web services using JAX-WS
Another option that you have is to simply generate client proxies for your CXF service using a tool like wsdl2java. Note that the next two options on this page I linked to, "JAX-WS Proxy" and "JAX-WS Dipatch APIs" do the same thing functionally as the Spring option above (creating a dynamic proxy at runtime).

Embedded Jetty and SOAP

I am trying to run an embedded Jetty and would like to expose a soap webservice. The project is loaded as a WAR generated by netbeans. The webservice is generated from a WSDL. What is the simplest way to add SOAP support to embedded Jetty
The axis2 web services framework can be deployed as a normal web application onto your embedded Jetty instance.
It provides a framework for the execution of your web service. You can embed such services within the Axis2 war file or deploy them separately .aar files (Special Axis2 archive file format)
It seems like there is a bridge to use JAX-WS with Jetty. Though I never use it personally.

Categories