KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > util > webservices > InfoGlueWebServices


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23
24 package org.infoglue.deliver.util.webservices;
25
26 import javax.xml.namespace.QName JavaDoc;
27 import javax.xml.rpc.ParameterMode JavaDoc;
28
29 import org.apache.axis.client.Call;
30 import org.apache.axis.client.Service;
31 import org.apache.axis.encoding.XMLType;
32 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
33 import org.apache.axis.encoding.ser.BeanSerializerFactory;
34 import org.infoglue.cms.entities.content.ContentVO;
35 import org.infoglue.cms.entities.content.ContentVersionVO;
36
37 /**
38  * This class helps in requesting information from an webservice.
39  * @author Mattias Bogeblad
40  */

41
42 public class InfoGlueWebServices
43 {
44     private String JavaDoc serviceUrl = "";
45     
46     private boolean isSuccessfull;
47     private String JavaDoc message;
48     
49     /**
50      * The constructor for this class.
51      */

52     
53     public InfoGlueWebServices()
54     {
55     }
56     
57     /**
58      * A method to set the serviceUrl which is the endpoint of this call.
59      */

60     
61     public String JavaDoc getServiceUrl()
62     {
63         return serviceUrl;
64     }
65
66     /**
67      * A method to get the serviceUrl which is the endpoint of this call.
68      */

69     
70     public void setServiceUrl(String JavaDoc serviceUrl)
71     {
72         this.serviceUrl = serviceUrl;
73     }
74
75     /**
76      * This is the method that lets you create a content and versions.
77      */

78
79     public Integer JavaDoc createContent(ContentVO contentVO, Integer JavaDoc parentContentId, Integer JavaDoc contentTypeDefinitionId, Integer JavaDoc repositoryId)
80     {
81         Integer JavaDoc newContentId = null;
82         
83         try
84         {
85             Service service = new Service();
86             Call call = (Call)service.createCall();
87
88             String JavaDoc endpoint = this.serviceUrl;
89
90             call.setTargetEndpointAddress(endpoint); //Set the target service host and service location,
91
call.setOperationName(new QName JavaDoc("http://soapinterop.org/", "createContent")); //This is the target services method to invoke.
92
call.setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" );
93
94             //register the ContentVO class
95
QName JavaDoc poqn = new QName JavaDoc("http://www.soapinterop.org/ContentVO", "ContentVO");
96             Class JavaDoc cls = ContentVO.class;
97             call.registerTypeMapping(cls, poqn, BeanSerializerFactory.class, BeanDeserializerFactory.class);
98             
99             QName JavaDoc qnameAttachment = new QName JavaDoc("urn:EchoAttachmentsService", "DataHandler");
100
101             call.addParameter("contentVO", poqn, ParameterMode.IN);
102             call.addParameter("parentContentId", XMLType.XSD_INT, ParameterMode.IN);
103             call.addParameter("contentTypeDefinitionId", XMLType.XSD_INT, ParameterMode.IN);
104             call.addParameter("repositoryId", XMLType.XSD_INT, ParameterMode.IN);
105
106             call.setReturnType(XMLType.XSD_INT);
107
108             Object JavaDoc[] args = {contentVO, parentContentId, contentTypeDefinitionId, repositoryId};
109             newContentId = (Integer JavaDoc)call.invoke(args); //Add the attachment.
110
}
111         catch (Exception JavaDoc e)
112         {
113             e.printStackTrace();
114         }
115         
116         return newContentId;
117     }
118     
119     /**
120      * This is the method that lets you create a contentversion.
121      */

122
123     public Integer JavaDoc createContentVersion(ContentVersionVO contentVersionVO, Integer JavaDoc contentId, Integer JavaDoc languageId)
124     {
125         Integer JavaDoc newContentVersionId = null;
126         
127         try
128         {
129             Service service = new Service();
130             Call call = (Call)service.createCall();
131
132             String JavaDoc endpoint = this.serviceUrl;
133
134             call.setTargetEndpointAddress(endpoint); //Set the target service host and service location,
135
call.setOperationName(new QName JavaDoc("http://soapinterop.org/", "createContentVersion")); //This is the target services method to invoke.
136
call.setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" );
137
138             //register the ContentVO class
139
QName JavaDoc poqn = new QName JavaDoc("http://www.soapinterop.org/ContentVersionVO", "ContentVersionVO");
140             Class JavaDoc cls = ContentVersionVO.class;
141             call.registerTypeMapping(cls, poqn, BeanSerializerFactory.class, BeanDeserializerFactory.class);
142             
143             QName JavaDoc qnameAttachment = new QName JavaDoc("urn:EchoAttachmentsService", "DataHandler");
144
145             call.addParameter("contentVersionVO", poqn, ParameterMode.IN);
146             call.addParameter("contentId", XMLType.XSD_INT, ParameterMode.IN);
147             call.addParameter("languageId", XMLType.XSD_INT, ParameterMode.IN);
148
149             call.setReturnType(XMLType.XSD_INT);
150
151             Object JavaDoc[] args = {contentVersionVO, contentId, languageId};
152             newContentVersionId = (Integer JavaDoc)call.invoke(args); //Add the attachment.
153
}
154         catch (Exception JavaDoc e)
155         {
156             e.printStackTrace();
157         }
158         
159         return newContentVersionId;
160     }
161         
162     
163     
164     /**
165      * This method returns true if the request to the webservice returned successfully.
166      */

167
168     public boolean getIsSuccessfull()
169     {
170         return this.isSuccessfull;
171     }
172
173     /**
174      * This method sets if the request to the webservice returned successfully.
175      */

176
177     public void setIsSuccessfull(boolean isSuccessfull)
178     {
179         this.isSuccessfull = isSuccessfull;
180     }
181
182     /**
183      * This method returns any message coming from the webservice.
184      */

185
186     public String JavaDoc getMessage()
187     {
188         return this.message;
189     }
190
191     /**
192      * This method sets a message from the webservice.
193      */

194     
195     public void setMessage(String JavaDoc message)
196     {
197         this.message = message;
198     }
199 }
Popular Tags