1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.backsource.amsterdam.plugins.axis;
21 import java.net.URL;
22 import java.net.MalformedURLException;
23
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26
27 import org.apache.axis.client.Call;
28 import org.apache.axis.client.Service;
29 import javax.xml.namespace.QName;
30
31 import org.backsource.utils.xml.ElementUtil;
32 import org.backsource.utils.xml.XmlException;
33
34 import org.backsource.amsterdam.service.publisher.Publisher;
35 import org.backsource.amsterdam.service.ServiceMessage;
36 import org.backsource.amsterdam.service.ServiceException;
37 import org.backsource.amsterdam.metadata.XmlConfigurable;
38 import org.backsource.amsterdam.deployment.DeploymentException;
39
40 import org.backsource.amsterdam.plugins.XMLHandlerBase;
41 /***
42 * Filter and Publisher that publishes a Document to the webservice specifyed in url.
43 * <p>It takes several arguments, a publisher may be confugured like this:
44 <pre> <publisher
45 className="org.backsource.amsterdam.plugins.axis.AxisHandler">
46 <ws-url>http://localhost:8080/axis-demo/services/DeliverDocument</ws-url>
47 <ns>http://localhost:8080/axis-demo</ns>
48 <method>handleDocument</method>
49 <user>vv</user>
50 <password>vv</password>
51 </publisher>
52 </pre>
53 <p>method is optional and defaults to handleDocument. user and password is also optional.</p>
54 *
55 * @author <a href="mailto:pra@mogul.com">Peter Antman</a>
56 * @version $Revision: 1.1 $
57 */
58
59 public class AxisHandler extends XMLHandlerBase implements Publisher,XmlConfigurable {
60 URL endpoint;
61 String user;
62 String password;
63 String ns;
64 String method;
65 public AxisHandler (){
66
67 }
68 public void importXml(Element element) throws DeploymentException {
69 super.importXml(element);
70 Element root = getRootElement(element);
71 try {
72 String wsUrlStr = ElementUtil.getContent( ElementUtil.getUniqueChild(root,"ws-url"),null);
73 endpoint = new URL(wsUrlStr);
74 ns = ElementUtil.getContent( ElementUtil.getUniqueChild(root,"ns"),null);
75 method = ElementUtil.getContent( ElementUtil.getOptionalChild(root,"method"),"handleDocument");
76 user = ElementUtil.getContent( ElementUtil.getOptionalChild(root,"user"),null);
77 password = ElementUtil.getContent( ElementUtil.getOptionalChild(root,"password"),null);
78 }catch (MalformedURLException e) {
79 throw new DeploymentException("ws-url as not an url:" +e);
80 }catch ( XmlException e) {
81 throw new DeploymentException("Error in reading configuration: " + e, e);
82 }
83
84 }
85 /***
86 * Publish document to webservice
87 */
88 public Document handleMessage(ServiceMessage message, Document doc) throws ServiceException {
89 try {
90 Service service = new Service();
91 Call call = (Call) service.createCall();
92 call.setTargetEndpointAddress( endpoint );
93 call.setOperationName(new QName(ns, method));
94 call.setOperationStyle(org.apache.axis.enum.Style.MESSAGE );
95
96 if ( user!= null) {
97 call.setUsername(user);
98 call.setPassword(password);
99 }
100
101 Object ret = call.invoke( new Object[] { doc} );
102 return doc;
103 } catch (Exception e) {
104 throw new ServiceException("Could not invoke webservice "+e,e);
105 }
106
107 }
108
109 }