View Javadoc

1   /*
2    * Copyright  1999-2004 The Apache Software Foundation.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *
16   */
17  
18  package org.apache.savan.publication.client;
19  
20  import javax.xml.namespace.QName;
21  
22  import org.apache.axiom.soap.SOAPEnvelope;
23  import org.apache.axis2.AxisFault;
24  import org.apache.axis2.addressing.EndpointReference;
25  import org.apache.axis2.client.OperationClient;
26  import org.apache.axis2.client.Options;
27  import org.apache.axis2.client.ServiceClient;
28  import org.apache.axis2.context.ConfigurationContext;
29  import org.apache.axis2.context.MessageContext;
30  import org.apache.axis2.description.Parameter;
31  import org.apache.savan.SavanConstants;
32  import org.apache.savan.SavanException;
33  import org.apache.savan.storage.SubscriberStore;
34  
35  /***
36   * This can be used to make the Publication Process easy.
37   * Handle things like engaging the savan module correctly and setting the
38   * correct subscriber store.
39   */
40  public class PublicationClient {
41  	
42  	public static final String TEMP_PUBLICATION_ACTION = "UUID:TempPublicationAction";
43  	
44  	public static void sendPublication (SOAPEnvelope publication,ConfigurationContext configurationContext, SubscriberStore store) throws SavanException {
45  		
46  		try {
47  			Options options = new Options ();
48  			sendPublication(publication,configurationContext,options,store);
49  			
50  		} catch (AxisFault e) {
51  			String message = "Could not send the publication";
52  			throw new SavanException (message,e);
53  		}
54  	}
55  	
56  	public static void sendPublication (SOAPEnvelope publication,ConfigurationContext configurationContext, Options options, SubscriberStore store) throws SavanException {
57  		
58  		try {
59  			ServiceClient sc = new ServiceClient (configurationContext,null);
60  			
61  			options.setTo(new EndpointReference ("http://temp.publication.URI"));
62  			
63  			if (options.getAction()==null)
64  				options.setAction(TEMP_PUBLICATION_ACTION);
65  			
66  			sc.setOptions(options);
67  			
68  			//this will not be required when the 
69  			Parameter parameter = new Parameter ();
70  			parameter.setName(SavanConstants.SUBSCRIBER_STORE);
71  			parameter.setValue(store);
72  			sc.getAxisService().addParameter(parameter);
73  			
74  			//if already engaged, axis2 will neglect this engagement.
75  			sc.engageModule( new QName("savan"));
76  			
77  			MessageContext mc = new MessageContext ();
78  			mc.setEnvelope(publication);
79  			OperationClient client = sc.createClient(ServiceClient.ANON_OUT_ONLY_OP);
80  			client.addMessageContext(mc);
81  			client.execute(true);
82  		} catch (AxisFault e) {
83  			String message = "Could not send the publication";
84  			throw new SavanException (message,e);
85  		}
86  	}
87  	
88  	public static void endSubscription (String subscriberID) {
89  		
90  	}
91  }