Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8734

Re: SMP 3.0 - OData CRUD Help

$
0
0

Hi Midhun VP,

I tried to implement a CREATE operation in the way described below:

 

protected void setUp() throws Exception {                try{            //final ISDMNetListener listener;            mPreferences = new SDMPreferences(mContext, mLogger);            mLogger.setLogLevel(ISDMLogger.DEBUG);                    param = new SDMConnectivityParameters();                            //Setting the username and password for the request response            param.setUserName("abapdev");            param.setUserPassword("hp@1234");                        //If the application end point if of odata, then call enableXsrf            if(Utilities.appSettings.getApplicationEndPoint().indexOf("odata")>0)                param.enableXsrf(true);                        reqMan = new SDMRequestManager(mLogger, mPreferences, param, 1);                parser = new SDMParser(mPreferences, mLogger);            mPreferences.setIntPreference(ISDMPreferences.SDM_CONNECTIVITY_CONNTIMEOUT, 7000);                                }  catch (Exception e) {                }                }    
public void postOperation()    {        try {                        setUp();            //Make post request after setting the postURL and postData        String PostURL =Utilities.appSettings.getApplicationEndPoint() +"yuserrfc1Collection";                String postdata ="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"            +"<entry\n"            +"xml:base=\""+Utilities.appSettings.getApplicationEndPoint()+"\""+"\n"            +"xmlns=\"http://www.w3.org/2005/Atom\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\"\n"            +"xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\">\n"            +"<category term=\"Y_USER_RFC1.yuserrfc1\"\n"                  +"scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\" />\n"            +"<content type=\"application/atom+xml\">\n"                  +"<m:properties>\n"                        +"<d:title_p/>n"                        +"<d:region/>\n"                        +"<d:country/>\n"                        +"<d:username>"+username+"</d:username>\n"                        +"<d:city/>\n"                        +"<d:islocked/>\n"                        +"<d:department/>\n"                        +"<d:lastname>"+lastname+"</d:lastname>\n"                        +"<d:comm_type/>\n"                        +"<d:telephone/>\n"                        +"<d:password>"+"welcome1"+"</d:password>\n"                        +"<d:name/>\n"                        +"<d:e_mail/>\n"                        +"<d:fullname>"+firstname+" "+lastname+"</d:fullname>\n"                        +"<d:firstname>"+firstname+"</d:firstname>\n"                        +"<d:language/>\n"                        +"<d:title/>\n"                        +"<d:userid/>\n"                  +"</m:properties>\n"            +"</content>\n"      +"</entry>";                    postrequest.setRequestMethod(ISDMRequest.REQUEST_METHOD_POST);        postrequest.setRequestUrl(PostURL);        postrequest.setListener(this);                    Map<String,String> headers = new HashMap<String,String>();        headers.put("Content-Type", "application/atom+xml");        postrequest.setHeaders(headers);        final byte[] theByteArray = postdata.getBytes();        postrequest.setData(theByteArray);        reqMan.makeRequest(postrequest);                //Wait until we get some response        synchronized (lockObject) {            try {                lockObject.wait();            } catch (InterruptedException e) {                Log.i("App msg", "request failed: "+e.getMessage());                            }        }                } catch (Exception e1) {            // TODO Auto-generated catch block            e1.printStackTrace();        }            }

Is there something wrong with this method? When I try to create record, it returns me "Create Successful" but the record never gets created.

 

This is my create activity on a Submit button.

 

btnSubmit.setOnClickListener(new OnClickListener(){
//            @Override            public void onClick(View v) {                //On clicking the save button, take values for the UI and pass them to the variables                //in request response class                ApplicationActivity.username  = edUser.getText().toString();                ApplicationActivity.firstname = edFirst.getText().toString();                ApplicationActivity.lastname = edLast.getText().toString();                                                 //After taking the inputs from the UI, call the postOperation method in CRUDOperations.java class                ApplicationActivity crud = new ApplicationActivity();                crud.mContext = CreateActivity.this;                crud.postOperation();                                //Get the response code after doing the post operation and show success or failure                //based on the response code                if((ApplicationActivity.responseCode == 200) || (ApplicationActivity.responseCode == 201) || (ApplicationActivity.responseCode == 204))                {                    Toast toast = Toast.makeText(CreateActivity.this, "Create successful", Toast.LENGTH_LONG);                    toast.show();                }                else                {                    Toast toast = Toast.makeText(CreateActivity.this, "Create Unsuccessful with error code" + String.valueOf(ApplicationActivity.responseCode), Toast.LENGTH_LONG);                    toast.show();                }                finish();            }                    });

Viewing all articles
Browse latest Browse all 8734


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>