- add user check before upload to AssetPacks upload
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7075 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
0925a6ca51
commit
f13e778cd6
@ -20,8 +20,10 @@ import org.openide.filesystems.FileUtil;
|
|||||||
public class OnlinePacksConnector {
|
public class OnlinePacksConnector {
|
||||||
|
|
||||||
public static void upload(String exsistingFileName, String user, String pass) {
|
public static void upload(String exsistingFileName, String user, String pass) {
|
||||||
|
if (test("http://jmonkeyengine.org/assetpacks/test.php", user, pass)) {
|
||||||
upload("http://jmonkeyengine.org/assetpacks/upload.php", exsistingFileName, user, pass);
|
upload("http://jmonkeyengine.org/assetpacks/upload.php", exsistingFileName, user, pass);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void upload(String urlString, String exsistingFileName, String user, String pass) {
|
public static void upload(String urlString, String exsistingFileName, String user, String pass) {
|
||||||
try {
|
try {
|
||||||
@ -72,4 +74,47 @@ public class OnlinePacksConnector {
|
|||||||
} finally {
|
} finally {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean test(String urlString, String user, String pass) {
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
String boundary = MultiPartFormOutputStream.createBoundary();
|
||||||
|
URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);
|
||||||
|
urlConn.setRequestProperty("Accept", "*/*");
|
||||||
|
urlConn.setRequestProperty("Content-Type", MultiPartFormOutputStream.getContentType(boundary));
|
||||||
|
urlConn.setRequestProperty("Connection", "Keep-Alive");
|
||||||
|
urlConn.setRequestProperty("Cache-Control", "no-cache");
|
||||||
|
MultiPartFormOutputStream out = new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
|
||||||
|
// write a text field element
|
||||||
|
out.writeField("user", user);
|
||||||
|
out.writeField("pass", pass);
|
||||||
|
out.close();
|
||||||
|
// read response from server
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
|
||||||
|
String line = "";
|
||||||
|
boolean success = false;
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
if (line.startsWith("Success")) {
|
||||||
|
success = true;
|
||||||
|
} else {
|
||||||
|
Confirmation msg = new NotifyDescriptor.Confirmation(
|
||||||
|
"Error connecting to jmonkeyengine.org,\nwrong user name or password!\nPlease configure in application settings.",
|
||||||
|
NotifyDescriptor.OK_CANCEL_OPTION,
|
||||||
|
NotifyDescriptor.ERROR_MESSAGE);
|
||||||
|
DialogDisplayer.getDefault().notifyLater(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
return success;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Confirmation msg = new NotifyDescriptor.Confirmation(
|
||||||
|
"Error connecting to jmonkeyengine.org!\n" + ex.getMessage(),
|
||||||
|
NotifyDescriptor.OK_CANCEL_OPTION,
|
||||||
|
NotifyDescriptor.ERROR_MESSAGE);
|
||||||
|
DialogDisplayer.getDefault().notifyLater(msg);
|
||||||
|
Logger.getLogger(OnlinePacksConnector.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user