Skip to content

Commit ea6e5ff

Browse files
author
Paul Gilmore
committed
Merge pull request #8 from PlayFab/Java-MoreTests
Java CloudScript test
2 parents 6b691ad + abeb85f commit ea6e5ff

32 files changed

+26703
-26726
lines changed

PlayFabClientSDK/src/playfab/PlayFabClientAPI.java

+3,005-3,005
Large diffs are not rendered by default.

PlayFabClientSDK/src/playfab/PlayFabClientModels.java

+2,500-2,500
Large diffs are not rendered by default.

PlayFabClientSDK/src/playfab/PlayFabErrors.java

+211-212
Large diffs are not rendered by default.

PlayFabClientSDK/src/playfab/PlayFabSettings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class PlayFabSettings {
1111

1212

1313
public static String GetLogicURL() {
14-
return "https://" + LogicServerURL;
14+
return LogicServerURL;
1515
}
1616

1717
public static String GetURL() {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package playfab;
22

33
public class PlayFabUtil {
4-
public static @interface Unordered {
5-
public String value() default "";
6-
}
4+
public static @interface Unordered {
5+
public String value() default "";
6+
}
77
}

PlayFabClientSDK/src/playfab/internal/PlayFabHTTP.java

+74-93
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,34 @@
55
import java.net.*;
66
import java.io.*;
77
import com.google.gson.*;
8-
import playfab.*;
9-
import playfab.PlayFabErrors.*;
8+
9+
import playfab.PlayFabErrors.PlayFabError;
10+
import playfab.PlayFabErrors.PlayFabErrorCode;
11+
import playfab.PlayFabErrors.PlayFabJsonError;
12+
import playfab.PlayFabErrors.PlayFabJsonSuccess;
1013

1114
public class PlayFabHTTP {
12-
13-
private static Gson gson = new GsonBuilder().setDateFormat("YYYY-MM-DD'T'hh:mm:ss.SSS'Z'").create();
14-
15-
public static class PlayFabJsonError {
16-
public int Code;
17-
public String Status;
18-
public String Error;
19-
public int ErrorCode;
20-
public String ErrorMessage;
21-
public Map<String, String[]> ErrorDetails = null;
22-
}
15+
private static Gson gson = new GsonBuilder().setDateFormat("YYYY-MM-DD'T'hh:mm:ss.SSS'Z'").create();
2316

24-
public static class PlayFabJsonSuccess<ResultT>{
25-
public int Code;
26-
public String Status;
27-
public ResultT Data;
28-
}
29-
30-
public static FutureTask<Object> doPost(final String url, final Object request, final String authType, final String authKey) {
31-
return new FutureTask<Object>(new Callable<Object>() {
32-
public Object call() throws Exception {
33-
return doPostPrivate(url, request, authType, authKey);
34-
}
35-
});
36-
}
37-
17+
public static FutureTask<Object> doPost(final String url, final Object request, final String authType, final String authKey) {
18+
return new FutureTask<Object>(new Callable<Object>() {
19+
public Object call() throws Exception {
20+
return doPostPrivate(url, request, authType, authKey);
21+
}
22+
});
23+
}
24+
3825
private static Object doPostPrivate(String url, Object request, String authType, String authKey) throws Exception {
3926
String bodyString = null;
40-
27+
4128
if(request == null) {
42-
bodyString = "{}";
29+
bodyString = "{}";
4330
}
4431
else if (request instanceof String) {
45-
bodyString = (String)request;
32+
bodyString = (String)request;
4633
}
4734
else {
48-
bodyString = gson.toJson(request);
35+
bodyString = gson.toJson(request);
4936
}
5037

5138
// System.out.println("Sending: " + bodyString);
@@ -54,77 +41,71 @@ else if (request instanceof String) {
5441
con.setRequestMethod("POST");
5542
con.setRequestProperty("Content-Type", "application/json");
5643
if(authType != null) {
57-
con.setRequestProperty(authType, authKey);
44+
con.setRequestProperty(authType, authKey);
5845
}
5946
con.setRequestProperty("X-PlayFabSDK", PlayFabVersion.getVersionString());
6047
con.setDoOutput(true);
6148
con.setDoInput(true);
49+
50+
// Make the API-Call and get the normal response httpCode
51+
int httpCode = 503; // default to SERVICE_UNAVAILABLE
6252
try {
63-
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
64-
writer.write(bodyString);
65-
writer.close();
66-
67-
String responseString = null;
68-
try {
69-
responseString = receive(con.getInputStream());
70-
} catch(IOException e) {
71-
responseString = receive(con.getErrorStream());
72-
}
73-
74-
if(con.getResponseCode() != 200) {
75-
PlayFabError error = new PlayFabError();
76-
if(responseString == null || responseString.isEmpty() || con.getResponseCode() == 404 ) {
77-
error.HttpCode = con.getResponseCode();
78-
return error;
79-
}
80-
PlayFabErrors.PlayFabJsonError errorResult = null;
81-
82-
try {
83-
errorResult = gson.fromJson(responseString, PlayFabErrors.PlayFabJsonError.class);
84-
} catch(Exception e) {
85-
error.HttpCode = con.getResponseCode();
86-
error.Error = PlayFabErrorCode.JsonParseError;
87-
error.ErrorMessage = e.getLocalizedMessage();
88-
return error;
89-
}
90-
91-
error.HttpCode = errorResult.code;
92-
error.HttpStatus = errorResult.status;
93-
error.Error = PlayFabErrorCode.getFromCode(errorResult.errorCode);
94-
error.ErrorMessage = errorResult.errorMessage;
95-
error.ErrorDetails = errorResult.errorDetails;
96-
return error;
97-
98-
}
99-
100-
if(responseString == null || responseString.length() == 0) {
101-
PlayFabError error = new PlayFabError();
102-
error.Error = PlayFabErrorCode.Unknown;
103-
error.ErrorMessage = "Internal server error";
104-
return error;
53+
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
54+
writer.write(bodyString);
55+
writer.close();
56+
httpCode = con.getResponseCode();
57+
} catch(Exception e) {
58+
return GeneratePfError(httpCode, PlayFabErrorCode.ServiceUnavailable, "Failed to post to server: " + url);
59+
}
60+
61+
// Get the response string
62+
String responseString = null;
63+
try {
64+
responseString = receive(con.getInputStream());
65+
} catch(IOException e) {
66+
responseString = receive(con.getErrorStream());
67+
}
68+
69+
// Check for normal error results
70+
if(httpCode != 200 || responseString == null || responseString.isEmpty()) {
71+
if(responseString == null || responseString.isEmpty() || httpCode == 404 )
72+
return GeneratePfError(httpCode, PlayFabErrorCode.ServiceUnavailable, "Empty server response");
73+
74+
PlayFabJsonError errorResult = null;
75+
try {
76+
errorResult = gson.fromJson(responseString, PlayFabJsonError.class);
77+
} catch(Exception e) {
78+
return GeneratePfError(httpCode, PlayFabErrorCode.JsonParseError, "Server response not proper json :" + responseString);
10579
}
80+
81+
httpCode = errorResult.code;
82+
return GeneratePfError(httpCode, PlayFabErrorCode.getFromCode(errorResult.errorCode), errorResult.errorMessage);
83+
}
10684

107-
return responseString;
108-
109-
} catch(Exception e) {
110-
PlayFabError error = new PlayFabError();
111-
error.Error = PlayFabErrorCode.ConnectionError;
112-
error.ErrorMessage = e.getLocalizedMessage();
113-
return error;
85+
return responseString;
86+
}
87+
88+
public static String receive(InputStream in) throws IOException {
89+
StringBuilder recieved = new StringBuilder();
90+
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
91+
92+
String line = null;
93+
while ((line = reader.readLine()) != null) {
94+
recieved.append(line);
95+
recieved.append('\n');
11496
}
97+
98+
return recieved.toString();
11599
}
100+
101+
public static PlayFabError GeneratePfError(int httpCode, PlayFabErrorCode pfErrorCode, String errorMessage) {
102+
PlayFabError output = new PlayFabError();
116103

117-
public static String receive(InputStream in) throws IOException {
118-
StringBuilder recieved = new StringBuilder();
119-
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
120-
121-
String line = null;
122-
while ((line = reader.readLine()) != null) {
123-
recieved.append(line);
124-
recieved.append('\n');
125-
}
126-
127-
return recieved.toString();
104+
output.httpCode = httpCode;
105+
output.httpStatus = "" + httpCode; // TODO: Convert this to the right string-name
106+
output.pfErrorCode = pfErrorCode;
107+
output.errorMessage = errorMessage;
108+
109+
return output;
128110
}
129-
130111
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package playfab.internal;
22

33
public class PlayFabVersion {
4-
public static String ApiRevision = "1.5.20150901";
5-
public static String SdkRevision = "1.0.2";
6-
public static String getVersionString() {
7-
return "JavaSDK-" + SdkRevision + "-" + ApiRevision;
8-
}
4+
public static String ApiRevision = "1.5.20150901";
5+
public static String SdkRevision = "1.0.2";
6+
public static String getVersionString() {
7+
return "JavaSDK-" + SdkRevision + "-" + ApiRevision;
8+
}
99
}
1010

1111

0 commit comments

Comments
 (0)