Configuration: Java 7, Eclipse - Juno, Jboss7.1.1 , Ant.
Considerations:
As Jboss7.1.1. already comes with CXF integrated, there is no need to include ANY libraries in the war file!.
Too good to be true? Well, you do need the jars for compilation :-)
Code:
1. Webservice (Service)
http://localhost:9990/console
Considerations:
As Jboss7.1.1. already comes with CXF integrated, there is no need to include ANY libraries in the war file!.
Too good to be true? Well, you do need the jars for compilation :-)
Code:
1. Webservice (Service)
package com.commonground.mobile.webservices.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface HelloWorldService {
@WebMethod
public String sayHello(String name);
}
2. Webservice Implementation
package com.commonground.mobile.webservices.service.impl;
import javax.jws.WebService;
import com.commonground.mobile.webservices.service.HelloWorldService;
@WebService(endpointInterface = "com.commonground.mobile.webservices.service.HelloWorldService", serviceName = "HelloWorldServiceImpl")
public class HelloWorldServiceImpl implements HelloWorldService {
public String sayHello(String name) {
// TODO Auto-generated method stub
System.out.println("got name: " + name);
return name;
}
}
3. web.xml
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>HelloWorldService</display-name>
<servlet>
<servlet-name>HelloWorldServiceImpl</servlet-name>
<servlet-class>com.commonground.mobile.webservices.service.impl.HelloWorldServiceImpl</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldServiceImpl</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
4. Build the war file(I called it mobile-ws) and deploy on Jboss7.1.1 application server.
Shut down the server from either the service or manually.
Make sure that your .war is NOT exploded, otherwise it will not work.
You can simply copy it to
<Drive>:\<JbossFolder>/jboss/standalone/deployments
On starting the application server from either the windows Service or manually,
you should see the server up and running by using this url:
Test your Webservice by pointing to:
http://localhost:8080/<name of application>?wsdl
You should see the response when you enter the above url:
<wsdl:definitions xmlns:ns1="http://service.webservices.mobile.commonground.com/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:tns="http://impl.service.webservices.mobile.commonground.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloWorldServiceImpl"targetNamespace="http://impl.service.webservices.mobile.commonground.com/">
<wsdl:import location="http://localhost:8080/mobile-ws?wsdl=HelloWorldService.wsdl" namespace="http://service.webservices.mobile.commonground.com/"></wsdl:import>
</wsdl:definitions>
Finally Test Client:
package client.com.commonground.mobile.webservices.client;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.commonground.mobile.webservices.service.HelloWorldService;
public class Client {
public static void main(String args[]) throws Exception {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(HelloWorldService.class);
factory.setAddress("http://localhost:8080/mobile-ws");
HelloWorldService client = (HelloWorldService) factory.create();
System.out.println("Server said: " + client.sayHello("cacamare"));
}
}
Remember that the standalone.xml DOES not have the http and https sockets enabled:
You can modify it before deployment by adding these 2 lines :
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
<socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
<socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
<socket-binding name="ajp" port="8009"/>
<socket-binding name="http" port="8080"/>
<socket-binding name="https" port="8443"/>
<socket-binding name="osgi-http" interface="management" port="8090"/>
<socket-binding name="remoting" port="4447"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
<outbound-socket-binding name="mail-smtp">
<remote-destination host="localhost" port="25"/>
</outbound-socket-binding>
</socket-binding-group>
Comments/suggestions are welcome.
ReplyDelete