ByteArrayOutputStream bs = new ByteArrayOutputStream();
soapReq.writeTo(bs);
log.debug("Request received::"+bs.toString());
}
SOAPBody soapReqBody = soapReq.getSOAPBody();
Iterator it = soapReqBody.getChildElements();
Element uddiReq = null;
while (uddiReq == null && it.hasNext())
{
Object current = it.next();
if (current instanceof Element)
{
uddiReq = (Element)current;
}
}
if (uddiReq == null)
throw new FatalErrorException("A UDDI request was not " +
"found in the SOAP message.");
String function = uddiReq.getLocalName();
if ((function == null) || (function.trim().length() == 0))
throw new FatalErrorException("The name of the UDDI request " +
"could not be identified.");
IHandler requestHandler = maker.lookup(function);
if (requestHandler == null)
throw new UnsupportedException("The UDDI request " +
"type specified is unknown: " + function);
String generic = uddiReq.getAttribute("generic");
if (generic == null)
throw new FatalErrorException("A UDDI generic attribute " +
"value was not found for UDDI request: " + function + " (The " +
"'generic' attribute must be present)");
else if (!generic.equals(IRegistry.UDDI_V2_GENERIC))
throw new UnsupportedException("Currently only UDDI v2 " +
"requests are supported. The generic attribute value " +
"received was: " + generic);
// Unmarshal the raw xml into the appropriate jUDDI
// request object.
RegistryObject uddiReqObj = requestHandler.unmarshal(uddiReq);
if(uddiReqObj == null)
throw new FatalErrorException("Uddi Request is null");
// Grab a reference to the shared jUDDI registry
// instance (make sure it's running) and execute the
// requested UDDI function.
RegistryObject uddiResObj = null;
RegistryEngine registry = RegistryServlet.getRegistry();
if ((registry != null) && (registry.isAvailable()))
uddiResObj = registry.execute(uddiReqObj);
else
throw new BusyException("The Registry is currently unavailable.");
// Lookup the appropriate response handler which will
// be used to marshal the UDDI object into the appropriate
// xml format.
IHandler responseHandler = maker.lookup(uddiResObj.getClass().getName());
if (responseHandler == null)
throw new FatalErrorException("The response object " +
"type is unknown: " + uddiResObj.getClass().getName());
// Create a new 'temp' XML element to use as a container
// in which to marshal the UDDI response data into.
DocumentBuilder docBuilder = getDocumentBuilder();
Document document = docBuilder.newDocument();
Element element = document.createElement("temp");
// Lookup the appropriate response handler and marshal
// the juddi object into the appropriate xml format (we
// only support UDDI v2.0 at this time). Attach the
// results to the body of the SOAP response.
responseHandler.marshal(uddiResObj, element);
log.debug("Response that will be sent:");
log.debug(XMLUtils.toString((Element) element.getFirstChild()));
// Grab a reference to the 'temp' element's
// only child here (this has the effect of
// discarding the temp element) and append
// this child to the soap response body
/*document.appendChild(element.getFirstChild());
soapRes.getSOAPBody().addDocument(document);*/
Element el = (Element) element.getFirstChild();
soapRes = this.createSOAPMessage(el);
} catch (Exception ex) // Catch ALL exceptions
{
// SOAP Fault values
String faultCode = null;
String faultString = null;
String faultActor = null;
// UDDI DispositionReport values
String errno = null;
String errCode = null;
String errMsg = null;
if (ex instanceof RegistryException)
{
log.error("RegistryException::",ex);
RegistryException rex = (RegistryException) ex;
faultCode = rex.getFaultCode(); // SOAP Fault faultCode
faultString = rex.getFaultString(); // SOAP Fault faultString
faultActor = rex.getFaultActor(); // SOAP Fault faultActor
DispositionReport dispRpt = rex.getDispositionReport();
if (dispRpt != null)
{
Result result = null;
ErrInfo errInfo = null;
Vector results = dispRpt.getResultVector();
if ((results != null) && (!results.isEmpty()))
result = (Result) results.elementAt(0);
if (result != null)
{
errno = String.valueOf(result.getErrno()); // UDDI Result errno
errInfo = result.getErrInfo();
if (errInfo != null)
{
errCode = errInfo.getErrCode(); // UDDI ErrInfo errCode
errMsg = errInfo.getErrMsg(); // UDDI ErrInfo errMsg
}
}
}
} else
{
log.error(ex.getMessage(), ex);
faultCode = "Server";
faultString = ex.getMessage();
faultActor = null;
errno = String.valueOf(Result.E_FATAL_ERROR);
errCode = Result.lookupErrCode(Result.E_FATAL_ERROR);
errMsg = Result.lookupErrText(Result.E_FATAL_ERROR);
}
try
{
SOAPBody soapResBody = soapRes.getSOAPBody();
SOAPFault soapFault = soapResBody.addFault();
if(faultCode == null)
faultCode = "Unavailable";
if (faultCode.contains(":") == false)
{