removed unused variables
[mono.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Messaging / SoapReceiver.cs
1 //
2 // Microsoft.Web.Services.Messaging.SoapReceiver.cs
3 //
4 // Author: Todd Berman <tberman@gentoo.org>
5 //
6 // (C) 2003 Todd Berman
7
8 using System;
9 using System.Web;
10 using Microsoft.Web.Services;
11 using Microsoft.Web.Services.Addressing;
12 using Microsoft.Web.Services.Configuration;
13
14 namespace Microsoft.Web.Services.Messaging {
15
16         public abstract class SoapReceiver : SoapPort, IHttpHandler
17         {
18
19                 private static Pipeline _defPipe = new Pipeline ();
20
21                 protected abstract void Receive (SoapEnvelope envelope);
22
23                 public SoapReceiver () : base ()
24                 {
25                 }
26
27                 protected void Receive (SoapEnvelope envelope, Exception e)
28                 {
29                 }
30
31                 public static void DispatchMessage (SoapEnvelope env)
32                 {
33                         DispatchMessage (env, null);
34                 }
35
36                 public static void DispatchMessage (SoapEnvelope env, RelatesTo relation)
37                 {
38                         if(env == null) {
39                                 throw new ArgumentNullException ("envelope");
40                         }
41                         SoapReceiver rec = null;
42                         AddressingHeaders header = null;
43
44                         try {
45
46                                 header = env.Context.Addressing;
47
48                                 header.Load (env);
49
50                                 if(header.RelatesTo != null || header.To != null || relation != null)
51                                 {
52                                         object to = null;
53                                         if(header.RelatesTo != null) {
54                                                 if(WebServicesConfiguration.MessagingConfiguration.GetTransport (header.RelatesTo.Value.Scheme) == null) {
55                                                         //FIXME: Incorrect exception here, should be using something in Routing.
56                                                         throw new ArgumentException ("Transport " + header.RelatesTo.Value.Scheme + " is not supported");
57                                                 }
58                                                 to = SoapReceivers.Receiver (header.RelatesTo.Value);
59                                                 env.Context.SetActor (header.RelatesTo);
60                                         }
61                                         if(to == null && header.To != null) {
62                                                 if(env.Context.Channel.Scheme != header.To.Value.Scheme) {
63                                                         //FIXME: Incorrect exception again.
64                                                         throw new ArgumentException ("Channel's Scheme and To's Scheme are not the same.");
65                                                 }
66                                                 to = SoapReceivers.Receiver (header.To.Value);
67                                                 env.Context.SetActor (header.RelatesTo);
68                                         }
69                                         if(to == null && relation != null) {
70                                                 to = SoapReceivers.Receiver (relation.Value);
71                                                 env.Context.Addressing.RelatesTo = relation;
72                                                 env.Context.SetActor (relation);
73                                         }
74                                         if(to != null) {
75                                                 rec = to as SoapReceiver;
76                                                 if(rec == null) {
77                                                         rec = (SoapReceiver) Activator.CreateInstance (to as Type);
78                                                 }
79                                                 if(rec != null) {
80                                                         Exception excep = null;
81                                                         try {
82                                                                 env.Context.SetIsInbound (true);
83                                                                 rec.FilterMessage (env);
84                                                         } catch (Exception e) {
85                                                                 excep = e;
86                                                         }
87                                                         if(excep != null) {
88                                                                 //FIXME: again, wrong exception type, should be throwing something XmlElement like
89                                                                 rec.Receive (env, excep);
90                                                         } else {
91                                                                 rec.Receive (env);
92                                                         }
93                                                 } else {
94                                                         //FIXME: same thing
95                                                         throw new InvalidOperationException ("no receiver found");
96                                                 }
97                                         } else {
98                                                 //FIXME: same
99                                                 throw new InvalidOperationException ("no receiver found pt 2");
100                                         }
101                                 }
102                         } catch (Exception e) {
103                                 if(rec == null) {
104                                         DispatchMessageFault (env, e);
105                                 } else {
106                                         DispatchMessageFault (env, e, rec.Pipeline);
107                                 }
108                         }
109                 }
110                 
111                 public static void DispatchMessageFault (SoapEnvelope env, Exception e)
112                 {
113                         DispatchMessageFault (env, e, _defPipe);
114                 }
115
116                 public static void DispatchMessageFault (SoapEnvelope env, Exception e, Pipeline pipe)
117                 {
118                 }
119                 
120                 public bool IsReusable {
121                         get {
122                                 return true;
123                         }
124                 }
125
126                 protected override void FilterMessage (SoapEnvelope env)
127                 {
128                         if(env == null) {
129                                 throw new ArgumentNullException ("envelope");
130                         }
131                         Pipeline.ProcessInputMessage (env);
132                 }
133
134                 public void ProcessSoapRequest (HttpContext context)
135                 {
136                         
137                 }
138
139                 public void ProcessNonSoapRequest (HttpContext context)
140                 {
141                         
142                 }
143
144                 public void ProcessRequest (HttpContext context)
145                 {
146                         if(context.Request.HttpMethod == "POST" || context.Request.Headers["SOAPAction"] != null) {
147                                 ProcessSoapRequest (context);
148                         }
149                         ProcessNonSoapRequest (context);
150                 }
151         }
152 }