Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hds
flexin
android-app
Commits
04475844
Commit
04475844
authored
Oct 25, 2017
by
Nastuzzi Samy
Browse files
Optimization
Preparation of NemopaySession Add/Optimization of HttpRequest methods
parent
54e5cc85
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/payutc/MainActivity.java
View file @
04475844
...
...
@@ -17,12 +17,14 @@ import android.widget.Toast;
import
fr.utc.simde.payutc.tools.NFCActivity
;
import
fr.utc.simde.payutc.tools.CASConnexion
;
import
fr.utc.simde.payutc.tools.Dialog
;
import
fr.utc.simde.payutc.tools.NemopaySession
;
public
class
MainActivity
extends
NFCActivity
{
private
static
final
String
LOG_TAG
=
"MainActivity"
;
private
static
Boolean
registered
=
false
;
private
static
Dialog
dialog
;
private
static
NemopaySession
nemopaySession
;
private
static
CASConnexion
casConnexion
;
private
static
TextView
AppConfigText
;
...
...
@@ -35,7 +37,8 @@ public class MainActivity extends NFCActivity {
setContentView
(
R
.
layout
.
activity_main
);
dialog
=
new
Dialog
(
MainActivity
.
this
);
casConnexion
=
new
CASConnexion
();
nemopaySession
=
new
NemopaySession
();
casConnexion
=
new
CASConnexion
(
nemopaySession
);
AppConfigText
=
findViewById
(
R
.
id
.
text_app_config
);
AppRegisteredText
=
findViewById
(
R
.
id
.
text_app_registered
);
...
...
app/src/main/java/fr/utc/simde/payutc/tools/CASConnexion.java
View file @
04475844
...
...
@@ -8,14 +8,13 @@ import android.util.Log;
public
class
CASConnexion
{
private
static
final
String
LOG_TAG
=
"CASConnexion"
;
private
static
final
String
casUrl
=
"https://api.nemopay.net/services/POSS3/getCasUrl?system_id=payutc"
;
private
static
final
String
service
=
"http://localhost"
;
private
String
url
;
private
String
username
;
private
String
location
;
private
String
ticket
;
public
CASConnexion
()
{
public
CASConnexion
(
final
NemopaySession
nemopaySession
)
{
this
.
url
=
""
;
this
.
username
=
""
;
this
.
location
=
""
;
...
...
@@ -25,9 +24,8 @@ public class CASConnexion {
@Override
public
void
run
()
{
try
{
HTTPRequest
http
=
new
HTTPRequest
(
casUrl
);
http
.
post
();
url
=
http
.
getResponse
();
HTTPRequest
request
=
nemopaySession
.
getCasUrl
();
url
=
request
.
getResponse
();
url
=
url
.
substring
(
1
,
url
.
length
()
-
1
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
...
...
@@ -48,13 +46,13 @@ public class CASConnexion {
if
(
this
.
url
.
isEmpty
()
||
username
.
isEmpty
()
||
password
.
isEmpty
())
throw
new
RuntimeException
(
"Elements required"
);
HTTPRequest
http
=
new
HTTPRequest
(
this
.
url
+
"v1/tickets/"
);
http
.
setArg
(
"username"
,
username
);
http
.
setArg
(
"password"
,
password
);
HTTPRequest
request
=
new
HTTPRequest
(
this
.
url
+
"v1/tickets/"
);
request
.
setArg
(
"username"
,
username
);
request
.
setArg
(
"password"
,
password
);
if
(
http
.
post
()
==
201
)
{
Log
.
d
(
LOG_TAG
,
http
.
getHeader
(
"Location"
));
this
.
location
=
http
.
getHeader
(
"Location"
);
if
(
request
.
post
()
==
201
)
{
Log
.
d
(
LOG_TAG
,
request
.
getHeader
(
"Location"
));
this
.
location
=
request
.
getHeader
(
"Location"
);
}
else
throw
new
RuntimeException
(
"Not Connected"
);
...
...
@@ -71,11 +69,11 @@ public class CASConnexion {
if
(
this
.
url
.
isEmpty
()
||
this
.
username
.
isEmpty
()
||
this
.
location
.
isEmpty
())
throw
new
RuntimeException
(
"Elements required"
);
HTTPRequest
http
=
new
HTTPRequest
(
this
.
location
);
http
.
setArg
(
"service"
,
this
.
service
);
HTTPRequest
request
=
new
HTTPRequest
(
this
.
location
);
request
.
setArg
(
"service"
,
this
.
service
);
if
(
http
.
post
()
==
200
)
{
this
.
ticket
=
http
.
getResponse
();
if
(
request
.
post
()
==
200
)
{
this
.
ticket
=
request
.
getResponse
();
Log
.
d
(
LOG_TAG
,
this
.
ticket
);
}
else
...
...
app/src/main/java/fr/utc/simde/payutc/tools/HTTPRequest.java
View file @
04475844
...
...
@@ -82,6 +82,13 @@ public class HTTPRequest {
return
this
.
request
.
getHeaderField
(
name
);
}
public
int
getResponseCode
()
throws
IOException
{
if
(
this
.
request
==
null
)
return
Integer
.
parseInt
(
null
);
return
this
.
request
.
getResponseCode
();
}
public
String
getResponseMessage
(
final
String
name
)
throws
IOException
{
if
(
this
.
request
==
null
)
return
null
;
...
...
@@ -113,6 +120,10 @@ public class HTTPRequest {
return
data
.
substring
(
0
,
data
.
equals
(
""
)
?
0
:
data
.
length
()
-
1
);
}
public
void
setArgs
(
Map
<
String
,
String
>
args
)
{
this
.
args
=
args
;
}
public
void
setArg
(
final
String
key
,
final
String
value
)
{
this
.
args
.
put
(
key
,
value
);
}
...
...
app/src/main/java/fr/utc/simde/payutc/tools/NemopaySession.java
View file @
04475844
package
fr.utc.simde.payutc.tools
;
import
java.io.IOException
;
import
java.net.HttpURLConnection
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created by Samy on 24/10/2017.
*/
public
class
NemopaySession
{
private
static
final
String
LOG_TAG
=
"NemopaySession"
;
private
static
final
String
url
=
"https://api.nemopay.net/services/"
;
private
String
key
;
private
String
session
;
private
String
username
;
public
NemopaySession
(
final
String
session
,
final
String
username
)
{
this
.
session
=
session
;
this
.
username
=
username
;
private
final
Map
<
String
,
String
>
defaultArgs
=
new
HashMap
<
String
,
String
>()
{{
put
(
"system_id"
,
"payutc"
);
}};
public
NemopaySession
()
{
this
.
session
=
""
;
this
.
username
=
""
;
}
public
HTTPRequest
getCasUrl
()
throws
IOException
{
return
construct
(
"POSS3"
,
"getCasUrl"
);
}
public
HTTPRequest
loginCas
(
final
String
ticket
,
final
String
service
)
throws
IOException
{
return
construct
(
"POSS3"
,
"loginCas2"
,
new
HashMap
<
String
,
String
>()
{{
put
(
"ticket"
,
ticket
);
put
(
"service"
,
service
);
}});
}
public
HTTPRequest
construct
(
final
String
method
,
final
String
service
)
throws
IOException
{
return
construct
(
method
,
service
,
new
HashMap
<
String
,
String
>());
}
public
HTTPRequest
construct
(
final
String
method
,
final
String
service
,
final
Map
<
String
,
String
>
args
)
throws
IOException
{
HTTPRequest
request
=
new
HTTPRequest
(
url
);
request
.
setArgs
(
defaultArgs
);
for
(
String
arg
:
args
.
keySet
())
request
.
setArg
(
arg
,
args
.
get
(
arg
));
request
.
post
();
return
request
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment