(String obj, String cmdline, String method)
| 147 | } |
| 148 | |
| 149 | private static String send(String obj, String cmdline, String method) { |
| 150 | BufferedReader bf = null; |
| 151 | InputStream is = null; |
| 152 | OutputStream os = null; |
| 153 | HttpURLConnection connection = null; |
| 154 | try { |
| 155 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 156 | ObjectOutput out = new ObjectOutputStream(bos); |
| 157 | |
| 158 | out.writeObject("|" + cmdline + "|" + System.lineSeparator() + obj); |
| 159 | if (OSSObjectURL.getProtocol().toLowerCase().startsWith("https")) { |
| 160 | HttpsURLConnection httpsURLConnection = (HttpsURLConnection) OSSObjectURL.openConnection(); |
| 161 | httpsURLConnection.setHostnameVerifier(new HostnameVerifier() { |
| 162 | @Override |
| 163 | public boolean verify(String hostname, SSLSession session) { |
| 164 | return true; |
| 165 | } |
| 166 | }); |
| 167 | connection = httpsURLConnection; |
| 168 | } else { |
| 169 | connection = (HttpURLConnection) OSSObjectURL.openConnection(); |
| 170 | } |
| 171 | connection.setRequestMethod(method); |
| 172 | connection.setDoOutput(true); |
| 173 | connection.setRequestProperty("Accept", "*/*"); |
| 174 | connection.setRequestProperty("Content-Type", "application/octet-stream"); |
| 175 | connection.setRequestProperty("Content-Length", obj.toString().getBytes().length + ""); |
| 176 | SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); |
| 177 | sdf.setTimeZone(TimeZone.getTimeZone("GMT")); |
| 178 | connection.setRequestProperty("Date", sdf.format(new Date())); |
| 179 | connection.setRequestProperty("Expect", "100-continue"); |
| 180 | String cmdSign = ""; |
| 181 | String toSign; |
| 182 | if (("PUT".equals(method)) && ("OSS".equals(type))) { |
| 183 | connection.setRequestProperty("x-oss-meta-info", meta); |
| 184 | connection.setRequestProperty("x-oss-meta-cmd", cmdline); |
| 185 | |
| 186 | cmdSign = "x-oss-meta-cmd:" + cmdline.trim() + "\n"; |
| 187 | |
| 188 | toSign = "" + method + "\n\napplication/octet-stream\n" + sdf.format(new Date()) + "\n" |
| 189 | + cmdSign + "x-oss-meta-info:" + meta.trim() + "\n/" + bucketname + path + UID; |
| 190 | |
| 191 | byte[] hm = hamcsha1(toSign.getBytes(), accessKeySecret.getBytes()); |
| 192 | if (!accessKeyId.isEmpty() && !accessKeySecret.isEmpty()) { |
| 193 | connection.setRequestProperty("Authorization", "OSS " + accessKeyId + ":" + |
| 194 | enCode64(new String(hm))); |
| 195 | } |
| 196 | |
| 197 | os = connection.getOutputStream(); |
| 198 | os.write(bos.toByteArray()); |
| 199 | } else if (("PUT".equals(method)) && ("COS".equals(type))) { |
| 200 | connection.setRequestProperty("x-cos-meta-info", meta); |
| 201 | connection.setRequestProperty("x-cos-meta-cmd", cmdline); |
| 202 | os = connection.getOutputStream(); |
| 203 | os.write(bos.toByteArray()); |
| 204 | } else if (("PUT".equals(method)) && ("S3".equals(type))) { |
| 205 | connection.setRequestProperty("x-amz-meta-info", meta); |
| 206 | connection.setRequestProperty("x-amz-meta-cmd", cmdline); |
no test coverage detected