Rest Services

  • Replies:7
  • OpenNot stickiedUnanswered

Apr 19, 2012 8:41:42 PM via Website

I am new to android application development.I am creating a application to call wcf REST service .Any help to get me started will be appreciated. Thanks.

Feb 6, 2013 1:27:27 PM via Website

Hi,

Sorry to interrupt the thread. I am very new to this forum. I am also trying to connect to REST services of Business Objects as POC and I am unable to establish connection.

I am gettting the following error when i try to make use of the consumer jars provided by BO 4.0. Please help me to proceed further with this.

Got struck with this for the whole day now.

[2013-02-06 17:37:36 - BOAndroidApp] Dx
trouble processing "javax/xml/namespace/NamespaceContext.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.

[2013-02-06 17:37:36 - BOAndroidApp] Dx 1 error; aborting
[2013-02-06 17:37:36 - BOAndroidApp] Conversion to Dalvik format failed with error 1

Feb 7, 2013 9:42:06 AM via Website

Thanks for your response.

I try to develop an android application which would connect to Business Objects server and retrieve the details required.

I use BO 4.0 Webservices Consumer SDK jars provided by business objects, rt.jar (without which i get java.rmi.remoteException error), axis2-kernel-1.3.jar, xbean-2.2.0.jar apart from android jar.

I dont get any compilation error when i build the code. But when i try to run , i get the below error.

Please help me !!!!

Sample code:

package com.example.testandroid;

import java.net.URL;
import com.businessobjects.dsws.Connection;
import com.businessobjects.dsws.session.Session;
import com.businessobjects.dsws.session.EnterpriseCredential;
import com.businessobjects.dsws.session.SessionInfo;
import com.businessobjects.dsws.biplatform.BIPlatform;
import com.businessobjects.dsws.biplatform.ResponseHolder;
import com.businessobjects.enterprise.infoobject.InfoObject;
import com.businessobjects.dsws.biplatform.constants.FixedCUIDs;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity
{
public static String serviceURL = "XX";
public static String cmsname = "XXX";
public static String username = "XX";
public static String password = "XX";
public static String authType = "XX";

Button btnCel;
TextView txtView;


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);

btnCel = (Button) findViewById(R.id.btnCel);
txtView =(TextView)findViewById(R.id.textView2);

btnCel.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

// Create the URL for the Session Service and instantiate a new Session
// Service
try
{

URL sessConnURL = new URL(serviceURL);
Connection boConnection = new Connection(sessConnURL);

// Setup the Enterprise Credentials used to login to the Enterprise System
EnterpriseCredential boCredential = EnterpriseCredential.Factory.newInstance();

boCredential.setLogin(username);
boCredential.setPassword(password);
boCredential.setAuthType(authType);

Session boSession = new Session(boConnection);

// Login to the Enterprise System and retrieve the SessionInfo
SessionInfo boSessionInfo = boSession.login(boCredential);

— modified on Feb 7, 2013 9:45:28 AM

Feb 16, 2013 4:01:33 PM via Website

At first sight, i found one error: you are calling networking code from UI thread.

Long-lasting operations are not permitted on UI thread. You must use another thread, or use Handler, or AsyncTask.

In your case, AsyncTask is best choice, i think.

Best regards.

Feb 18, 2013 11:10:04 PM via Website

Hi,

Never use AsyncTask to perform network request or whatever that need to be persisted. Async Task are strongly tied to your activity and if the user change the orientation of the screen since the App is re created the AsyncTask will be stopped.

I suggest you to use Service pattern with Intent Service and ResultReceiver. Take a look to RESTDroid (search for RESTDroid by PCreations in Github). It's a library that allows you to perform any kind of REST request asynchronously and notify your UI with Request Listeners implementing the Virgil Dobjanschi's service pattern and using POJO's (here POJOs can be you Business Objects)

— modified on Feb 18, 2013 11:10:46 PM