List of usage examples for java.lang Error getMessage
public String getMessage()
From source file:com.amazonaws.elasticmapreduce.AmazonElasticMapReduceClient.java
/** * Invokes request using parameters from parameters map. * Returns response of the T type passed to this method *//*from w ww. j ava 2 s . c o m*/ private <T> T invoke(Class<T> clazz, Map<String, String> parameters) throws AmazonElasticMapReduceException { String actionName = parameters.get("Action"); T response = null; String responseBodyString = null; PostMethod method = new PostMethod(config.getServiceURL()); int status = -1; log.debug("Invoking" + actionName + " request. Current parameters: " + parameters); try { /* Set content type and encoding */ log.debug("Setting content-type to application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); /* Add required request parameters and set request body */ log.debug("Adding required parameters..."); addRequiredParametersToRequest(method, parameters); log.debug("Done adding additional required parameteres. Parameters now: " + parameters); boolean shouldRetry = true; int retries = 0; do { log.debug("Sending Request to host: " + config.getServiceURL()); try { /* Submit request */ status = httpClient.executeMethod(method); /* Consume response stream */ responseBodyString = getResponsBodyAsString(method.getResponseBodyAsStream()); /* Successful response. Attempting to unmarshal into the <Action>Response type */ if (status == HttpStatus.SC_OK) { shouldRetry = false; log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); if (responseBodyString != null && responseBodyString.trim().endsWith(actionName + "Response>")) { log.debug("Attempting to transform " + actionName + "Response type..."); responseBodyString = ResponseTransformer.transform(responseBodyString); log.debug("Transformed response to: " + responseBodyString); } log.debug("Attempting to unmarshal into the " + actionName + "Response type..."); response = clazz.cast(getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString)))); log.debug("Unmarshalled response into " + actionName + "Response type."); } else { /* Unsucessful response. Attempting to unmarshall into ErrorResponse type */ log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR || status == HttpStatus.SC_SERVICE_UNAVAILABLE) && pauseIfRetryNeeded(++retries)) { shouldRetry = true; } else { log.debug("Attempting to unmarshal into the ErrorResponse type..."); ErrorResponse errorResponse = (ErrorResponse) getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString))); log.debug("Unmarshalled response into the ErrorResponse type."); com.amazonaws.elasticmapreduce.model.Error error = errorResponse.getError().get(0); throw new AmazonElasticMapReduceException(error.getMessage(), status, error.getCode(), error.getType(), errorResponse.getRequestId(), errorResponse.toXML()); } } } catch (JAXBException je) { /* Response cannot be unmarshalled neither as <Action>Response or ErrorResponse types. Checking for other possible errors. */ log.debug("Caught JAXBException", je); log.debug("Response cannot be unmarshalled neither as " + actionName + "Response or ErrorResponse types." + "Checking for other possible errors."); AmazonElasticMapReduceException awse = processErrors(responseBodyString, status); throw awse; } catch (IOException ioe) { log.debug("Caught IOException exception", ioe); throw new AmazonElasticMapReduceException("Internal Error", ioe); } catch (Exception e) { log.debug("Caught Exception", e); throw new AmazonElasticMapReduceException(e); } finally { method.releaseConnection(); } } while (shouldRetry); } catch (AmazonElasticMapReduceException se) { log.debug("Caught AmazonElasticMapReduceException", se); throw se; } catch (Throwable t) { log.debug("Caught Exception", t); throw new AmazonElasticMapReduceException(t); } return response; }
From source file:com.amazonservices.mws.sellers.MarketplaceWebServiceSellersClient.java
/** * Invokes request using parameters from parameters map. Returns response of * the T type passed to this method/*from w w w . ja v a2 s . c o m*/ */ private <T> T invoke(Class<T> clazz, Map<String, String> parameters) throws MarketplaceWebServiceSellersException { String actionName = parameters.get("Action"); T response = null; String responseBodyString = null; HttpPost method = new HttpPost(config.getServiceURL()); int status = -1; log.debug("Invoking" + actionName + " request. Current parameters: " + parameters); try { /* Set content type and encoding */ log.debug("Setting content-type to application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); method.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); /* Set X-Amazon-User-Agent to header */ method.addHeader("X-Amazon-User-Agent", config.getUserAgent()); /* Add required request parameters and set request body */ log.debug("Adding required parameters..."); addRequiredParametersToRequest(method, parameters); log.debug("Done adding additional required parameteres. Parameters now: " + parameters); boolean shouldRetry = true; int retries = 0; do { log.debug("Sending Request to host: " + config.getServiceURL()); try { /* Submit request */ HttpResponse postResponse; postResponse = httpClient.execute(method, httpContext); status = postResponse.getStatusLine().getStatusCode(); /* Consume response stream */ responseBodyString = getResponsBodyAsString(postResponse.getEntity().getContent()); /* * Successful response. Attempting to unmarshal into the * <Action>Response type */ if (status == HttpStatus.SC_OK && responseBodyString != null) { shouldRetry = false; log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); log.debug("Attempting to unmarshal into the " + actionName + "Response type..."); response = clazz.cast(getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString)))); log.debug("Unmarshalled response into " + actionName + "Response type."); } else { /* * Unsucessful response. Attempting to unmarshall * into ErrorResponse type */ log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR && pauseIfRetryNeeded(++retries))) { shouldRetry = true; } else { log.debug("Attempting to unmarshal into the ErrorResponse type..."); ErrorResponse errorResponse = (ErrorResponse) getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString))); log.debug("Unmarshalled response into the ErrorResponse type."); com.amazonservices.mws.sellers.model.Error error = errorResponse.getError().get(0); if (status == HttpStatus.SC_SERVICE_UNAVAILABLE && !(error.getCode().equals("RequestThrottled")) && pauseIfRetryNeeded(++retries)) { shouldRetry = true; } else { shouldRetry = false; throw new MarketplaceWebServiceSellersException(error.getMessage(), status, error.getCode(), error.getType(), errorResponse.getRequestId(), errorResponse.toXML()); } } } } catch (JAXBException je) { /* * Response cannot be unmarshalled neither as * <Action>Response or ErrorResponse types. Checking for * other possible errors. */ log.debug("Caught JAXBException", je); log.debug("Response cannot be unmarshalled neither as " + actionName + "Response or ErrorResponse types." + "Checking for other possible errors."); MarketplaceWebServiceSellersException awse = processErrors(responseBodyString, status); throw awse; } catch (IOException ioe) { log.debug("Caught IOException exception", ioe); throw new MarketplaceWebServiceSellersException("Internal Error", ioe); } catch (MarketplaceWebServiceSellersException e) { throw e; } catch (Exception e) { log.debug("Caught Exception", e); throw new MarketplaceWebServiceSellersException(e); } finally { method.releaseConnection(); } } while (shouldRetry); } catch (MarketplaceWebServiceSellersException se) { log.debug("Caught MarketplaceWebServiceSellersException", se); throw se; } catch (Throwable t) { log.debug("Caught Exception", t); throw new MarketplaceWebServiceSellersException(t); } return response; }
From source file:org.springframework.web.portlet.DispatcherPortlet.java
/** * Processes the actual dispatching to the handler for event requests. * <p>The handler will be obtained by applying the portlet's HandlerMappings in order. * The HandlerAdapter will be obtained by querying the portlet's installed * HandlerAdapters to find the first that supports the handler class. * @param request current portlet action request * @param response current portlet Action response * @throws Exception in case of any kind of processing failure *///from w w w .jav a2 s .c om @Override protected void doEventService(EventRequest request, EventResponse response) throws Exception { if (logger.isDebugEnabled()) { logger.debug("DispatcherPortlet with name '" + getPortletName() + "' received action request"); } HandlerExecutionChain mappedHandler = null; int interceptorIndex = -1; try { // Determine handler for the current request. mappedHandler = getHandler(request); if (mappedHandler == null || mappedHandler.getHandler() == null) { noHandlerFound(request, response); return; } // Apply preHandle methods of registered interceptors. HandlerInterceptor[] interceptors = mappedHandler.getInterceptors(); if (interceptors != null) { for (int i = 0; i < interceptors.length; i++) { HandlerInterceptor interceptor = interceptors[i]; if (!interceptor.preHandleEvent(request, response, mappedHandler.getHandler())) { triggerAfterEventCompletion(mappedHandler, interceptorIndex, request, response, null); return; } interceptorIndex = i; } } // Actually invoke the handler. HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); ha.handleEvent(request, response, mappedHandler.getHandler()); // Trigger after-completion for successful outcome. triggerAfterEventCompletion(mappedHandler, interceptorIndex, request, response, null); } catch (Exception ex) { // Trigger after-completion for thrown exception. triggerAfterEventCompletion(mappedHandler, interceptorIndex, request, response, ex); // Forward the exception to the render phase to be displayed. if (this.forwardEventException) { try { exposeActionException(request, response, ex); logger.debug("Caught exception during event phase - forwarding to render phase", ex); } catch (IllegalStateException ex2) { // Probably sendRedirect called... need to rethrow exception immediately. throw ex; } } else { throw ex; } } catch (Error err) { PortletException ex = new PortletException( "Error occured during request processing: " + err.getMessage(), err); // Trigger after-completion for thrown exception. triggerAfterEventCompletion(mappedHandler, interceptorIndex, request, response, ex); throw ex; } }
From source file:org.springframework.web.portlet.DispatcherPortlet.java
/** * Processes the actual dispatching to the handler for action requests. * <p>The handler will be obtained by applying the portlet's HandlerMappings in order. * The HandlerAdapter will be obtained by querying the portlet's installed * HandlerAdapters to find the first that supports the handler class. * @param request current portlet action request * @param response current portlet Action response * @throws Exception in case of any kind of processing failure *//* w ww . j a v a2 s. c o m*/ @Override protected void doActionService(ActionRequest request, ActionResponse response) throws Exception { if (logger.isDebugEnabled()) { logger.debug("DispatcherPortlet with name '" + getPortletName() + "' received action request"); } ActionRequest processedRequest = request; HandlerExecutionChain mappedHandler = null; int interceptorIndex = -1; try { processedRequest = checkMultipart(request); // Determine handler for the current request. mappedHandler = getHandler(processedRequest); if (mappedHandler == null || mappedHandler.getHandler() == null) { noHandlerFound(processedRequest, response); return; } // Apply preHandle methods of registered interceptors. HandlerInterceptor[] interceptors = mappedHandler.getInterceptors(); if (interceptors != null) { for (int i = 0; i < interceptors.length; i++) { HandlerInterceptor interceptor = interceptors[i]; if (!interceptor.preHandleAction(processedRequest, response, mappedHandler.getHandler())) { triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, null); return; } interceptorIndex = i; } } // Actually invoke the handler. HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); ha.handleAction(processedRequest, response, mappedHandler.getHandler()); // Trigger after-completion for successful outcome. triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, null); } catch (Exception ex) { // Trigger after-completion for thrown exception. triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex); // Forward the exception to the render phase to be displayed. if (this.forwardActionException) { try { exposeActionException(request, response, ex); logger.debug("Caught exception during action phase - forwarding to render phase", ex); } catch (IllegalStateException ex2) { // Probably sendRedirect called... need to rethrow exception immediately. throw ex; } } else { throw ex; } } catch (Error err) { PortletException ex = new PortletException( "Error occured during request processing: " + err.getMessage(), err); // Trigger after-completion for thrown exception. triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex); throw ex; } finally { // Clean up any resources used by a multipart request. if (processedRequest instanceof MultipartActionRequest && processedRequest != request) { this.multipartResolver.cleanupMultipart((MultipartActionRequest) processedRequest); } } }
From source file:org.springframework.web.portlet.DispatcherPortlet.java
/** * Processes the actual dispatching to the handler for resource requests. * <p>The handler will be obtained by applying the portlet's HandlerMappings in order. * The HandlerAdapter will be obtained by querying the portlet's installed * HandlerAdapters to find the first that supports the handler class. * @param request current portlet render request * @param response current portlet render response * @throws Exception in case of any kind of processing failure */// w w w . j av a2 s. com @Override protected void doResourceService(ResourceRequest request, ResourceResponse response) throws Exception { if (logger.isDebugEnabled()) { logger.debug("DispatcherPortlet with name '" + getPortletName() + "' received resource request"); } HandlerExecutionChain mappedHandler = null; int interceptorIndex = -1; try { ModelAndView mv; try { // Determine handler for the current request. mappedHandler = getHandler(request); if (mappedHandler == null || mappedHandler.getHandler() == null) { noHandlerFound(request, response); return; } // Apply preHandle methods of registered interceptors. HandlerInterceptor[] interceptors = mappedHandler.getInterceptors(); if (interceptors != null) { for (int i = 0; i < interceptors.length; i++) { HandlerInterceptor interceptor = interceptors[i]; if (!interceptor.preHandleResource(request, response, mappedHandler.getHandler())) { triggerAfterResourceCompletion(mappedHandler, interceptorIndex, request, response, null); return; } interceptorIndex = i; } } // Actually invoke the handler. HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); mv = ha.handleResource(request, response, mappedHandler.getHandler()); // Apply postHandle methods of registered interceptors. if (interceptors != null) { for (int i = interceptors.length - 1; i >= 0; i--) { HandlerInterceptor interceptor = interceptors[i]; interceptor.postHandleResource(request, response, mappedHandler.getHandler(), mv); } } } catch (ModelAndViewDefiningException ex) { logger.debug("ModelAndViewDefiningException encountered", ex); mv = ex.getModelAndView(); } catch (Exception ex) { Object handler = (mappedHandler != null ? mappedHandler.getHandler() : null); mv = processHandlerException(request, response, handler, ex); } // Did the handler return a view to render? if (mv != null && !mv.isEmpty()) { render(mv, request, response); } else { if (logger.isDebugEnabled()) { logger.debug("Null ModelAndView returned to DispatcherPortlet with name '" + getPortletName() + "': assuming HandlerAdapter completed request handling"); } } // Trigger after-completion for successful outcome. triggerAfterResourceCompletion(mappedHandler, interceptorIndex, request, response, null); } catch (Exception ex) { // Trigger after-completion for thrown exception. triggerAfterResourceCompletion(mappedHandler, interceptorIndex, request, response, ex); throw ex; } catch (Error err) { PortletException ex = new PortletException( "Error occured during request processing: " + err.getMessage(), err); // Trigger after-completion for thrown exception. triggerAfterResourceCompletion(mappedHandler, interceptorIndex, request, response, ex); throw ex; } }
From source file:org.springframework.web.portlet.DispatcherPortlet.java
/** * Processes the actual dispatching to the handler for render requests. * <p>The handler will be obtained by applying the portlet's HandlerMappings in order. * The HandlerAdapter will be obtained by querying the portlet's installed * HandlerAdapters to find the first that supports the handler class. * @param request current portlet render request * @param response current portlet render response * @throws Exception in case of any kind of processing failure *///from w ww . ja v a 2 s. c om @Override protected void doRenderService(RenderRequest request, RenderResponse response) throws Exception { if (logger.isDebugEnabled()) { logger.debug("DispatcherPortlet with name '" + getPortletName() + "' received render request"); } HandlerExecutionChain mappedHandler = null; int interceptorIndex = -1; try { ModelAndView mv; try { // Determine handler for the current request. mappedHandler = getHandler(request); if (mappedHandler == null || mappedHandler.getHandler() == null) { noHandlerFound(request, response); return; } // Apply preHandle methods of registered interceptors. HandlerInterceptor[] interceptors = mappedHandler.getInterceptors(); if (interceptors != null) { for (int i = 0; i < interceptors.length; i++) { HandlerInterceptor interceptor = interceptors[i]; if (!interceptor.preHandleRender(request, response, mappedHandler.getHandler())) { triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, null); return; } interceptorIndex = i; } } // Check for forwarded exception from the action phase PortletSession session = request.getPortletSession(false); if (session != null) { if (request.getParameter(ACTION_EXCEPTION_RENDER_PARAMETER) != null) { Exception ex = (Exception) session.getAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE); if (ex != null) { logger.debug("Render phase found exception caught during action phase - rethrowing it"); throw ex; } } else { session.removeAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE); } } // Actually invoke the handler. HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); mv = ha.handleRender(request, response, mappedHandler.getHandler()); // Apply postHandle methods of registered interceptors. if (interceptors != null) { for (int i = interceptors.length - 1; i >= 0; i--) { HandlerInterceptor interceptor = interceptors[i]; interceptor.postHandleRender(request, response, mappedHandler.getHandler(), mv); } } } catch (ModelAndViewDefiningException ex) { logger.debug("ModelAndViewDefiningException encountered", ex); mv = ex.getModelAndView(); } catch (Exception ex) { Object handler = (mappedHandler != null ? mappedHandler.getHandler() : null); mv = processHandlerException(request, response, handler, ex); } // Did the handler return a view to render? if (mv != null && !mv.isEmpty()) { render(mv, request, response); } else { if (logger.isDebugEnabled()) { logger.debug("Null ModelAndView returned to DispatcherPortlet with name '" + getPortletName() + "': assuming HandlerAdapter completed request handling"); } } // Trigger after-completion for successful outcome. triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, null); } catch (Exception ex) { // Trigger after-completion for thrown exception. triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, ex); throw ex; } catch (Error err) { PortletException ex = new PortletException( "Error occured during request processing: " + err.getMessage(), err); // Trigger after-completion for thrown exception. triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, ex); throw ex; } }
From source file:com.amazonaws.mws.MarketplaceWebServiceOrdersClient.java
/** * Invokes request using parameters from parameters map. Returns response of * the T type passed to this method/*from w w w . ja v a 2 s . c om*/ */ private <T> T invoke(Class<T> clazz, Map<String, String> parameters) throws MarketplaceWebServiceOrdersException { String actionName = parameters.get("Action"); T response = null; String responseBodyString = null; HttpPost method = new HttpPost(config.getServiceURL()); int status = -1; log.debug("Invoking" + actionName + " request. Current parameters: " + parameters); try { /* Set content type and encoding */ log.debug("Setting content-type to application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); method.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); /* Set X-Amazon-User-Agent to header */ method.addHeader("X-Amazon-User-Agent", config.getUserAgent()); /* Add required request parameters and set request body */ log.debug("Adding required parameters..."); method.setEntity(createEntity(parameters)); log.debug("Done adding additional required parameteres. Parameters now: " + parameters); boolean shouldRetry = true; int retries = 0; HttpResponse httpResponse = null; do { log.debug("Sending Request to host: " + config.getServiceURL()); try { /* Submit request */ httpResponse = httpClient.execute(method); status = httpResponse.getStatusLine().getStatusCode(); /* Consume response stream */ responseBodyString = getResponsBodyAsString(httpResponse.getEntity().getContent()); /* * Successful response. Attempting to unmarshal into the * <Action>Response type */ if (status == HttpStatus.SC_OK && responseBodyString != null) { shouldRetry = false; log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); log.debug("Attempting to unmarshal into the " + actionName + "Response type..."); response = clazz.cast(getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString)))); log.debug("Unmarshalled response into " + actionName + "Response type."); } else { /* * Unsucessful response. Attempting to unmarshall * into ErrorResponse type */ log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR && pauseIfRetryNeeded(++retries))) { shouldRetry = true; } else { log.debug("Attempting to unmarshal into the ErrorResponse type..."); ErrorResponse errorResponse = (ErrorResponse) getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString))); log.debug("Unmarshalled response into the ErrorResponse type."); com.amazonaws.mws.model.orders.Error error = errorResponse.getError().get(0); if (status == HttpStatus.SC_SERVICE_UNAVAILABLE && !(error.getCode().equals("RequestThrottled")) && pauseIfRetryNeeded(++retries)) { shouldRetry = true; } else { shouldRetry = false; throw new MarketplaceWebServiceOrdersException(error.getMessage(), status, error.getCode(), error.getType(), errorResponse.getRequestId(), errorResponse.toXML()); } } } } catch (JAXBException je) { /* * Response cannot be unmarshalled neither as * <Action>Response or ErrorResponse types. Checking for * other possible errors. */ log.debug("Caught JAXBException", je); log.debug("Response cannot be unmarshalled neither as " + actionName + "Response or ErrorResponse types." + "Checking for other possible errors."); MarketplaceWebServiceOrdersException awse = processErrors(responseBodyString, status); throw awse; } catch (IOException ioe) { log.debug("Caught IOException exception", ioe); throw new MarketplaceWebServiceOrdersException("Internal Error", ioe); } catch (MarketplaceWebServiceOrdersException e) { throw e; } catch (Exception e) { log.debug("Caught Exception", e); throw new MarketplaceWebServiceOrdersException(e); } finally { method.releaseConnection(); } } while (shouldRetry); } catch (MarketplaceWebServiceOrdersException se) { log.debug("Caught MarketplaceWebServiceOrdersException", se); throw se; } catch (Throwable t) { log.debug("Caught Exception", t); throw new MarketplaceWebServiceOrdersException(t); } return response; }
From source file:com.amazonaws.fps.AmazonFPSClient.java
/** * Invokes request using parameters from parameters map. Returns response of * the T type passed to this method//from w w w . j ava2 s .c om */ private <T> T invoke(Class<T> clazz, Map<String, String> parameters) throws AmazonFPSException { String actionName = parameters.get("Action"); T response = null; String responseBodyString = null; PostMethod method = new PostMethod(config.getServiceURL()); int status = -1; log.debug("Invoking" + actionName + " request. Current parameters: " + parameters); try { /* Set content type and encoding */ log.debug("Setting content-type to application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); /* Add required request parameters and set request body */ log.debug("Adding required parameters..."); addRequiredParametersToRequest(method, parameters); System.out.println(parameters); log.debug("Done adding additional required parameteres. Parameters now: " + parameters); boolean shouldRetry = true; int retries = 0; do { log.debug("Sending Request to host: " + config.getServiceURL()); try { /* Submit request */ status = httpClient.executeMethod(method); /* Consume response stream */ responseBodyString = getResponsBodyAsString(method.getResponseBodyAsStream()); /* * Successful response. Attempting to unmarshal into the * <Action>Response type */ if (status == HttpStatus.SC_OK) { shouldRetry = false; log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); log.debug("Attempting to unmarshal into the " + actionName + "Response type..."); response = clazz.cast(getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString)))); log.debug("Unmarshalled response into " + actionName + "Response type."); } else { /* * Unsucessful response. Attempting to unmarshall * into ErrorResponse type */ log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR || status == HttpStatus.SC_SERVICE_UNAVAILABLE) && pauseIfRetryNeeded(++retries)) { shouldRetry = true; } else { log.debug("Attempting to unmarshal into the ErrorResponse type..."); ErrorResponse errorResponse = (ErrorResponse) getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString))); log.debug("Unmarshalled response into the ErrorResponse type."); com.amazonaws.fps.model.Error error = errorResponse.getError().get(0); throw new AmazonFPSException(error.getMessage(), status, error.getCode(), error.getType(), errorResponse.getRequestId(), errorResponse.toXML()); } } } catch (JAXBException je) { /* * Response cannot be unmarshalled neither as * <Action>Response or ErrorResponse types. Checking for * other possible errors. */ log.debug("Caught JAXBException", je); log.debug("Response cannot be unmarshalled neither as " + actionName + "Response or ErrorResponse types." + "Checking for other possible errors."); AmazonFPSException awse = processErrors(responseBodyString, status); throw awse; } catch (IOException ioe) { log.debug("Caught IOException exception", ioe); throw new AmazonFPSException("Internal Error", ioe); } catch (Exception e) { log.debug("Caught Exception", e); throw new AmazonFPSException(e); } finally { method.releaseConnection(); } } while (shouldRetry); } catch (AmazonFPSException se) { log.debug("Caught AmazonFPSException", se); throw se; } catch (Throwable t) { log.debug("Caught Exception", t); throw new AmazonFPSException(t); } return response; }
From source file:mondrian.gui.Workbench.java
/** * Check if schema file is valid by initiating a mondrian connection. */// w w w. j av a 2 s.c o m private void checkSchemaFile(File file) { try { // this connection parses the catalog file which if invalid will // throw exception PropertyList list = new PropertyList(); list.put("Provider", "mondrian"); list.put("Jdbc", jdbcConnectionUrl); list.put("Catalog", file.toURI().toURL().toString()); list.put("JdbcDrivers", jdbcDriverClassName); if (jdbcUsername != null && jdbcUsername.length() > 0) { list.put("JdbcUser", jdbcUsername); } if (jdbcPassword != null && jdbcPassword.length() > 0) { list.put("JdbcPassword", jdbcPassword); } DriverManager.getConnection(list, null); } catch (Exception ex) { LOGGER.error("Exception : Schema file " + file.getAbsolutePath() + " is invalid." + ex.getMessage(), ex); } catch (Error err) { LOGGER.error("Error : Schema file " + file.getAbsolutePath() + " is invalid." + err.getMessage(), err); } }
From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java
public void processNewMMCSignal(SignalEx signal) { ContentValues values = null;//from w ww . j a va 2 s . com // if in a service outage, store a null signal // (I've seen cases where phone was out of service yet it was still returning a signal level) try { if (mPhoneState.getLastServiceState() == ServiceState.STATE_OUT_OF_SERVICE) signal = null; // avoid storing repeating identical signals if (mPhoneState.lastKnownMMCSignal != null && mPhoneState.lastKnownMMCSignal.getSignalStrength() != null && signal != null && signal.getSignalStrength() != null) if (mPhoneState.lastKnownMMCSignal.getSignalStrength().toString().equals( signal.getSignalStrength().toString()) && tmlastSig + 3000 > System.currentTimeMillis()) return; tmlastSig = System.currentTimeMillis(); Integer dbmValue = 0; boolean isLTE = false; if (signal == null) dbmValue = -256; else if (signal.getSignalStrength() == null) dbmValue = 0; //store the last known signal if (signal != null && signal.getSignalStrength() != null) { prevMMCSignal = mPhoneState.lastKnownMMCSignal; // used for looking at signal just before a call ended mPhoneState.lastKnownMMCSignal = signal; } else if (signal == null) mPhoneState.lastKnownMMCSignal = null; //push the new signal level into the sqlite database long stagedEventId = owner.getEventManager().getStagedEventId(); int serviceState = mPhoneState.getLastServiceState(); int wifiSignal = -1; WifiManager wifiManager = (WifiManager) owner.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiinfo = wifiManager.getConnectionInfo(); if (wifiinfo != null && wifiinfo.getBSSID() != null) wifiSignal = wifiManager.getConnectionInfo().getRssi(); //if (signal != null) // disabled because we do want the no-signal to be written to the signals table { values = ContentValuesGenerator.generateFromSignal(signal, telephonyManager.getPhoneType(), telephonyManager.getNetworkType(), serviceState, telephonyManager.getDataState(), stagedEventId, wifiSignal, mPhoneState.mServicemode); Integer valSignal = (Integer) values.get("signal"); if (mPhoneState.getNetworkType() == PhoneState.NETWORK_NEWTYPE_LTE) // && phoneStateListener.previousNetworkState == TelephonyManager.DATA_CONNECTED) valSignal = (Integer) values.get("lteRsrp"); if (valSignal != null && dbmValue != null && valSignal > -130 && valSignal < -30) // && (dbmValue <= -120 || dbmValue >= -1)) dbmValue = valSignal; if ((dbmValue > -120 || mPhoneState.getNetworkType() == PhoneState.NETWORK_NEWTYPE_LTE) && dbmValue < -40) this.validSignal = true; if (this.validSignal) // make sure phone has at least one valid signal before recording owner.getDBProvider(owner).insert(TablesEnum.SIGNAL_STRENGTHS.getContentUri(), values); } //update the signal strength percentometer, chart, and look for low/high signal event if (dbmValue != null) { if (dbmValue < -120) // might be -256 if no service, but want to display as -120 on livestatus chart dbmValue = -120; owner.getIntentDispatcher().updateSignalStrength(dbmValue, mPhoneState.getNetworkType(), owner.bWifiConnected, wifiSignal); // Store signal in a sharedPreference for tools such as Indoor/Transit sample mapper, which dont have reference to service if (isLTE == true) // improve the value of the signal for LTE, so that Indoor samples don't look redder in LTE PreferenceManager.getDefaultSharedPreferences(owner).edit() .putInt(PreferenceKeys.Miscellaneous.SIGNAL_STRENGTH, (dbmValue + 15)).commit(); else PreferenceManager.getDefaultSharedPreferences(owner).edit() .putInt(PreferenceKeys.Miscellaneous.SIGNAL_STRENGTH, dbmValue).commit(); } } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "exception", e); LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "values: " + values); } catch (Error err) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "processNewMMCSignal", "error" + err.getMessage()); } }