Is #WebService annotation a must in service class? - web-services

I have a SOAP web service. For experiment, I removed the #WebService annotation in service class and it's still working without any problem. So I think #WebService annotation is not a must in service class. Am i missing something here. ( I'm using CXF 2.7.7 )

Found This answer from CXF forum. Great place to get help !
http://cxf.547215.n5.nabble.com/Is-WebService-annotation-a-must-in-service-class-td5744739.html#a5744826

Related

Implementing RESTful service and consume xml at the service and map it to a bean class

Can anyone please explain hot to implement RESTful service and post data in an xml and cnsume the xml at the service and map it to a java bean class? It would be better if an example can be posted. I have tried it using a json object using this
http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-resteasy-client-framework/
but not able to do it with an xml
The same site that you tried the json example also provides a RESTEasy + JAXB example. Hope this helps.
Add to your REST methods:
#Consumes("application/xml") and #Produces("application/xml"). Your method would consume/produce XML.

EJB as WebService context-root gone

I'm working on a project with JAX-WS.
When I annotate my endpoint class with #WebService the WSDL is marked in console like
.../<context-root>/XXXService?wsdl
When I add #Stateless on those endpoints the WSDL is not marked in console and the actual address is
.../XXXService/XXXEndpoint?wsdl
Is this normal or expected?
Update
For further readers.
I couldn't find any resolution. I decided not to use mixed #Stateless+#WebService. I split those #EJBs and #WebServices for clear module separation.
What youre experiencing is expected behaviour. It's a different matter if the service s not functional. When an EJB 3.x stateless bean is deployed as a WS, it's naming defaults to what you see there,
Servername/SIBnameService/SIBName.
The reason for this is obvious: EJBs don't operate within the context of a web application and so cannot be addressed as such. You can customise the default name using the serviceName attribute on the #WebService annotation
Look at this from apache

Contract-First Web Services using CXF , Spring and JAX-WS

I am currently looking at redeveloping a web service that is currently written in .Net. I would like to port it across to Java using a CXF, Spring, Hibernate and Maven stack.
The WSDL for the service is already available and is well formed so I would like to reuse rather than redeveloping the interface. This will also mean that the clients will not require significant changes in order to use the new service.
I would like to use a JAX-WS type approach to developing the web service, similar to the Java-first approach at http://cxf.apache.org/docs/writing-a-service-with-spring.html. The only difference being that I would like to follow a contract-first approach and ensure that the exact WSDL is used.
Has anyone attempted this before? Are there any good guides online that I can refer to?
I am actually not seeing in your question what is stopping you from developing it with WSDL first approach.
Check my answer here, for the tutorials you need.
I guess its pretty straight forward (The WS stack part)
1.Create the Implementation stubs using WSDL (contract)
2.Create Client using WSDL
* implement methods using your own logic and syntax
both 1&2 is supported by CXF.
good guides here
and here

Inject generated beans

Let's i have simply #Stateless session bean. (EJB 3.0)
#Stateless
public class SomeBeanWS implements ISomeBeanWS {
// ...
}
And I have many WebServices (that are beans also) that have already deployed on the app server.
I have WSDLs of this Services.
I can generate Interfaces if this WebServices in my project using Maven.
Can I inject this Webservieces (beans) to my SomeBeanWS?
May you're using NetBeans, it provides a "generate WebService from WSDL" tool.
It helped me accessing external WS from within my ManagedBean (by using #WebServiceRef annotation there). Only injecting the WS through a Session Bean doesn't work (see here).
Edit says: I've found a solution, follow the link ;)

What is the best way to consume a web service in Grails?

I know there are a few web service plug-ins for Grails, some of them look like they aren't maintained. I have a jar with all the stubs generated from a wsdl and now I need to start integrating. Which plugin would serve best for this? Also, the web service uses SOAP, not REST.
I know your question asked about a plugin for consuming, but I've never used one of the Grails-WS plugins, so I can't comment there. Instead, if your stubs are compatible with JAXB marshalling you can use the Spring Web Services project. You'll just have to add a dependency in BuildConfig.groovy to import the appropriate jars.
http://static.springsource.org/spring-ws/sites/2.0/reference/html/client.html
So you just define some JAXB marshaller/unmarshaller beans and web service handlers. You can get as detailed as you want with this from the documentation above and define timeouts and security if you specify your own connection handler or interceptors.
myJaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) {
classesToBeBound = ['my.class.Class1','my.class.Class2']
}
myWebServiceMessageFactory(org.springframework.ws.soap.saaj.SaajSoapMessageFactory)
myWebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate, ref('myWebServiceMessageFactory')) {
marshaller = ref('myJaxb2Marshaller')
unmarshaller = ref('myJaxb2Marshaller')
}
At that point you can use Grail's dependency injection to use the WebServiceTemplate in your Grails code:
class myService {
def myWebServiceTemplate
void myMethod {
...
Class1 myRequestObject = new Class1(data:myData)
Class2 myResponseObject = myWebServiceTemplate.marshalSendAndReceive(mySoapEndpoint, myRequestObject)
...
}
}
I would recommend using Spring's way.
You're developing in grails after all, so maybie you don't need a plugin.
Read Spring docs on Remoting and webservices, chapter 19.5.2 "Accessing web services using JAX-RPC".
No need for any of your jar's stubs. Spring will generate everything for you...
P.S. : I assume you know how to declare spring beans in grails...