/** * Creates a random cnonce value based on the current time. * * @return The cnonce value as String. * @throws UnsupportedDigestAlgorithmException if MD5 algorithm is not supported. */ public static String createCnonce() { String cnonce; MessageDigest md5Helper = createMessageDigest("MD5"); cnonce = Long.toString(System.currentTimeMillis()); cnonce = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(cnonce))); return cnonce; } }
a2 = method + ':' + uri; String md5a2 = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(a2))); encode(md5Helper.digest(EncodingUtils.getAsciiBytes(serverDigestValue)));
protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
/** * Write the content disposition header to the specified output stream * * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendDispositionHeader(OutputStream out) throws IOException { if (DEBUG) Log.d(TAG, "enter sendDispositionHeader(OutputStream out)"); out.write(CONTENT_DISPOSITION_BYTES); out.write(QUOTE_BYTES); out.write(EncodingUtils.getAsciiBytes(getName())); out.write(QUOTE_BYTES); }
/** * Write the content transfer encoding header to the specified * output stream * * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendTransferEncodingHeader(OutputStream out) throws IOException { if (DEBUG) Log.d(TAG, "enter sendTransferEncodingHeader(OutputStream out)"); String transferEncoding = getTransferEncoding(); if (transferEncoding != null) { out.write(CRLF_BYTES); out.write(CONTENT_TRANSFER_ENCODING_BYTES); out.write(EncodingUtils.getAsciiBytes(transferEncoding)); } }
/** * Write the content type header to the specified output stream * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendContentTypeHeader(OutputStream out) throws IOException { if (DEBUG) Log.d(TAG, "enter sendContentTypeHeader(OutputStream out)"); String contentType = getContentType(); if (contentType != null) { out.write(CRLF_BYTES); out.write(CONTENT_TYPE_BYTES); out.write(EncodingUtils.getAsciiBytes(contentType)); String charSet = getCharSet(); if (charSet != null) { out.write(CHARSET_BYTES); out.write(EncodingUtils.getAsciiBytes(charSet)); } } }
/** * Creates a random cnonce value based on the current time. * * @return The cnonce value as String. * @throws UnsupportedDigestAlgorithmException if MD5 algorithm is not supported. */ public static String createCnonce() { String cnonce; MessageDigest md5Helper = createMessageDigest("MD5"); cnonce = Long.toString(System.currentTimeMillis()); cnonce = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(cnonce))); return cnonce; } }
/** * Creates a random cnonce value based on the current time. * * @return The cnonce value as String. * @throws UnsupportedDigestAlgorithmException if MD5 algorithm is not supported. */ public static String createCnonce() { String cnonce; MessageDigest md5Helper = createMessageDigest("MD5"); cnonce = Long.toString(System.currentTimeMillis()); cnonce = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(cnonce))); return cnonce; } }
/** * Creates a random cnonce value based on the current time. * * @return The cnonce value as String. * @throws UnsupportedDigestAlgorithmException if MD5 algorithm is not supported. */ public static String createCnonce() { String cnonce; MessageDigest md5Helper = createMessageDigest("MD5"); cnonce = Long.toString(System.currentTimeMillis()); cnonce = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(cnonce))); return cnonce; } }
/** * Creates a random cnonce value based on the current time. * * @return The cnonce value as String. * @throws UnsupportedDigestAlgorithmException if MD5 algorithm is not supported. */ public static String createCnonce() { String cnonce; MessageDigest md5Helper = createMessageDigest("MD5"); cnonce = Long.toString(System.currentTimeMillis()); cnonce = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(cnonce))); return cnonce; } }
/** * Write the disposition header to the output stream * @param out The output stream * @throws IOException If an IO problem occurs * @see Part#sendDispositionHeader(OutputStream) */ @Override protected void sendDispositionHeader(OutputStream out) throws IOException { if (DEBUG) Log.d(TAG, "enter sendDispositionHeader(OutputStream out)"); super.sendDispositionHeader(out); String filename = this.source.getFileName(); if (filename != null) { out.write(FILE_NAME_BYTES); out.write(QUOTE_BYTES); out.write(EncodingUtils.getAsciiBytes(filename)); out.write(QUOTE_BYTES); } }
/** * Returns the MIME boundary string that is used to demarcate boundaries of * this part. The first call to this method will implicitly create a new * boundary string. To create a boundary string first the * HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise * a random one is generated. * * @return The boundary string of this entity in ASCII encoding. */ protected byte[] getMultipartBoundary() { if (multipartBoundary == null) { String temp = null; if (params != null) { temp = (String) params.getParameter(MULTIPART_BOUNDARY); } if (temp != null) { multipartBoundary = EncodingUtils.getAsciiBytes(temp); } else { multipartBoundary = generateMultipartBoundary(); } } return multipartBoundary; }
protected void handleException(final HttpException ex, final HttpResponse response) { int code = HttpStatus.SC_INTERNAL_SERVER_ERROR; if (ex instanceof MethodNotSupportedException) { code = HttpStatus.SC_NOT_IMPLEMENTED; } else if (ex instanceof UnsupportedHttpVersionException) { code = HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED; } else if (ex instanceof ProtocolException) { code = HttpStatus.SC_BAD_REQUEST; } response.setStatusCode(code); byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset. * * @param escaped a string * @return the unescaped string * * @throws URIException if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(String escaped) throws UriException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(escaped)); return EncodingUtils.getString(rawdata, Uri.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new UriException(e.getMessage()); } }
/** * Handles the given exception and generates an HTTP response to be sent * back to the client to inform about the exceptional condition encountered * in the course of the request processing. * * @param ex the exception. * @param response the HTTP response. */ protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } String message = ex.getMessage(); if (message == null) { message = ex.toString(); } final byte[] msg = EncodingUtils.getAsciiBytes(message); final ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
/** * Handles the given exception and generates an HTTP response to be sent * back to the client to inform about the exceptional condition encountered * in the course of the request processing. * * @param ex the exception. * @param response the HTTP response. */ protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } String message = ex.getMessage(); if (message == null) { message = ex.toString(); } final byte[] msg = EncodingUtils.getAsciiBytes(message); final ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }