protected void writeFaultElement( Document d, Element bodyElement, ActionInvocation actionInvocation) { Element faultElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Fault"); bodyElement.appendChild(faultElement); // This stuff is really completely arbitrary nonsense... let's hope they fired the guy who // decided this XMLUtil.appendNewElement(d, faultElement, "faultcode", "s:Client"); XMLUtil.appendNewElement(d, faultElement, "faultstring", "UPnPError"); Element detailElement = d.createElement("detail"); faultElement.appendChild(detailElement); Element upnpErrorElement = d.createElementNS(Constants.NS_UPNP_CONTROL_10, "UPnPError"); detailElement.appendChild(upnpErrorElement); int errorCode = actionInvocation.getFailure().getErrorCode(); String errorDescription = actionInvocation.getFailure().getMessage(); log.fine("Writing fault element: " + errorCode + " - " + errorDescription); XMLUtil.appendNewElement(d, upnpErrorElement, "errorCode", Integer.toString(errorCode)); XMLUtil.appendNewElement(d, upnpErrorElement, "errorDescription", errorDescription); }
public void writeBody(ActionResponseMessage responseMessage, ActionInvocation actionInvocation) throws UnsupportedDataException { log.fine("Writing body of " + responseMessage + " for: " + actionInvocation); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document d = factory.newDocumentBuilder().newDocument(); Element body = writeBodyElement(d); if (actionInvocation.getFailure() != null) { writeBodyFailure(d, body, responseMessage, actionInvocation); } else { writeBodyResponse(d, body, responseMessage, actionInvocation); } if (log.isLoggable(Level.FINER)) { log.finer( "===================================== SOAP BODY BEGIN ============================================"); log.finer(responseMessage.getBodyString()); log.finer( "-===================================== SOAP BODY END ============================================"); } } catch (Exception ex) { throw new UnsupportedDataException("Can't transform message payload: " + ex, ex); } }
@Test(dataProvider = "devices") public void invokeActions(LocalDevice device) { LocalService svc = device.getServices()[0]; ActionInvocation setColor = new ActionInvocation(svc.getAction("SetColor")); setColor.setInput("In", MyServiceWithEnum.Color.Blue); svc.getExecutor(setColor.getAction()).execute(setColor); assertEquals(setColor.getFailure(), null); assertEquals(setColor.getOutput().length, 0); ActionInvocation getColor = new ActionInvocation(svc.getAction("GetColor")); svc.getExecutor(getColor.getAction()).execute(getColor); assertEquals(getColor.getFailure(), null); assertEquals(getColor.getOutput().length, 1); assertEquals(getColor.getOutput()[0].toString(), MyServiceWithEnum.Color.Blue.name()); }