Web Services com Spring e Apache CXF
Criação de Web Services com Spring Framework e Apache CXF


Last updated
Criação de Web Services com Spring Framework e Apache CXF


Last updated
package br.com.web.store.webservice;
import java.util.List;
import br.com.web.store.dto.InGameDTO;
import br.com.web.store.dto.OutGameDTO;
public interface WebStoreService {
public List<OutGameDTO> listarJogos();
public OutGameDTO buscarJogo(InGameDTO produtoDTO);
public void desabilitarProduto(Integer id);
}
package br.com.web.store.webservice;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.springframework.scheduling.annotation.Async;
import br.com.web.store.dao.ProdutoRepo;
import br.com.web.store.dto.InGameDTO;
import br.com.web.store.dto.OutGameDTO;
@WebService
public class WebStoreServiceSoap implements WebStoreService {
private ProdutoRepo repo = new ProdutoRepo();
@WebMethod
public List<OutGameDTO> listarJogos() {
return repo.getListajogos();
}
@WebMethod
public OutGameDTO buscarJogo(InGameDTO produtoDTO) {
return repo.obterJogo(produtoDTO).get();
}
@Async
@WebMethod
public void desabilitarProduto(Integer id) {
System.err.println("Produto Desabilitado com Sucesso!");
}
}<?xml version="1.0" encoding="UTF-8"?>
<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-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="webStoreServiceSoapBean" class="br.com.web.store.webservice.WebStoreServiceSoap" />
<jaxws:endpoint id="webStoreServiceSoap"
implementor="#webStoreServiceSoapBean"
address="/service/WebStoreServiceSoap"
publish="true"
publishedEndpointUrl="http://localhost:8080/app-service-store-ws-cxf/service/WebStoreServiceSoap" />
</beans>// trecho de código omitido
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/webservice-definition-beans.xml</param-value>
</context-param>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
<url-pattern>/service</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>