FileDocCategorySizeDatePackage
UPnPActionInvocationImpl.javaAPI DocAzureus 3.0.3.44182Sat Mar 17 03:39:40 GMT 2007com.aelitis.net.upnp.impl.services

UPnPActionInvocationImpl

public class UPnPActionInvocationImpl extends Object implements UPnPActionInvocation
author
parg

Fields Summary
protected UPnPActionImpl
action
protected List
arg_names
protected List
arg_values
Constructors Summary
protected UPnPActionInvocationImpl(UPnPActionImpl _action)

	
	
	
				 
	
		action		= _action;
	
Methods Summary
public voidaddArgument(java.lang.String name, java.lang.String value)

		arg_names.add( name );
		
		arg_values.add( value );
	
public UPnPActionArgument[]invoke()

	
		UPnPService	service = action.getService();
		
		String	soap_action = service.getServiceType() + "#" + action.getName();
		
		try{
			String	request =
				"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"+
				"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"+
					"  <s:Body>\n";
													
			request += "    <u:" + action.getName() + 
							" xmlns:u=\"" + service.getServiceType()+ "\">\n";
			
			
			for (int i=0;i<arg_names.size();i++){
			
				String	name 	= (String)arg_names.get(i);
				String	value 	= (String)arg_values.get(i);
				
				request += "      <" + name + ">" + value + "</" + name + ">\n";
			}
			
			request += "    </u:" + action.getName() + ">\n";

			request += "  </s:Body>\n"+
						"</s:Envelope>";
							
				// try standard POST
			
			SimpleXMLParserDocument resp_doc	= ((UPnPDeviceImpl)action.getService().getDevice()).getUPnP().performSOAPRequest( service, soap_action, request );
						
			SimpleXMLParserDocumentNode	body = resp_doc.getChild( "Body" );
			
			SimpleXMLParserDocumentNode fault = body.getChild( "Fault" );
			
			if ( fault != null ){
				
				throw( new UPnPException( "Invoke of '" + soap_action + "' failed - fault reported: " + fault.getValue()));
			}
			
			SimpleXMLParserDocumentNode	resp_node = body.getChild( action.getName() + "Response" );
			
			if ( resp_node == null ){
				
				throw( new UPnPException( "Invoke of '" + soap_action + "' failed - response missing: " + body.getValue()));
			}
			
			SimpleXMLParserDocumentNode[]	out_nodes = resp_node.getChildren();
			
			UPnPActionArgument[]	resp = new UPnPActionArgument[out_nodes.length];
			
			for (int i=0;i<out_nodes.length;i++){
				
				resp[i] = new UPnPActionArgumentImpl( out_nodes[i].getName(), out_nodes[i].getValue());
			}
			
			return( resp );
			
		}catch( Throwable e ){
			
			if ( e instanceof UPnPException ){
				
				throw((UPnPException)e);
			}
			
			throw( new UPnPException( "Invoke of '" + soap_action + "' on '" + action.getService().getControlURL() + "' failed: " + e.getMessage(), e ));	
		}
	
public java.util.Mapinvoke2()

		UPnPActionArgument[]	res = invoke();
		
		Map	map = new HashMap();
		
		for (int i=0;i<res.length;i++){
			
			map.put( res[i].getName(), res[i].getValue());
		}
		
		return( map );