List of usage examples for java.lang String toString
public String toString()
From source file:com.mnt.base.web.DigestAuthenticator.java
static public String md5(String sb, char[] passwd) { byte[] unencodedPassword = sb.toString().getBytes(); MessageDigest md = null;//from w w w .jav a 2s. c o m try { md = MessageDigest.getInstance("MD5"); } catch (Exception e) { return sb.toString(); } md.reset(); md.update(unencodedPassword); for (int i = 0; i < passwd.length; i++) { md.update((byte) passwd[i]); } byte[] digest = md.digest(); //StringBuffer buf = new StringBuffer(); /*char j; for (int i = 0; i < encodedPassword.length; i++) { j = (char)((encodedPassword[i] >> 4) & 0xf); if(j <= 9) { buf.append((char)(j + '0')); } else { buf.append((char)(j + 'a' - 10)); } j = (char)((encodedPassword[i]) & 0xf); if(j <= 9) { buf.append((char)(j + '0')); } else { buf.append((char)(j + 'a' - 10)); } }*/ StringBuffer res = new StringBuffer(digest.length * 2); for (int i = 0; i < digest.length; i++) { int hashchar = ((digest[i] >>> 4) & 0xf); res.append(charArray[hashchar]); hashchar = (digest[i] & 0xf); res.append(charArray[hashchar]); } return res.toString(); }
From source file:org.n52.sor.client.Client.java
/** * @param request//from ww w . j a v a 2 s. com * @return * @throws UnsupportedEncodingException * @throws IOException * @throws HttpException */ private static XmlObject doSend(String request, String requestMethod) throws UnsupportedEncodingException, IOException { log.debug("Sending request (first 100 characters): {}", request.substring(0, Math.min(request.length(), 100))); PropertiesManager pm = PropertiesManager.getInstance(); // create and set up HttpClient try (CloseableHttpClient client = HttpClientBuilder.create().build();) { HttpRequestBase method = null; if (requestMethod.equals(GET_METHOD)) { String sorURL = pm.getServiceEndpointGet(); log.debug("Client connecting via GET to {}", sorURL); HttpGet get = new HttpGet(request); method = get; } else if (requestMethod.equals(POST_METHOD)) { String sorURL = pm.getServiceEndpointPost(); log.debug("Client connecting via POST to {}", sorURL); HttpPost postMethod = new HttpPost(sorURL.toString()); postMethod.setEntity( new StringEntity(request, PropertiesManager.getInstance().getClientRequestContentType())); method = postMethod; } else throw new IllegalArgumentException("requestMethod not supported!"); HttpResponse httpResponse = client.execute(method); XmlObject response = XmlObject.Factory.parse(httpResponse.getEntity().getContent()); return response; } catch (XmlException e) { log.error("Error parsing response.", e); } return null; }
From source file:fileoperations.FileOperations.java
public static boolean writeCollectionToFile(Collection<String> objToWrite, String delimiter, String fileToWrite) {//w w w . ja v a 2s . c om loggerObj.log(Level.INFO, "inside writeObjectToFile method"); BufferedWriter bw = null; loggerObj.log(Level.INFO, "File to write the object is:" + fileToWrite); File file = new File(fileToWrite); try { if (file.exists()) { file.delete(); } if (!file.exists()) { file.createNewFile(); loggerObj.log(Level.INFO, "File did not exist before: so created new one with the name: " + fileToWrite); } FileWriter fw = new FileWriter(file, true); bw = new BufferedWriter(fw); for (String i : objToWrite) { bw.write(i.toString() + ","); } } catch (IOException ex) { loggerObj.log(Level.SEVERE, "Error in writing to the file:" + fileToWrite + "\n Exception is " + ex.toString()); return false; } catch (Exception ex) { loggerObj.log(Level.SEVERE, "Error in writing to the file:" + fileToWrite + "\n Exception is " + ex.toString()); return false; } finally { try { if (bw != null) { bw.close(); } } catch (IOException ex) { loggerObj.log(Level.SEVERE, "Error in closing the file:" + fileToWrite + " after reading"); return false; } } loggerObj.log(Level.INFO, "Successfully written the object to: " + fileToWrite); return true; }
From source file:io.undertow.server.security.DigestAuthenticationAuthTestCase.java
static void _testBadUsername() throws Exception { TestHttpClient client = new TestHttpClient(); HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL()); HttpResponse result = client.execute(get); assertEquals(StatusCodes.UNAUTHORIZED, result.getStatusLine().getStatusCode()); Header[] values = result.getHeaders(WWW_AUTHENTICATE.toString()); String value = getAuthHeader(DIGEST, values); Map<DigestWWWAuthenticateToken, String> parsedHeader = DigestWWWAuthenticateToken .parseHeader(value.substring(7)); assertEquals(REALM_NAME, parsedHeader.get(DigestWWWAuthenticateToken.REALM)); assertEquals(DigestAlgorithm.MD5.getToken(), parsedHeader.get(DigestWWWAuthenticateToken.ALGORITHM)); assertEquals(DigestQop.AUTH.getToken(), parsedHeader.get(DigestWWWAuthenticateToken.MESSAGE_QOP)); String clientNonce = createNonce(); int nonceCount = 1; String nonce = parsedHeader.get(DigestWWWAuthenticateToken.NONCE); String opaque = parsedHeader.get(DigestWWWAuthenticateToken.OPAQUE); assertNotNull(opaque);//from ww w. ja v a 2 s .c o m client = new TestHttpClient(); get = new HttpGet(DefaultServer.getDefaultServerURL()); int thisNonceCount = nonceCount++; String authorization = createAuthorizationLine("noUser", "passwordOne", "GET", "/", nonce, thisNonceCount, clientNonce, opaque); get.addHeader(AUTHORIZATION.toString(), authorization); result = client.execute(get); assertEquals(StatusCodes.UNAUTHORIZED, result.getStatusLine().getStatusCode()); assertSingleNotificationType(EventType.FAILED_AUTHENTICATION); }
From source file:io.undertow.server.security.DigestAuthenticationAuthTestCase.java
static void _testBadPassword() throws Exception { TestHttpClient client = new TestHttpClient(); HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL()); HttpResponse result = client.execute(get); assertEquals(StatusCodes.UNAUTHORIZED, result.getStatusLine().getStatusCode()); Header[] values = result.getHeaders(WWW_AUTHENTICATE.toString()); String value = getAuthHeader(DIGEST, values); Map<DigestWWWAuthenticateToken, String> parsedHeader = DigestWWWAuthenticateToken .parseHeader(value.substring(7)); assertEquals(REALM_NAME, parsedHeader.get(DigestWWWAuthenticateToken.REALM)); assertEquals(DigestAlgorithm.MD5.getToken(), parsedHeader.get(DigestWWWAuthenticateToken.ALGORITHM)); assertEquals(DigestQop.AUTH.getToken(), parsedHeader.get(DigestWWWAuthenticateToken.MESSAGE_QOP)); String clientNonce = createNonce(); int nonceCount = 1; String nonce = parsedHeader.get(DigestWWWAuthenticateToken.NONCE); String opaque = parsedHeader.get(DigestWWWAuthenticateToken.OPAQUE); assertNotNull(opaque);/*from w ww . ja va2 s . co m*/ client = new TestHttpClient(); get = new HttpGet(DefaultServer.getDefaultServerURL()); int thisNonceCount = nonceCount++; String authorization = createAuthorizationLine("userOne", "badPassword", "GET", "/", nonce, thisNonceCount, clientNonce, opaque); get.addHeader(AUTHORIZATION.toString(), authorization); result = client.execute(get); assertEquals(StatusCodes.UNAUTHORIZED, result.getStatusLine().getStatusCode()); assertSingleNotificationType(EventType.FAILED_AUTHENTICATION); }
From source file:io.undertow.server.security.DigestAuthenticationAuthTestCase.java
static void _testBadNonce() throws Exception { TestHttpClient client = new TestHttpClient(); HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL()); HttpResponse result = client.execute(get); assertEquals(StatusCodes.UNAUTHORIZED, result.getStatusLine().getStatusCode()); Header[] values = result.getHeaders(WWW_AUTHENTICATE.toString()); String value = getAuthHeader(DIGEST, values); Map<DigestWWWAuthenticateToken, String> parsedHeader = DigestWWWAuthenticateToken .parseHeader(value.substring(7)); assertEquals(REALM_NAME, parsedHeader.get(DigestWWWAuthenticateToken.REALM)); assertEquals(DigestAlgorithm.MD5.getToken(), parsedHeader.get(DigestWWWAuthenticateToken.ALGORITHM)); assertEquals(DigestQop.AUTH.getToken(), parsedHeader.get(DigestWWWAuthenticateToken.MESSAGE_QOP)); String clientNonce = createNonce(); int nonceCount = 1; String nonce = "AU1aCIiy48ENMTM1MTE3OTUxMDU2OLrHnBlV2GBzzguCWOPET+0="; String opaque = parsedHeader.get(DigestWWWAuthenticateToken.OPAQUE); assertNotNull(opaque);//from w w w .j a v a 2 s . c o m client = new TestHttpClient(); get = new HttpGet(DefaultServer.getDefaultServerURL()); int thisNonceCount = nonceCount++; String authorization = createAuthorizationLine("userOne", "badPassword", "GET", "/", nonce, thisNonceCount, clientNonce, opaque); get.addHeader(AUTHORIZATION.toString(), authorization); result = client.execute(get); assertEquals(StatusCodes.UNAUTHORIZED, result.getStatusLine().getStatusCode()); assertSingleNotificationType(EventType.FAILED_AUTHENTICATION); }
From source file:com.hx.sync.utils.MemberUtils.java
/** * erp?/*www . jav a 2 s.com*/ * @param url * @param adapterNo * @param data * @return */ public static JSONObject accessERPInterface(String url, String adapterNo, String data) { Map<String, String> params = new HashMap<String, String>(); SecretUtil secretUtil = new SecretUtil(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); String identityCode = secretUtil.md5Ticket(data.toString(), millis); params.put("identityCode", identityCode); params.put("adapterNo", adapterNo); params.put("data", data); params.put("systemId", Constants.SYSTEM_ID_GROUP_ERP); params.put("time", millis); JSONObject resultJson = HttpClientUtil.postForm(url, params, true); return resultJson; }
From source file:models.utils.FileIoUtils.java
/** * 20130927 Fixed Memory Leak. Dont use line by line, just use apache * commons io!! so simple and easy!/*from ww w. j a va 2s . com*/ * * @param filePath * @return */ public static String readFileToString(String filePath) { String fileContentString = null; try { VirtualFile vf = VirtualFile.fromRelativePath(filePath); File realFile = vf.getRealFile(); fileContentString = FileUtils.readFileToString(realFile); models.utils.LogUtils.printLogNormal("Completed read file with file size: " + fileContentString.toString().length() / VarUtils.CONVERSION_1024 + " KB. Path: " + filePath + " at " + DateUtils.getNowDateTimeStr()); } catch (java.io.FileNotFoundException e) { models.utils.LogUtils.printLogError("File Not Found exception." + e.getLocalizedMessage()); fileContentString = "File Not Found exception. This file may have been removed. " + filePath; } catch (Throwable e) { models.utils.LogUtils.printLogError("Error in readConfigFile." + e.getLocalizedMessage()); e.printStackTrace(); fileContentString = "File Not Found exception. This file may have been removed. " + filePath; } return fileContentString.toString(); }
From source file:com.datasalt.pangool.solr.SolrRecordWriter.java
static String relativePathForZipEntry(final String rawPath, final String baseName, final String root) { String relativePath = rawPath.replaceFirst(Pattern.quote(root.toString()), ""); LOG.info(//from ww w. j a va2 s . c om String.format("RawPath %s, baseName %s, root %s, first %s", rawPath, baseName, root, relativePath)); if (relativePath.startsWith(Path.SEPARATOR)) { relativePath = relativePath.substring(1); } LOG.info(String.format("RawPath %s, baseName %s, root %s, post leading slash %s", rawPath, baseName, root, relativePath)); if (relativePath.isEmpty()) { LOG.warn(String.format("No data after root (%s) removal from raw path %s", root, rawPath)); return baseName; } // Construct the path that will be written to the zip file, including // removing any leading '/' characters String inZipPath = baseName + Path.SEPARATOR_CHAR + relativePath; LOG.info(String.format("RawPath %s, baseName %s, root %s, inZip 1 %s", rawPath, baseName, root, inZipPath)); if (inZipPath.startsWith(Path.SEPARATOR)) { inZipPath = inZipPath.substring(1); } LOG.info(String.format("RawPath %s, baseName %s, root %s, inZip 2 %s", rawPath, baseName, root, inZipPath)); return inZipPath; }
From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java
public static void antTarget(AemDemo aemDemo, String targetName) { String selectedDemoMachine = (String) aemDemo.getListDemoMachines().getSelectedValue(); if (Arrays.asList(AemDemoConstants.INSTANCE_ACTIONS).contains(targetName) && (selectedDemoMachine == null || selectedDemoMachine.toString().length() == 0)) { JOptionPane.showMessageDialog(null, "Please select a demo environment before running this command"); } else {/*w ww . j a va 2 s . com*/ // New ANT project AemDemoProject p = new AemDemoProject(aemDemo); if (selectedDemoMachine != null && selectedDemoMachine.length() > 0) p.setUserProperty("demo.build", selectedDemoMachine.toString()); // Make sure host name is there try { p.setUserProperty("demo.hostname", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException ex) { logger.error(ex.getMessage()); } p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, aemDemo.getBuildFile()); // Running the target name as a new Thread System.out.println("Running ANT target: " + targetName); Thread t = new Thread(new AemDemoRunnable(aemDemo, p, targetName)); t.start(); } }