Home > Mobile >  Why Android client even not DataSnap Restful server
Why Android client even not DataSnap Restful server

Time:09-28

I early contact with the development of Android, now want to try the Android connected with Delphi XE10.3 developed a DataSnap Restful server, the following code can be compiled through, but the runtime cannot perform server functions, execution to catch, print error messages is Null, and can use the browser on the computer or mobile phone in the normal execution of this Restful server, the code is as follows (kotlin) : ask everybody to help see what reason, thank you very much!

Package com. Arkon. Edittexttest

The import androidx. Appcompat. App. AppCompatActivity
The import android. OS. Bundle
Import the embarcadero. Javaandroid. DBXException
Import the embarcadero. Javaandroid. DSProxy
Import the embarcadero. Javaandroid. DSRESTConnection
The import kotlinx. Android. Synthetic. Main. Activity_main. *

The class MainActivity: AppCompatActivity () {
Override fun onCreate (savedInstanceState: Bundle? {
Super. OnCreate (savedInstanceState)
The setContentView (R.l ayout. Activity_main)

BtnReverse. SetOnClickListener {
Val conn: DSRESTConnection?=DSRESTConnection ()
Conn? The host="172.16.9.12"
Conn? Port=8080
Conn? The protocol="HTTP"
Val serverProxy: DSProxy TMyTestServerMethods?=DSProxy. TMyTestServerMethods (conn)
Try {
Var s: String?=serverProxy? ReverseString (edtText. Text. The toString ())
Label2. Text=s
{} the catch (e: DBXException)
E.p rintStackTrace ()
Label2. Text="error, error message:" + e.m essage
}
}
}
}

Yes test code above, the following is used in the Java package (Delphi program automatically generated), but because of space constraints can't completely,
Package the embarcadero. Javaandroid;

import java.util.Date;

Public class DSProxy {
Public static class TMyTestServerMethods extends DSAdmin {
Public TMyTestServerMethods (DSRESTConnection Connection) {
Super (Connection).
}


Private DSRESTParameterMetaData [] TMyTestServerMethods_EchoString_Metadata;
Private DSRESTParameterMetaData [] get_TMyTestServerMethods_EchoString_Metadata () {
If (TMyTestServerMethods_EchoString_Metadata=null https://bbs.csdn.net/topics/={
TMyTestServerMethods_EchoString_Metadata=https://bbs.csdn.net/topics/new DSRESTParameterMetaData [] {
New DSRESTParameterMetaData (" Value ", DSRESTParamDirection. Input, DBXDataTypes WideStringType, "string"),
New DSRESTParameterMetaData (" ", DSRESTParamDirection. ReturnValue DBXDataTypes. WideStringType, "string"),
};
}
Return TMyTestServerMethods_EchoString_Metadata;
}

/* *
* @ param Value [in] -type on server: string
* @ return result -type on server: string
*/
Public String you (String Value) throws DBXException {
DSRESTCommand CMD=getConnection (). CreateCommand ();
CMD. SetRequestType (DSHTTPRequestType. GET);
CMD. SetText (" TMyTestServerMethods. You ");
CMD. Prepare (get_TMyTestServerMethods_EchoString_Metadata ());
CMD. The getParameter (0). The getValue () SetAsString (Value);
GetConnection (). The execute (CMD);
Return CMD. The getParameter (1). The getValue (). The GetAsString ();
}


Private DSRESTParameterMetaData [] TMyTestServerMethods_ReverseString_Metadata;
Private DSRESTParameterMetaData [] get_TMyTestServerMethods_ReverseString_Metadata () {
If (TMyTestServerMethods_ReverseString_Metadata=null https://bbs.csdn.net/topics/={
TMyTestServerMethods_ReverseString_Metadata=https://bbs.csdn.net/topics/new DSRESTParameterMetaData [] {
New DSRESTParameterMetaData (" Value ", DSRESTParamDirection. Input, DBXDataTypes WideStringType, "string"),
New DSRESTParameterMetaData (" ", DSRESTParamDirection. ReturnValue DBXDataTypes. WideStringType, "string"),
};
}
Return TMyTestServerMethods_ReverseString_Metadata;
}

/* *
* @ param Value [in] -type on server: string
* @ return result -type on server: string
*/
Public String ReverseString (String Value) throws DBXException {
DSRESTCommand CMD=getConnection (). CreateCommand ();
CMD. SetRequestType (DSHTTPRequestType. GET);
CMD. SetText (" TMyTestServerMethods ReverseString ");
CMD. Prepare (get_TMyTestServerMethods_ReverseString_Metadata ());
CMD. The getParameter (0). The getValue () SetAsString (Value);
GetConnection (). The execute (CMD);
Return CMD. The getParameter (1). The getValue (). The GetAsString ();
}
}

}


Package the embarcadero. Javaandroid;

import java.io.InputStream;
Import the Java. IO. UnsupportedEncodingException;
The import java.net.URLEncoder;
Import the Java. Security. KeyManagementException;
Import the Java. Security. KeyStoreException;
Import the Java. Security. NoSuchAlgorithmException;
Import the Java. Security. UnrecoverableKeyException;
Import the Java. Util. LinkedList;
import java.util.List;

The import org. Apache. HTTP. Header;
The import org. Apache. HTTP. HeaderElement;
The import org. Apache. HTTP. HttpResponse;
The import org. Apache. HTTP. Client. HttpClient;
The import org. Apache. HTTP. Client. The methods. HttpDelete;
The import org. Apache. HTTP. Client. The methods. HttpGet;
The import org. Apache. HTTP. Client. The methods. The HttpPost;
The import org. Apache. HTTP. Client. The methods. HttpPut;
The import org. Apache. HTTP. Client. The methods. HttpUriRequest;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related