How can I get access to Servet Context in apache cxf? - web-services

How can I get access to Servlet context in my apache cxf web service application?
I am using apache cxf 2.2.7 and Json as the data transfer format.

Have a look at ServletContextAware interface: Spring beans registered in Web context and implementing this interface get the access to ServletContext. More aggressive approach is to request bean with name servletContext from Web Context or use ServletContextParameterFactoryBean.
Otherwise (if you don't use Spring+CXF, which is unusual) you need to implement javax.servlet.ServletContextListener and register this implementation in <web-app> → <listener> → <listener-class>. The implementation should save ServletContext to be later used by your WebService.

Related

Use CXF client api with Java web application

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

How to create SOAP client with spring application

I need to create a client with WSDL. I have a Java web application with JSF, Spring and JPA. In this application I need to create a form and send the info to the SOAP web service. This service should return another object with status.
Please, any idea I will be grateful
regards
sorry by my english
I assume you have generated classes from the WSDL needed for you client. In Spring it is very simple by using Apache CXF. For e.g.:
<jaxws:client id="yourService"
serviceClass="com.something.YourService"
address="the URL of web service"
username="username"
password="password"/>
And in your class where you need to call this web service just autowire it:
#Autowired
#Qualifier("yourService")
private YourService service;
Take a look at the example: http://cxf.apache.org/docs/writing-a-service-with-spring.html

Spring web-scoped beans and axis2

I want to use spring web-scoped beans in web-service written on AXIS2 framework.
How to configure it?
Axis2 and Spring documentation disagree with each other.
Axis2 documentation says:
For the purpose of this example, we'll configure Spring via a WAR file's web.xml. Let's add a context-param and a listener:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
Spring documentation says:
When using a Servlet 2.4+ web container, with requests processed outside of Spring's DispatcherServlet (e.g. when using JSF or Struts), you need to add the following javax.servlet.ServletRequestListener to the declarations in your web application's 'web.xml' file.
<web-app>
...
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
...
</web-app>
When I use Axis2-recommended ContextLoaderListener with Spring web-scoped beans I got on deploy
java.lang.IllegalStateException: No thread-bound request found: Are
you referring to request attributes outside of an actual web request,
or processing a request outside of the originally receiving thread? If
you are actually operating within a web request and still receive this
message, your code is probably running outside of
DispatcherServlet/DispatcherPortlet: In this case, use
RequestContextListener or RequestContextFilter to expose the current
request.
When I use Spring-recommeded RequestContextListener I got running Web-service with fault on requests:
<faultstring>The SERVICE_OBJECT_SUPPLIER parameter is not specified.</faultstring>
In other words: how to configure AXIS2 with Spring and RequestContextListener?
No such functionality in AXIS2. See request https://issues.apache.org/jira/browse/AXIS2-5467 "Extend Spring support to accept web-scoped beans" for detail.

What is the difference between a Rest WS and Servlet

How do they differ in action? Servlet print html only?
Servlet :
--is a web component
--it's a powerful java technology
--managed by a container (namely web server such as tomcat) that generates dynamic content
--platform independent java classes (byte code)
--interacts with web clients as request response paradigm
--Request handling methods
****doGet,doPost,doDelete,doPut,doOptions,doHead,doTrace****
Rest WS (Representational State Transfer Web Service)
--A way to achieving service oriented architecture in web application
--it's an architectural concept
--web service resource is uniquely identifiable using URLS
--it has explicit relationship with HTTP methods namely GET,POST,PUT,DELETE
--highly re useable across the platform
A Rest WS is a service which you call, which returns data in a REST format.
A Servlet is a bit of UI that shows information to the user.
They are very different, although a Servlet could get the information that it displays from a Rest web service.

ASMX Web Services: Where can I see SOAP and WSDL generating by the platform

Following reference indicates ASP.NET automatically creates a WSDL and SOAP request. Where or through what I can see the nuts and bolts?
http://www.w3schools.com/webservices/ws_example.asp
ASP.net generates the WSDL according to the method(WebMethod) signature along with other web service specific attributes.
For example, the method name is web service operation, serialized parameter of the method is part of SOAP request and serialized return object of the method is part of SOAP response.
Search Related topics for details,
Building XML Web Services Using
ASP.NET XML serialization
Your reference is out of date. You should not use ASMX web services for new web service development. Microsoft now considers them to be "legacy technology". You should use WCF for all new web service development.