EldoS | Feel safer!

Software components for data protection, secure storage and transfer

JAVA HTTPSPost & HTTSServer : how to post/retrieve parameters ?

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#35849
Posted: 02/05/2016 06:41:08
by Yann Fontaine (SUPPORT DISABLED)
Joined: 02/01/2016
Posts: 39

Hi,

i tried to test JAVA HTTPSPost and HTTPSServer examples, but removing for the moment SSL (will do it later, one problem at a time)

I managed to send a file, but i don't know how to post/retrieve additional infos

Here is the example :
String FilePath = tbPath.getText().trim();
TElFileStream stream = new TElFileStream(FilePath, "r", true);
TElStringList SL = new TElStringList();
SL.add("upload", "Upload");
SL.add("RVR", "PARAD");
SL.add("TOTO=TITI");

pbUploading.setMinimum(0);
pbUploading.setMaximum((int) (stream.getLength() / 1024));
pbUploading.setValue(0);

try
{
HTTPSClient.postWebForm(tbURL.getText(), SL, "userfile", FilePath, stream, "", true);
}

1st question :
--------------

how to retrieve the matching values of TElStringList in the serverside ?
I tried to modifiy the ClientThread class, but don't where are these values (only find name)
private void saveFiles(TElMultipartFormList mpl)
{
TElMultipartFormData mfd;
for (int i = 0; i < mpl.getCount(); i++)
{
mfd = mpl.getValuesByIndex(i);
if (mfd instanceof TElMultipartFormList)
{
saveFiles((TElMultipartFormList)mfd);
}
else if (mfd.getFileName() != "")
{
try{
FileOutputStream fos = new FileOutputStream(m_basePath + "/" + mfd.getFileName());
try {
fos.write(m_uploadStream.getBuffer(), (int)mfd.getContentStartPos(), (int)mfd.getContentSize());
} finally {
fos.close();
}
}catch (Exception ex)
{
m_currentResponse.setStatusCode(500);
}
}
else
{
System.out.println ("String Name->"+mfd.getName ()); // here i can get upload, RVR, TOTO
// WHERE TO FIND THE MATCHING VALUE(S) ???

}
}
}

2nd question :
--------------

is there any other way to post (typed) values, like boolean, interger, or other primitive types ?

3rd question :
--------------

How to retrieve the values of the 2nd question ?

Thanks for your reply.
I'm searching for hours, and very annoying

Another thing : When running and debbuging theses examples, i can see high CPU usage... Some Thread(s) serverside are nor free after use.. I think it's for that...

Waiting for help

Yann
#35850
Posted: 02/05/2016 07:20:06
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

Quote
1st question :
--------------
how to retrieve the matching values of TElStringList in the serverside ?


You should collect all incoming data using TElHTTPSServer.OnData method and then use TElHTTPSServer.ParseMultipartFormData method to parse it into TElMultipartFormList object:

1. https://www.eldos.com/documentation/sb...ndata.html
2. https://www.eldos.com/documentation/sb...mdata.html

TElMultipartFormList allows to retrieve received parameters and their values.

Quote
is there any other way to post (typed) values, like boolean, interger, or other primitive types ?

HTTP alows to post textual data, but you can interpret this data according to your needs. All data convertions should be done manually.

Quote
When running and debbuging theses examples, i can see high CPU usage

The sample is just a simple demonstration of components usage. Network related part should be reviewed and optimized to use in production.
#35851
Posted: 02/05/2016 09:28:13
by Yann Fontaine (SUPPORT DISABLED)
Joined: 02/01/2016
Posts: 39

But, with the example ?
Is this parsed and filled anywhere ?

i can see in the ClientThread example, defined with

m_httpsServ.setOnData(new TSBDataEvent(onData));

and later, i uses

m_uploadStream.setPosition(0);
TElMultipartFormList mpl = m_httpsServ.parseMultipartFormData(m_currentRequest, m_uploadStream, false);
saveFiles(mpl);

so, the parseMultipartFormData i called.

What i have to modify to get my values (because i retrieve the keys, so values may be somewhere, but don't know where to search, what method to call...)
#35852
Posted: 02/05/2016 09:43:39
by Vsevolod Ievgiienko (EldoS Corp.)

The code will look next way:

Code
TElMultipartFormList mpl = ...;
TElMultipartFormData rvr = mpl.getValuesByName("RVR");
String value = new String(rvr.getContent()); // should contain "PARAD"
#35892
Posted: 02/16/2016 04:49:43
by Yann Fontaine (SUPPORT DISABLED)
Joined: 02/01/2016
Posts: 39

Hi,

this doesn't work :-(

TElMultipartFormData mfd;
for (int i = 0; i < mpl.getCount(); i++)
{
mfd = mpl.getValuesByIndex(i);
if (mfd instanceof TElMultipartFormList)
{
saveFiles((TElMultipartFormList)mfd);
}
else if (mfd.getFileName() != "")
{
try{
FileOutputStream fos = new FileOutputStream(m_basePath + "/" + "aze.xlsx");//mfd.getFileName());
try {
fos.write(m_uploadStream.getBuffer(), (int)mfd.getContentStartPos(), (int)mfd.getContentSize());
} finally {
fos.close();
}
}catch (Exception ex)
{
m_currentResponse.setStatusCode(500);
}
}
else
{
/// HERE I PUT YOUR CODE TO GET VALUES
TElMultipartFormData aValues = mpl.getValuesByName(mfd.getName ());
System.out.println ("String Name->"+mfd.getName ()+" = "+new String (aValues.getContent ()));
}
}
#35898
Posted: 02/16/2016 07:18:20
by Vsevolod Ievgiienko (EldoS Corp.)

Code
TElMultipartFormList mpl = m_httpsServ.parseMultipartFormData(m_currentRequest, m_uploadStream, false);

Please change the 3rd parameter to 'true'. This should help:

Code
TElMultipartFormList mpl = m_httpsServ.parseMultipartFormData(m_currentRequest, m_uploadStream, true);
#35939
Posted: 02/18/2016 11:50:22
by Yann Fontaine (SUPPORT DISABLED)
Joined: 02/01/2016
Posts: 39

Hi Vsevolod,

thanks, yes, this parameter changed the result, and now i can retrieve my values
But without any clear doc, still impossible to know what are capabilities, and what params/methods does
It's very handicapping & frustrating (and time consuming) !
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 1977 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!