1 16 package org.apache.juddi.transport.axis; 17 18 import java.util.Vector ; 19 20 import javax.xml.soap.Detail ; 21 import javax.xml.soap.SOAPBody ; 22 import javax.xml.soap.SOAPElement ; 23 import javax.xml.soap.SOAPFault ; 24 25 import org.apache.axis.AxisFault; 26 import org.apache.axis.Message; 27 import org.apache.axis.MessageContext; 28 import org.apache.axis.message.SOAPBodyElement; 29 import org.apache.axis.message.SOAPEnvelope; 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.apache.juddi.IRegistry; 33 import org.apache.juddi.datatype.RegistryObject; 34 import org.apache.juddi.datatype.response.DispositionReport; 35 import org.apache.juddi.datatype.response.ErrInfo; 36 import org.apache.juddi.datatype.response.Result; 37 import org.apache.juddi.error.BusyException; 38 import org.apache.juddi.error.RegistryException; 39 import org.apache.juddi.error.UnsupportedException; 40 import org.apache.juddi.handler.HandlerMaker; 41 import org.apache.juddi.handler.IHandler; 42 import org.apache.juddi.registry.RegistryEngine; 43 import org.apache.juddi.registry.RegistryServlet; 44 import org.apache.juddi.util.Config; 45 import org.apache.juddi.util.xml.XMLUtils; 46 import org.w3c.dom.Document ; 47 import org.w3c.dom.Element ; 48 49 53 public class AxisProcessor 54 { 55 private static Log log = LogFactory.getLog(AxisProcessor.class); 57 58 private static HandlerMaker maker = HandlerMaker.getInstance(); 60 61 65 public AxisProcessor(Message soapResponse,MessageContext messageContext) 66 { 67 69 SOAPEnvelope soapReqEnv = null; 70 SOAPEnvelope soapResEnv = null; 71 72 75 Message soapRequest = messageContext.getRequestMessage(); 76 77 79 try { log.debug(soapRequest.getSOAPPartAsString()); } 80 catch(AxisFault af) { 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 soapReqEnv = soapRequest.getSOAPEnvelope(); 95 soapResEnv = soapResponse.getSOAPEnvelope(); 96 97 100 SOAPBodyElement requestBody = soapReqEnv.getFirstBody(); 101 request = requestBody.getAsDOM(); 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 Object juddiServlet = messageContext.getProperty("transport.http.servlet"); 136 137 141 if((juddiServlet instanceof InquiryServlet) && 142 (!(uddiRequest instanceof org.apache.juddi.datatype.request.Inquiry))) 143 { 144 throw new RegistryException("Inquiry API " + 145 "does not support function: "+function); 146 } 147 else if (juddiServlet instanceof PublishServlet && 148 (!(uddiRequest instanceof org.apache.juddi.datatype.request.Publish) && 149 !(uddiRequest instanceof org.apache.juddi.datatype.request.SecurityPolicy))) 150 { 151 throw new RegistryException("Publish API " + 152 "does not support function: "+function); 153 } 154 else if ((juddiServlet instanceof AdminServlet) && (!(uddiRequest instanceof org.apache.juddi.datatype.request.Admin))) 156 { 157 throw new RegistryException("Admin API " + 158 "does not support function: "+function); 159 } 160 161 165 RegistryObject uddiResponse = null; 166 167 RegistryEngine registry = RegistryServlet.getRegistry(); 168 if ((registry != null) && (registry.isAvailable())) 169 uddiResponse = registry.execute(uddiRequest); 170 else 171 throw new BusyException("The Registry is unavailable"); 172 173 177 Document document = XMLUtils.createDocument(); 178 Element element = document.createElement("temp"); 179 180 186 IHandler responseHandler = maker.lookup(uddiResponse.getClass().getName()); 187 responseHandler.marshal(uddiResponse,element); 188 189 194 response = (Element )element.getFirstChild(); 195 SOAPBodyElement soapRespBody = new SOAPBodyElement(response); 196 SOAPEnvelope soapRespEnv = soapResponse.getSOAPEnvelope(); 197 soapRespEnv.addBodyElement(soapRespBody); 198 } 199 catch(Exception ex) 200 { 201 log.error(ex.getMessage(),ex); 202 203 String faultCode = null; 204 String faultString = null; 205 String faultActor = null; 206 String errno = null; 207 String errCode = null; 208 String errText = null; 209 210 218 if (ex instanceof RegistryException) 219 { 220 RegistryException rex = (RegistryException)ex; 221 222 faultCode = rex.getFaultCode(); faultString = rex.getFaultString(); faultActor = rex.getFaultActor(); 226 DispositionReport dispRpt = rex.getDispositionReport(); 227 if (dispRpt != null) 228 { 229 Result result = null; 230 ErrInfo errInfo = null; 231 232 Vector results = dispRpt.getResultVector(); 233 if ((results != null) && (!results.isEmpty())) 234 result = (Result)results.elementAt(0); 235 236 if (result != null) 237 { 238 errno = String.valueOf(result.getErrno()); errInfo = result.getErrInfo(); 240 241 if (errInfo != null) 242 { 243 errCode = errInfo.getErrCode(); errText = errInfo.getErrMsg(); } 246 } 247 } 248 } 249 else 250 { 251 257 faultCode = "Server"; 258 faultString = ex.getMessage(); 259 faultActor = null; 260 261 errno = String.valueOf(Result.E_FATAL_ERROR); 262 errCode = Result.lookupErrCode(Result.E_FATAL_ERROR); 263 errText = Result.lookupErrText(Result.E_FATAL_ERROR) + 264 " An internal UDDI server error has " + 265 "occurred. Please report this error " + 266 "to the UDDI server administrator."; 267 } 268 269 273 try { 274 SOAPBody soapResBody = soapResEnv.getBody(); 275 SOAPFault soapFault = soapResBody.addFault(); 276 soapFault.setFaultCode(faultCode); 277 soapFault.setFaultString(faultString); 278 soapFault.setFaultActor(faultActor); 279 280 Detail faultDetail = soapFault.addDetail(); 281 282 SOAPElement dispRpt = faultDetail.addChildElement("dispositionReport","",IRegistry.UDDI_V2_NAMESPACE); 283 dispRpt.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 284 dispRpt.setAttribute("operator",Config.getOperator()); 285 286 SOAPElement result = dispRpt.addChildElement("result"); 287 result.setAttribute("errno",errno); 288 289 SOAPElement errInfo = result.addChildElement("errInfo"); 290 errInfo.setAttribute("errCode",errCode); 291 errInfo.setValue(errText); 292 } 293 catch (Exception e) { 294 e.printStackTrace(); 295 } 296 } 297 298 try { log.debug(soapResponse.getSOAPPartAsString()); } 300 catch(AxisFault af) { 301 af.printStackTrace(); 302 } 303 } 304 } 305 | Popular Tags |