1 7 package org.jboss.jaxr.juddi.axis; 8 9 14 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 import org.apache.juddi.IRegistry; 18 import org.apache.juddi.datatype.RegistryObject; 19 import org.apache.juddi.datatype.response.DispositionReport; 20 import org.apache.juddi.error.BusyException; 21 import org.apache.juddi.error.RegistryException; 22 import org.apache.juddi.error.UnsupportedException; 23 import org.apache.juddi.handler.DispositionReportHandler; 24 import org.apache.juddi.handler.HandlerMaker; 25 import org.apache.juddi.handler.IHandler; 26 import org.apache.juddi.registry.RegistryEngine; 27 import org.apache.juddi.registry.RegistryServlet; 28 import org.apache.juddi.util.Config; 29 import org.apache.juddi.util.xml.XMLUtils; 30 import org.jboss.axis.AxisFault; 31 import org.jboss.axis.Message; 32 import org.jboss.axis.MessageContext; 33 import org.jboss.axis.message.SOAPBodyElementAxisImpl; 34 import org.jboss.axis.message.SOAPEnvelopeAxisImpl; 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.Element ; 37 38 39 45 public class JBossJuddiAxisProcessor 46 { 47 private static Log log = LogFactory.getLog(JBossJuddiAxisProcessor.class); 49 50 private static HandlerMaker maker = HandlerMaker.getInstance(); 52 53 57 public JBossJuddiAxisProcessor(Message soapResponse, MessageContext messageContext) 58 { 59 68 69 72 Message soapRequest = messageContext.getRequestMessage(); 73 74 76 try 77 { 78 log.debug(soapRequest.getSOAPPartAsString()); 79 } catch (AxisFault af) 80 { 81 af.printStackTrace(); 82 } 83 84 Element request = null; 85 Element response = null; 86 String function = null; 87 String generic = null; 88 89 try 90 { 91 94 SOAPEnvelopeAxisImpl env = soapRequest.getSOAPEnvelope(); 95 SOAPBodyElementAxisImpl requestBody = env.getFirstBody(); 96 request = requestBody.getAsDOM(); 97 98 102 103 108 function = request.getLocalName(); 109 110 113 generic = request.getAttribute("generic"); 114 if (generic == null) 115 generic = IRegistry.UDDI_V2_GENERIC; 116 117 121 IHandler requestHandler = maker.lookup(function); 122 if (requestHandler == null) 123 throw new UnsupportedException("The request " + 124 "type is unknown: " + function); 125 126 129 RegistryObject uddiRequest = requestHandler.unmarshal(request); 130 131 135 136 140 Object juddiServlet = messageContext.getProperty("transport.http.servlet"); 141 142 146 if ((juddiServlet instanceof JBossJuddiInquiryServlet) && 148 (!(uddiRequest instanceof org.apache.juddi.datatype.request.Inquiry))) 149 { 150 throw new RegistryException("Inquiry API " + 151 "does not support function: " + function); 152 } else if (juddiServlet instanceof JBossJuddiPublishServlet && 153 (!(uddiRequest instanceof org.apache.juddi.datatype.request.Publish) && 154 !(uddiRequest instanceof org.apache.juddi.datatype.request.SecurityPolicy))) 155 { 156 throw new RegistryException("Publish API " + 157 "does not support function: " + function); 158 } else if ((juddiServlet instanceof JBossJuddiAdminServlet) && (!(uddiRequest instanceof org.apache.juddi.datatype.request.Admin))) 160 { 161 throw new RegistryException("Admin API " + 162 "does not support function: " + function); 163 } 164 165 169 RegistryObject uddiResponse = null; 170 171 RegistryEngine registry = RegistryServlet.getRegistry(); 172 if ((registry != null) && (registry.isAvailable())) 173 uddiResponse = registry.execute(uddiRequest); 174 else 175 throw new BusyException("The Registry is unavailable"); 176 177 181 Document document = XMLUtils.createDocument(); 182 Element element = document.createElement("temp"); 183 184 190 IHandler responseHandler = maker.lookup(uddiResponse.getClass().getName()); 191 responseHandler.marshal(uddiResponse, element); 192 193 198 response = (Element ) element.getFirstChild(); 199 } catch (RegistryException rex) 200 { 201 log.error(rex.getMessage(), rex); 202 203 String fCode = rex.getFaultCode(); 204 String fString = rex.getFaultString(); 205 String fActor = rex.getFaultActor(); 206 207 DispositionReport dispRpt = rex.getDispositionReport(); 208 if (dispRpt != null) 209 { 210 dispRpt.setGeneric(generic); 211 dispRpt.setOperator(Config.getOperator()); 212 } 213 214 216 217 response = createFault(fCode, fString, fActor, dispRpt); 218 } catch (AxisFault axf) 219 { 220 log.error(axf.getMessage(), axf); 221 String fCode = String.valueOf(axf.getFaultCode()); 222 String fString = axf.getFaultString(); 223 String fActor = axf.getFaultActor(); 224 225 227 228 response = createFault(fCode, fString, fActor, null); 229 } catch (Exception ex) 230 { 231 log.error(ex.getMessage(), ex); 232 233 String fCode = null; 234 String fString = ex.getMessage(); 235 String fActor = null; 236 237 239 240 response = createFault(fCode, fString, fActor, null); 241 } finally 242 { 243 248 250 } 251 252 try 253 { 254 255 SOAPBodyElementAxisImpl soapRespBody = new SOAPBodyElementAxisImpl(response); 256 SOAPEnvelopeAxisImpl soapRespEnv = soapResponse.getSOAPEnvelope(); 257 soapRespEnv.addBodyElement(soapRespBody); 258 259 260 } catch (AxisFault af) 261 { 262 af.printStackTrace(); 263 } 264 265 try 267 { 268 log.debug(soapResponse.getSOAPPartAsString()); 269 } catch (AxisFault af) 270 { 271 af.printStackTrace(); 272 } 273 274 } 275 276 private static Element createFault(String fCode, String fString, String fActor, DispositionReport dispRpt) 277 { 278 280 Document document = XMLUtils.createDocument(); 281 Element fault = document.createElement("Fault"); 282 283 if (fCode != null) 284 { 285 Element fCodeElement = document.createElement("faultcode"); 286 fCodeElement.appendChild(document.createTextNode(fCode)); 287 fault.appendChild(fCodeElement); 288 } 289 290 if (fString == null) 291 fString = ""; 292 293 Element fStringElement = document.createElement("faultstring"); 294 fStringElement.appendChild(document.createTextNode(fString)); 295 fault.appendChild(fStringElement); 296 297 if (fActor != null) 298 { 299 Element fActorElement = document.createElement("faultactor"); 300 fActorElement.appendChild(document.createTextNode(fActor)); 301 fault.appendChild(fActorElement); 302 } 303 304 308 if (dispRpt != null) 309 { 310 Element fDetailElement = document.createElement("detail"); 311 IHandler handler = maker.lookup(DispositionReportHandler.TAG_NAME); 312 handler.marshal(dispRpt, fDetailElement); 313 fault.appendChild(fDetailElement); 314 } 315 316 return fault; 317 } 318 } 319 320 | Popular Tags |