XML-RPC using Android

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

XML-RPC using Android

Postby Gekirou » Mon Dec 27, 2010 10:51 pm

Dear Community,

i'm trying to make my android connect to my OSGi XML-RPC server, but i am having some issues with this.

My Webserver (using Apache XML-RPC):
Code: Select all
public void startWebserver() {
       webServer = new WebServer(port);
         XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
         PropertyHandlerMapping phm = new PropertyHandlerMapping();
         
         AuthenticationHandler myAuth = new AuthenticationHandler(){
         @Override
         public boolean isAuthorized(XmlRpcRequest pRequest)
               throws XmlRpcException {

//            XmlRpcHttpRequestConfig config = (XmlRpcHttpRequestConfig) pRequest.getConfig();
//               return "myuser".equals(config.getBasicUserName()) && "mypw".equals(config.getBasicPassword());
            return true;
         }
         };
         
         phm.setAuthenticationHandler(myAuth);
         try {
         phm.load(Thread.currentThread().getContextClassLoader(), "properties");
      } catch (IOException e) {
         System.out.println("IO Exception!");
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (XmlRpcException e) {
         System.out.println("Bla bla");
         e.printStackTrace();
      }

         xmlRpcServer.setHandlerMapping(phm);
         XmlRpcServerConfigImpl serverConfig =  (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
         serverConfig.setEnabledForExtensions(true);
         serverConfig.setContentLengthOptional(false);
         try {
         webServer.start();
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }   
   }


My Android Application:
Code: Select all
public void initGUI() {
           setContentView(R.layout.mymain);
            l = (LinearLayout) findViewById(R.id.myMainLayout);
            linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         
           
            try {
             serverURL = new URL(server+":"+port);
          } catch (MalformedURLException e) {
             System.out.println("Invalid URL - could not connect!");
          }
          
          myServer = new XMLRPCClient(serverURL);
          myServer.setBasicAuthentication("myuser", "mypw", true);
          
            HashMap<String,Integer> state=null;
          Object[] params = new Object[]{new Integer(33)};

          try {
             state = (HashMap<String,Integer>) myServer.call("Tester.getStatement", params );
          } catch (XMLRPCException e) {e.printStackTrace();}
          state.size();

           
           
//            myView = new View[state.size()];
//            buttons = new ToggleButton[state.size()];
//            txt = new TextView[state.size()];
           
            myView = new View[15];
            buttons = new ToggleButton[15];
            txt = new TextView[15];
           
//          Iterator<Entry<String, Integer>> itr = state.entrySet().iterator();
          Entry<String, Integer> entry;
          int i =0;
//            while(itr.hasNext()){
//            entry = itr.next();
            myView[i] = linflater.inflate(R.layout.myviews, null);
            buttons[i] = (ToggleButton) myView[i].findViewById(R.id.ToggleButton01);
            buttons[i].setId(i);
            txt[i] = (TextView) myView[i].findViewById(R.id.Module);
            txt[i].setText(("Device "/*+entry.getKey().substring(entry.getKey().indexOf('#')+1)+*/+" Status").toString());
//            uri = entry.getKey();
            buttons[i].setOnCheckedChangeListener(new OnCheckedChangeListener(){

//               String uriHere = uri;
             @Override
             public void onCheckedChanged(CompoundButton buttonView,
                   boolean isChecked) {   
                //switchState(uriHere);
             }
            });
           
         
            l.addView(myView[i]);
            i++;
           


I willingly commented out most of my code, using the hashmap. I am (logically) getting no problems, when i comment out the command " state.size();". My Server keeps return me a "XMLRPCnotAuthorized Exception". When i change the webserver auth-method to it's original, nothing changes. I am using this android XML-RPC library: "http://code.google.com/p/android-xmlrpc/".

Could anyone help me?

Thanks!

greetings,
Geki
Gekirou
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 27, 2010 10:45 pm

Top

Re: XML-RPC using Android

Postby Ath » Tue Dec 28, 2010 12:01 am

You could check out the code for OpenJira, that also uses XML-RPC to connect to a Jira server Guess it uses the same code. Project is OSS and can be found here: http://code.google.com/p/openjira/
/Ath
Ath
Developer
Developer
 
Posts: 42
Joined: Sun Jun 06, 2010 6:07 pm
Location: NL

Re: XML-RPC using Android

Postby Gekirou » Tue Dec 28, 2010 1:16 pm

Small update:

I got it working with my AuthMethod always returning true, but can't connect without this. It always gives me a notAuhtorizedException. Switching the auth method to preemptive doesn't change anything.

I will give openJIRA a look. I hope that it doesn't wrap to much around XML-RPC. The Server should be usable for both - C++ and Java.

I would be thankful for further help!

greetings,
Geki
Gekirou
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 27, 2010 10:45 pm

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 5 guests