felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From furf...@apache.org
Subject svn commit: r425350 - in /incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/upnp/ src/main/java/...
Date Tue, 25 Jul 2006 09:33:39 GMT
Author: furfari
Date: Tue Jul 25 02:33:38 2006
New Revision: 425350

URL: http://svn.apache.org/viewvc?rev=425350&view=rev
Log:
Simple utility to test UPnPException sending custom SOAP messages Felix-67

Added:
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/upnp/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/upnp/test/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/upnp/test/soap/
    incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/upnp/test/soap/TestSOAP.java

Added: incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/upnp/test/soap/TestSOAP.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/upnp/test/soap/TestSOAP.java?rev=425350&view=auto
==============================================================================
--- incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/upnp/test/soap/TestSOAP.java
(added)
+++ incubator/felix/sandbox/furfari/org.apache.felix.upnp.test.soap/src/main/java/org/apache/felix/upnp/test/soap/TestSOAP.java
Tue Jul 25 02:33:38 2006
@@ -0,0 +1,165 @@
+/*
+DomoWare UPnP Base Driver is an implementation of the OSGi UnP Device Specifaction
+Copyright (C) 2006 Matteo Demuru, Francesco Furfari, Stefano "Kismet" Lenzi
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+You can contact us at:
+	{matte-d, sygent, kismet-sl} [at] users.sourceforge.net
+*/
+
+package org.apache.felix.upnp.test.soap;
+
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.StringTokenizer;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+public class TestSOAP {
+
+    public static void main(String[] args) throws IOException {
+        new TestSoapFrame();
+    }
+
+}
+
+class TestSoapFrame extends JFrame {
+    
+    private JTextField txtControlUrl;
+    private JTextArea txtRequestProperty;
+    private JTextArea txtRequest;
+    private JTextArea txtResponse;
+
+    public TestSoapFrame(){
+        super("Test SOAP messages");
+        setSize(750,600);
+        setResizable(false);
+        //getContentPane().setLayout(new GridLayout(0,1));
+        getContentPane().setLayout(new FlowLayout());
+        
+        JLabel lblControlUrl = new JLabel("Controlo URL");
+        txtControlUrl = new JTextField("http://192.168.48.1:4004/service/0/ctrl",65);
+        
+        JLabel lblRequestProperty= new JLabel("Request Property");
+        txtRequestProperty = new JTextArea(5,65);
+        txtRequestProperty.append("Content-type text/xml; charset=\"utf-8\"\n");
+        txtRequestProperty.append("SOAPACTION urn:schemas-upnp-org:service:SwitchPower:1#SetTarget\n");
+        txtRequestProperty.append("Connection close\n");
+        txtRequestProperty.validate();
+        
+        JLabel lblRequest= new JLabel("Content Request");
+        txtRequest = new JTextArea(10,65);
+        txtRequest.append("<?xml version='1.0' encoding='utf-8'?>\n");
+        txtRequest.append("<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'
s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>\n");
+        txtRequest.append("  <s:Body>\n");
+        txtRequest.append("    <u:SetTarget xmlns:u='urn:schemas-upnp-org:service:SwitchPowerx:1'>\n");
+        txtRequest.append("      <NewTargetValue>0</NewTargetValue>\n");
+        txtRequest.append("    </u:SetTarget>\n");
+        txtRequest.append("  </s:Body>\n");
+        txtRequest.append("</s:Envelope>\n");
+        
+        JLabel lblResponse= new JLabel("Response");
+        txtResponse = new JTextArea(10,65);
+       
+        JButton btnSend = new JButton("Send");
+        btnSend.addActionListener(new ActionListener(){
+            private HttpURLConnection connection;
+
+            public void actionPerformed(ActionEvent e) {
+              try {
+                txtResponse.setText("");
+                URL netUrl = new URL(txtControlUrl.getText());
+                connection = (HttpURLConnection) netUrl.openConnection();
+                
+                connection.setRequestMethod( "POST" );
+                connection.setRequestProperty("Content-Length", "" + Integer.toString(txtRequest.getText().getBytes().length));
+                StringTokenizer tokenizer = new StringTokenizer(txtRequestProperty.getText(),"\n");
+                while (tokenizer.hasMoreTokens()){
+                    String line = tokenizer.nextToken();
+                    String property = line.substring(0,line.indexOf(" "));
+                    String value = line.substring(line.indexOf(" ")+1).trim();
+                    connection.setRequestProperty(property, value);
+                }
+                
+                connection.setUseCaches(false);
+                connection.setDoInput(true);
+                connection.setDoOutput(true);
+              
+              DataOutputStream out = new DataOutputStream( connection.getOutputStream() );
+              out.writeBytes( txtRequest.getText());
+              out.flush();
+              out.close();
+      
+              InputStreamReader isr = new InputStreamReader(connection.getInputStream())
;
+              BufferedReader reader = new BufferedReader(isr);
+              String response = reader.readLine();
+              while( null != response ) {
+                  txtResponse.append( response + "\n");
+                  response = reader.readLine();
+              }
+                
+            } catch (Exception ex) {
+                txtResponse.setText("");
+                txtResponse.setText(ex.toString() + "\n");    
+                try {
+                    InputStreamReader isr = new InputStreamReader(connection.getErrorStream())
;
+                    BufferedReader reader = new BufferedReader(isr);
+                    String response = reader.readLine();
+                    while( null != response ) {
+                        txtResponse.append( response + "\n");
+                        response = reader.readLine();
+                    }
+                } catch (Exception ex2){
+                     txtResponse.append(ex2.toString()+"\n");
+                }
+            }
+            
+        }});
+        getContentPane().add(lblControlUrl);
+        getContentPane().add(txtControlUrl);
+        getContentPane().add(lblRequestProperty);
+        getContentPane().add(new JScrollPane(txtRequestProperty));
+        getContentPane().add(lblRequest);
+        getContentPane().add(new JScrollPane(txtRequest));
+        getContentPane().add(lblResponse);
+        getContentPane().add(new JScrollPane(txtResponse));
+        getContentPane().add(btnSend);
+        setVisible(true);
+        
+        addWindowListener(new WindowAdapter(){
+            public void windowClosing(WindowEvent e) 
+            {
+                dispose();
+            }
+        });         
+       
+    }
+    
+ }
\ No newline at end of file



Mime
View raw message