public final synchronized T getInfo(URI uri, RenderingContext context) { T result = cache.get(uri); if (result == null) { try { result = requestInfo(uri, context); } catch (Exception e) { loader .logger() .info( "Error while getting capabilities for " + uri + ". The print module will assume it's a standard WMS."); String stackTrace = ""; for (StackTraceElement el : e.getStackTrace()) { stackTrace += el.toString() + "\n"; } loader.logger().info(stackTrace); result = loader.createNewErrorResult(); } if (loader.logger().isDebugEnabled()) { loader.logger().debug("GetCapabilities " + uri + ": " + result); } cache.put(uri, result); } return result; }
/* * This method is use to get the result of research of tag */ public String getSearcResult(String url) { String searchResult = null; URL myUrl; try { myUrl = new URL(url); URLConnection connect = myUrl.openConnection(); searchResult = getResponseOfInstagram(connect); } catch (Exception exc) { System.out.println(exc.getStackTrace()); } return searchResult; }
// [JACKSON-888] public void testStackTraceElement() throws Exception { StackTraceElement elem = null; try { throw new IllegalStateException(); } catch (Exception e) { elem = e.getStackTrace()[0]; } String json = MAPPER.writeValueAsString(elem); StackTraceElement back = MAPPER.readValue(json, StackTraceElement.class); assertEquals("testStackTraceElement", back.getMethodName()); assertEquals(elem.getLineNumber(), back.getLineNumber()); assertEquals(elem.getClassName(), back.getClassName()); assertEquals(elem.isNativeMethod(), back.isNativeMethod()); assertTrue(back.getClassName().endsWith("TestJdkTypes")); assertFalse(back.isNativeMethod()); }
/* * This method communicate with the instagram server and return the * response in text format. * */ public String getResponseOfInstagram(URLConnection connect) { String response = null; try { BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream())); String inputLine; response = ""; while ((inputLine = reader.readLine()) != null) { response += inputLine + "\n"; } reader.close(); } catch (Exception excp) { System.out.println(excp.getStackTrace()); } return response; }
public static void main(String[] args) throws UnknownHostException, IOException { // TODO Auto-generated method stub System.out.println("Hello World"); try { Socket socket = new Socket("localhost", 9876); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); DataOutputStream writer = new DataOutputStream(socket.getOutputStream()); // start reading from the socket as soon as a connection is accepted RunnableSocketReader sock_reader = new RunnableSocketReader(socket, "Server"); sock_reader.start(); while (true) { String str = reader.readLine(); writer.writeBytes(str + "\r\n"); if (str.equalsIgnoreCase("quit")) break; } socket.close(); } catch (Exception e) { e.getStackTrace(); } }
/* * This method is use to receive client information according to his code. * The request is a post request */ public String getClientInformations(String url, List<String> parameters, List<String> value) { // If the both list hasn't the same size, then the request will not // be possible. In that case, we return null for the response if (parameters.size() != value.size()) { return null; } String response = null; int i = 0; int size = value.size(); String reqParameters = ""; OutputStreamWriter outWriter = null; URL myUrl; try { // We set the parameters of the request. We scan both of the list // and we set the parameters of request according to the index of // both lists. while (i < size) { if (i == 0) { reqParameters = URLEncoder.encode(parameters.get(i), "UTF-8") + "=" + URLEncoder.encode(value.get(i), "UTF-8"); } else { reqParameters += "&" + URLEncoder.encode(parameters.get(i), "UTF-8") + "=" + URLEncoder.encode(value.get(i), "UTF-8"); } i += 1; } // We create the connection to instagram myUrl = new URL(url); // We open the connection URLConnection connect = myUrl.openConnection(); // We use connect for output connect.setDoOutput(true); // We send the request; outWriter = new OutputStreamWriter(connect.getOutputStream()); // We add parameters to the request outWriter.write(reqParameters); // We flush the stream outWriter.flush(); // We get response for instagram response = getResponseOfInstagram(connect); // We close the stream outWriter.close(); } catch (Exception exc) { System.out.println(exc.getStackTrace()); } return response; }