Created
September 23, 2016 09:08
-
-
Save YMA-MDL/624d5976877b69f5295a295aedbf84b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.net.*; | |
| import java.io.*; | |
| import java.security.*; | |
| import java.math.*; | |
| class filecheckin | |
| { | |
| public static String calcMD5(String s) { | |
| MessageDigest m = null; | |
| try { | |
| m=MessageDigest.getInstance("MD5"); | |
| m.update(s.getBytes(),0,s.length()); | |
| } | |
| catch (NoSuchAlgorithmException e) { | |
| System.err.println("Invalid algorithm"); | |
| System.exit(-1); | |
| } | |
| return (new BigInteger(1,m.digest()).toString(16)); | |
| } | |
| public static void main(String args[]) | |
| { | |
| try { | |
| URL u = new URL("http://localhost/innovator91/vault/VaultServer.aspx"); | |
| URLConnection uc = u.openConnection(); | |
| HttpURLConnection connection = (HttpURLConnection) uc; | |
| String boundary = "-------------------------BRdnIy5hBONlyI"; | |
| String docPath = "C:\\testdoc.txt"; | |
| connection.setDoOutput(true); | |
| connection.setRequestMethod("POST"); | |
| connection.setRequestProperty("Content-Type", "multipart/form-data; boundary="+boundary); | |
| OutputStream os = connection.getOutputStream(); | |
| File file = new File(docPath); | |
| FileInputStream is = new FileInputStream(file); | |
| String content = "--"+boundary +"\r\nContent-Disposition: form-data; name=\"SOAPACTION\"; \r\nContent-Type: text/plain\r\n\r\nApplyItem\r\n"; | |
| os.write(content.getBytes()); | |
| content = "--"+boundary +"\r\nContent-Disposition: form-data; name=\"AUTHUSER\"; \r\nContent-Type: text/plain\r\n\r\nadmin\r\n"; | |
| os.write(content.getBytes()); | |
| content = "--"+boundary +"\r\nContent-Disposition: form-data; name=\"AUTHPASSWORD\"; \r\nContent-Type: text/plain\r\n\r\n"+calcMD5("innovator")+"\r\n"; | |
| os.write(content.getBytes()); | |
| content = "--"+boundary +"\r\nContent-Disposition: form-data; name=\"DATABASE\"; \r\nContent-Type: text/plain\r\n\r\nsolutions91\r\n"; | |
| os.write(content.getBytes()); | |
| content = "--"+boundary +"\r\nContent-Disposition: form-data; name=\"XMLDATA\"; \r\nContent-Type: text/plain\r\n\r\n"; | |
| content += "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>"; | |
| content += " <SOAP-ENV:Body>"; | |
| content += " <ApplyItem>"; | |
| content += " <Item type='Document' id='76126C1815DA441B80E11492ACF437A4' action='add'>"; | |
| content += " <item_number>X-1001</item_number>"; | |
| content += " <name>Test</name>"; | |
| content += " <locked_by_id keyed_name='admin'>30B991F927274FA3829655F50C99472E</locked_by_id>"; | |
| content += " <Relationships>"; | |
| content += " <Item type='Document File' id='A311B7E4A1414BF9971F01867E919A43' action='add'>"; | |
| content += " <related_id>"; | |
| content += " <Item type='File' id='534007B45DBA48249AC49C8F90A26DF4' action='add'>"; | |
| content += " <filename>testdoc.txt</filename>"; | |
| content += " <checkedout_path>C:</checkedout_path>"; | |
| content += " <new_version>1</new_version>"; | |
| content += " <file_size>11</file_size>"; | |
| content += " <checksum>FB53A94DDC6855BA4DCB9E9BD10E0AC0</checksum>"; | |
| content += " <Relationships>"; | |
| content += " <Item type='Located' id='78FF03607AAA4926B80E5CE628729AF5' action='add'>"; | |
| content += " <source_id keyed_name='testdoc.txt'>534007B45DBA48249AC49C8F90A26DF4</source_id>"; | |
| content += " <related_id keyed_name='Default'>67BBB9204FE84A8981ED8313049BA06C</related_id>"; | |
| content += " </Item>"; | |
| content += " </Relationships>"; | |
| content += " </Item>"; | |
| content += " </related_id>"; | |
| content += " <source_id keyed_name='X-1001'>76126C1815DA441B80E11492ACF437A4</source_id>"; | |
| content += " </Item>" ; | |
| content += " </Relationships>"; | |
| content += " </Item>"; | |
| content += " </ApplyItem>"; | |
| content += " </SOAP-ENV:Body>"; | |
| content += "</SOAP-ENV:Envelope>\r\n\r\n"; | |
| os.write(content.getBytes()); | |
| content = "--"+boundary +"\r\nContent-Disposition: form-data; name=\"534007B45DBA48249AC49C8F90A26DF4\"; filename=\"testdoc.txt\";\r\nContent-Type: text/plain\r\n\r\n"; | |
| os.write(content.getBytes()); | |
| byte[] buffer = new byte[4096]; | |
| int bytes_read; | |
| while((bytes_read = is.read(buffer)) != -1) { | |
| os.write(buffer, 0, bytes_read); | |
| content = "\r\n--"+boundary+"--"; | |
| os.write(content.getBytes()); | |
| } | |
| os.flush(); | |
| os.close(); | |
| InputStream in = connection.getInputStream(); | |
| int c; | |
| while ((c = in.read()) != -1) System.out.write(c); | |
| in.close(); | |
| } | |
| catch (IOException e) { | |
| System.err.println(e); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment