IDEMPIERE-1182 Adding REST web-services support. Adding a simple rest mapping (jaxrs) for the current model base ad services.
This commit is contained in:
parent
eab98bfc54
commit
c6211c7241
|
@ -22,5 +22,6 @@
|
|||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="WEB-INF/src"/>
|
||||
<classpathentry kind="lib" path="WEB-INF/lib/jsr311-api-1.1.jar"/>
|
||||
<classpathentry kind="output" path="WEB-INF/classes/"/>
|
||||
</classpath>
|
||||
|
|
|
@ -78,8 +78,12 @@ Bundle-ClassPath: .,
|
|||
WEB-INF/lib/aopalliance-1.0.jar,
|
||||
WEB-INF/lib/idempiere-xmlbeans-1.0.jar,
|
||||
WEB-INF/lib/axis.jar,
|
||||
WEB-INF/lib/commons-discovery-0.5.jar
|
||||
Export-Package: javax.wsdl,
|
||||
WEB-INF/lib/commons-discovery-0.5.jar,
|
||||
WEB-INF/lib/jsr311-api-1.1.jar
|
||||
Export-Package: javax.ws.rs,
|
||||
javax.ws.rs.core,
|
||||
javax.ws.rs.ext,
|
||||
javax.wsdl,
|
||||
javax.wsdl.extensions,
|
||||
javax.wsdl.extensions.http,
|
||||
javax.wsdl.extensions.mime,
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?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:jaxrs="http://cxf.apache.org/jaxrs"
|
||||
xmlns:jaxws="http://cxf.apache.org/jaxws"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://cxf.apache.org/jaxrs
|
||||
http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||
|
||||
<import resource="classpath:META-INF/cxf/cxf.xml" />
|
||||
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
|
||||
|
||||
<!-- JAX-RS -->
|
||||
<jaxrs:server id="idempiereRest" address="/rest">
|
||||
<jaxrs:serviceBeans>
|
||||
<ref bean="ModelADServiceBean" />
|
||||
<ref bean="CompositeServiceBean" />
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<ref bean="xmlBeansProvider" />
|
||||
</jaxrs:providers>
|
||||
</jaxrs:server>
|
||||
|
||||
<bean id="ModelADServiceBean" class="org.idempiere.adinterface.ModelADServiceImpl" />
|
||||
<bean id="CompositeServiceBean" class="com.trekglobal.ws.CompositeServiceImpl" />
|
||||
|
||||
<bean id="xmlBeansProvider"
|
||||
class="org.apache.cxf.jaxrs.provider.xmlbeans.XMLBeansElementProvider" />
|
||||
</beans>
|
|
@ -5,10 +5,17 @@ import javax.jws.soap.SOAPBinding;
|
|||
import javax.jws.soap.SOAPBinding.ParameterStyle;
|
||||
import javax.jws.soap.SOAPBinding.Style;
|
||||
import javax.jws.soap.SOAPBinding.Use;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.idempiere.adInterface.x10.CompositeRequestDocument;
|
||||
import org.idempiere.adInterface.x10.CompositeResponsesDocument;
|
||||
|
||||
@Path("/composite_service/")
|
||||
@Consumes("application/xml")
|
||||
@Produces("application/xml")
|
||||
@WebService(targetNamespace="http://idempiere.org/ADInterface/1_0")
|
||||
@SOAPBinding(style=Style.RPC,use=Use.LITERAL,parameterStyle=ParameterStyle.WRAPPED)
|
||||
public interface CompositeService {
|
||||
|
@ -18,5 +25,7 @@ public interface CompositeService {
|
|||
* @param reqs
|
||||
* @return CompositeResponsesDocument
|
||||
*/
|
||||
@POST
|
||||
@Path("/composite_operation")
|
||||
public CompositeResponsesDocument compositeOperation(CompositeRequestDocument reqs);
|
||||
}
|
||||
|
|
|
@ -87,7 +87,8 @@ public class CompositeServiceImpl extends AbstractService implements CompositeSe
|
|||
return ret;
|
||||
}
|
||||
|
||||
ModelADServiceImpl modelADService = new ModelADServiceImpl(ctx);
|
||||
ModelADServiceImpl modelADService = new ModelADServiceImpl(jaxwsContext, jaxrsContext);
|
||||
|
||||
|
||||
String trxName = Trx.createTrxName(webServiceName);
|
||||
|
||||
|
|
|
@ -35,6 +35,10 @@ import javax.jws.soap.SOAPBinding;
|
|||
import javax.jws.soap.SOAPBinding.ParameterStyle;
|
||||
import javax.jws.soap.SOAPBinding.Style;
|
||||
import javax.jws.soap.SOAPBinding.Use;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.idempiere.adInterface.x10.ModelCRUDRequestDocument;
|
||||
import org.idempiere.adInterface.x10.ModelGetListRequestDocument;
|
||||
|
@ -44,28 +48,49 @@ import org.idempiere.adInterface.x10.RunProcessResponseDocument;
|
|||
import org.idempiere.adInterface.x10.StandardResponseDocument;
|
||||
import org.idempiere.adInterface.x10.WindowTabDataDocument;
|
||||
|
||||
@Path("/model_adservice/")
|
||||
@Consumes("application/xml")
|
||||
@Produces("application/xml")
|
||||
@WebService(targetNamespace="http://idempiere.org/ADInterface/1_0")
|
||||
@SOAPBinding(style=Style.RPC,use=Use.LITERAL,parameterStyle=ParameterStyle.WRAPPED)
|
||||
public interface ModelADService {
|
||||
|
||||
/* Model oriented web services */
|
||||
|
||||
@POST
|
||||
@Path("/set_docaction")
|
||||
public StandardResponseDocument setDocAction(ModelSetDocActionRequestDocument req);
|
||||
|
||||
@POST
|
||||
@Path("/run_process")
|
||||
public RunProcessResponseDocument runProcess(ModelRunProcessRequestDocument req);
|
||||
|
||||
@POST
|
||||
@Path("/get_list")
|
||||
public WindowTabDataDocument getList(ModelGetListRequestDocument req);
|
||||
|
||||
@POST
|
||||
@Path("/create_data")
|
||||
public StandardResponseDocument createData(ModelCRUDRequestDocument req);
|
||||
|
||||
@POST
|
||||
@Path("/update_data")
|
||||
public StandardResponseDocument updateData(ModelCRUDRequestDocument req);
|
||||
|
||||
@POST
|
||||
@Path("/delete_data")
|
||||
public StandardResponseDocument deleteData(ModelCRUDRequestDocument req);
|
||||
|
||||
@POST
|
||||
@Path("/read_data")
|
||||
public WindowTabDataDocument readData(ModelCRUDRequestDocument req);
|
||||
|
||||
@POST
|
||||
@Path("/query_data")
|
||||
public WindowTabDataDocument queryData(ModelCRUDRequestDocument req);
|
||||
|
||||
public StandardResponseDocument createUpdateData(ModelCRUDRequestDocument req);
|
||||
@POST
|
||||
@Path("/create_update_data")
|
||||
public StandardResponseDocument createUpdateData(ModelCRUDRequestDocument req);
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import javax.jws.WebService;
|
|||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.WebServiceContext;
|
||||
|
||||
import org.apache.cxf.jaxrs.ext.MessageContext;
|
||||
import org.apache.xmlbeans.StringEnumAbstractBase.Table;
|
||||
import org.compiere.model.Lookup;
|
||||
import org.compiere.model.MColumn;
|
||||
|
@ -147,9 +148,10 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
|||
log.info("Creating session object ADService");
|
||||
}
|
||||
|
||||
public ModelADServiceImpl(WebServiceContext ctx)
|
||||
public ModelADServiceImpl(WebServiceContext soapContext, MessageContext jaxrsContext)
|
||||
{
|
||||
this.ctx =ctx;
|
||||
this.jaxwsContext = soapContext;
|
||||
this.jaxrsContext = jaxrsContext;
|
||||
|
||||
log.info("Creating session object ADService");
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Properties;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.WebServiceContext;
|
||||
import javax.xml.ws.handler.MessageContext;
|
||||
|
@ -68,7 +69,10 @@ public class AbstractService {
|
|||
+ "AND WS_WebServiceType_ID=?";
|
||||
private static final String COMPIERE_SERVICE = "CompiereService";
|
||||
@Resource
|
||||
protected WebServiceContext ctx;
|
||||
protected WebServiceContext jaxwsContext; //soap context
|
||||
|
||||
@Context
|
||||
protected org.apache.cxf.jaxrs.ext.MessageContext jaxrsContext ; //rest context
|
||||
|
||||
/**
|
||||
* Login to web Services
|
||||
|
@ -193,8 +197,6 @@ public class AbstractService {
|
|||
*/
|
||||
protected String authenticate(String webServiceValue, String methodValue, String serviceTypeValue, CompiereService m_cs) {
|
||||
|
||||
HttpServletRequest req = (HttpServletRequest) ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST);
|
||||
|
||||
MWebService m_webservice = MWebService.get(m_cs.getCtx(), webServiceValue);
|
||||
if (m_webservice == null || !m_webservice.isActive())
|
||||
return "Web Service " + webServiceValue + " not registered";
|
||||
|
@ -229,7 +231,7 @@ public class AbstractService {
|
|||
if (m_webservicetype == null)
|
||||
return "Service type " + serviceTypeValue + " not configured";
|
||||
|
||||
req.setAttribute("MWebServiceType", m_webservicetype);
|
||||
getHttpServletRequest().setAttribute("MWebServiceType", m_webservicetype);
|
||||
|
||||
// Check if role has access on web-service
|
||||
String hasAccess = DB.getSQLValueStringEx(null, ROLE_ACCESS_SQL,
|
||||
|
@ -271,7 +273,9 @@ public class AbstractService {
|
|||
* @return Compiere Service object for current request
|
||||
*/
|
||||
protected CompiereService getCompiereService() {
|
||||
HttpServletRequest req = (HttpServletRequest) ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST);
|
||||
|
||||
HttpServletRequest req = getHttpServletRequest();
|
||||
|
||||
CompiereService m_cs = (CompiereService) req.getAttribute(COMPIERE_SERVICE);
|
||||
if (m_cs == null) {
|
||||
m_cs = new CompiereService();
|
||||
|
@ -285,9 +289,8 @@ public class AbstractService {
|
|||
* @return
|
||||
*/
|
||||
protected MWebServiceType getWebServiceType() {
|
||||
HttpServletRequest req = (HttpServletRequest) ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST);
|
||||
|
||||
return (MWebServiceType) req.getAttribute("MWebServiceType");
|
||||
return (MWebServiceType) getHttpServletRequest().getAttribute("MWebServiceType");
|
||||
|
||||
}
|
||||
|
||||
|
@ -296,7 +299,7 @@ public class AbstractService {
|
|||
* @return
|
||||
*/
|
||||
protected Map<String, Object> getRequestCtx() {
|
||||
HttpServletRequest req = (HttpServletRequest) ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST);
|
||||
HttpServletRequest req = getHttpServletRequest();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Object> reqCtx= (Map<String,Object>)req.getAttribute("RequestCtx");
|
||||
|
@ -631,5 +634,18 @@ public class AbstractService {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HttpServletRequest object
|
||||
* @return HttpServletRequest
|
||||
*/
|
||||
private HttpServletRequest getHttpServletRequest() {
|
||||
HttpServletRequest req;
|
||||
if (jaxrsContext != null) {
|
||||
req = (HttpServletRequest) jaxrsContext.getHttpServletRequest();
|
||||
} else
|
||||
req = (HttpServletRequest) jaxwsContext.getMessageContext().get(
|
||||
MessageContext.SERVLET_REQUEST);
|
||||
return req;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
classpath:/META-INF/cxf/services.xml
|
||||
classpath:/META-INF/cxf/rest-context.xml
|
||||
</param-value>
|
||||
</context-param>
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ bin.includes = META-INF/,\
|
|||
WEB-INF/lib/idempiere-xmlbeans-1.0.jar,\
|
||||
plugin.xml,\
|
||||
WEB-INF/lib/axis.jar,\
|
||||
WEB-INF/lib/commons-discovery-0.5.jar
|
||||
WEB-INF/lib/commons-discovery-0.5.jar,\
|
||||
WEB-INF/lib/jsr311-api-1.1.jar
|
||||
src.includes = WEB-INF/classes/,\
|
||||
WEB-INF/lib/,\
|
||||
WEB-INF/web.xml,\
|
||||
|
|
Loading…
Reference in New Issue