private Object parseMessage() { // Consume SOAP message, if any // TODO: Add a SOAP handler in Parser.java if (soapAction != null) { try { MimeHeaders mime_headers = new MimeHeaders(); for (Object k : headers.getIds()) { if (k instanceof String) { String name = (String) k; String value = Context.toString(ScriptableObject.getProperty(headers, name)); mime_headers.addHeader(name, value); } } return MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL) .createMessage(mime_headers, request.getInputStream()); } catch (IOException ex) { throw new ESXXException("Unable to read SOAP message stream: " + ex.getMessage()); } catch (SOAPException ex) { throw new ESXXException(400 /* Bad Request */, "Invalid SOAP message: " + ex.getMessage()); } finally { try { request.getInputStream().close(); } catch (Exception ignored) { } } } else if (contentType != null && contentLength > 0) { try { ESXX esxx = ESXX.getInstance(); return esxx.parseStream( contentType, request.getInputStream(), URI.create("urn:x-esxx:incoming-request-entity"), null, new java.io.PrintWriter(request.getErrorWriter()), Context.getCurrentContext(), this); } catch (Exception ex) { throw new ESXXException( 400 /* Bad Request */, "Unable to parse request entity: " + ex.getMessage(), ex); } finally { try { request.getInputStream().close(); } catch (Exception ignored) { } } } else { // Return a dummy object return Context.getCurrentContext().newObject(this); } }