Spring web-scoped beans and axis2 - web-services

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.

Related

Configure http basic auth on EJB web service in Wildfly

I work with Glassfish and in glassfish-ejb-jar.xml I'm able to secure ejb exposed web service like this (http basic auth)
<ejb>
<ejb-name>Command</ejb-name>
<webservice-endpoint>
<port-component-name>Command</port-component-name>
<endpoint-address-uri>NPI/command</endpoint-address-uri>
<login-config>
<auth-method>BASIC</auth-method>
<realm>NPI</realm>
</login-config>
</webservice-endpoint>
</ejb>
I'm looking for a similar way to do it when deploying to Wildfly but so far I wasn't able to find a solution.
All I have found is a description how to do it in web.xml but I guess that asks for web services to be exposed via servlet cointainer.
Are there any Wildfly specific deployment descriptors or methods to get the same results as with glassfish ejb descriptor on glassfish server?

How to identify cxf web service end point

I am trying to creating web service using wsdl first approach and CXF. I am able to generate java file from wsdl and deploy the war file to tomcat server. However, I don't see any soapaction in the generated file. How do I identify the end point url for this web service?
thanks,
Usually in CXF you use Spring configuration to configure endpoint, as described in JAX-WS Configuration. Usually address is relative, e.g.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:endpoint id="classImpl"
implementor="org.apache.cxf.jaxws.service.Hello"
address="/helloService"/>
</beans>
Address is local to you web app context root.
Assuming that name of you web application is SomeWebApp and the server is available at localhost:8080 then web service should be published at http://localhost:8080/SomeWebApp/helloService. You can test it retrieving WSDL at: http://localhost:8080/SomeWebApp/helloService?wsdl. This URL can be used to create SOAP UI project (the tool that I really recommend for exploring and testing SOAP services).
If you don't use Spring to configure endpoint or you still can't access web service please provide more details about your configuration.

Starting JAXWS servlet at root of the web context?

Is it possible to start JAXWS servlet at the roor of the web contex, so that the WSDL will be also accessible?
My context root, defined in application.xml is /myapp/webservice/v1 (the last part should be configurable in the deployment descriptor, and the web service should be available in web context root).
I've tried:
<servlet>
<display-name>WebService</display-name>
<servlet-name>WebService</servlet-name>
<servlet-class>my.package.WebServiceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WebService</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
The WebService answers under the address /myapp/webservice/v1, but when I type /myapp/webservice/v1?wsdl, it's converted into /myapp/webservice/v1/?wsdl, which doesn't return WSDL, but it tries to invoke the WebService itself, which answers: "Hello! This is an Axis2 Web Service!" (standard greeting when doing GET to WebService).
I've tried also with url pattern '.'. '' and '/' are not accepted (WebSphere).
When I use
<url-pattern>ws</url-pattern>
and
<welcome-file-list>
<welcome-file>ws</welcome-file>
</welcome-file-list>
the web service works, but the WSDL is available only on /myapp/webservice/v1/ws?wsdl, which makes the solution incompatibile with existing clients.
The reason behind is to create version as separate WARs, which can be then deployed independently or within EAR, and to make WebService address fully configurable, we need to make it accessible under the context root of the Web Module.
I don't know if the problems we are experiencing are WebSphere-specific or Axis-specific...

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

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.

Regarding Spring and Apache CXF Integration

Inside the applicationcontext.xml file we have like this
<bean id="vincent" class="com.bayer.vincent.service.vincent"/>
<jaxws:endpoint
id="vincentSOAP"
implementor="#vincent"
implementorClass="com.bayer.vincent.service.vincent"
address="/vincent/soap"
bindingUri="http://schemas.xmlsoap.org/wsdl/soap/" />
what does this mean by this defination ??
My question is how the vincent class is being getting called ??
CXF has provided a custom spring namespace to help easily configure a webservice endpoint here.
If the implementor starts with a #, CXF makes the assumption that the endpoint is a Spring Bean, the way it is in your case.
The endpoint will have to be a normal JAX-WS endpoint, i.e annotated with #Webservice annotation, eg:
#WebService(serviceName="MemberService", endpointInterface="org.bk.memberservice.endpoint.MemberEndpoint", targetNamespace="http://bk.org/memberservice/")
Now any call to your uri-/vincent/soap, will be redirected by the CXF front controller(which you can register in the web.xml file):
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
which maintains an internal registry of payload uri's to handlers(in this case the Spring bean) and dispatches the request appropriately.
As far I understand there created proxy class which forwards all calls to your real class.
See also Configuring an Endpoint where described all jaxws:endpoint attributes.