@Override
	public void execute(IntuitMessage intuitMessage) throws FMSException {	
		LOG.debug("Enter HTTPURLConnectionInterceptor...");
		RequestElements intuitRequest = intuitMessage.getRequestElements();
		
		URI uri = null;
		HttpURLConnection httpUrlConnection = null;
		String methodtype = intuitRequest.getRequestParameters().get(RequestElements.REQ_PARAM_METHOD_TYPE);
		
		//setup proxy if configured
		Proxy proxy = setupProxy();
		
		try {
			uri = new URI(intuitRequest.getRequestParameters().get(RequestElements.REQ_PARAM_RESOURCE_URL));
			URL url = uri.toURL();	
			
			httpUrlConnection = proxy==null? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
			httpUrlConnection.setRequestMethod(methodtype);
			
			//set timeouts
			setTimeout(httpUrlConnection);				
			
			// populate the headers
			populateRequestHeaders(httpUrlConnection, intuitRequest.getRequestHeaders());
					
			// authorize the request
			authorizeRequest(intuitRequest.getContext(), httpUrlConnection);			
			
			if(intuitRequest.getCompressedData()!=null){
				httpUrlConnection.setDoOutput(true);
			}
			
			LOG.debug("Request URI : " + uri);
			LOG.debug("Request Method : " + methodtype);
			LOG.debug("Request Headers : " + httpUrlConnection.getRequestProperties());
			LOG.debug("Request Body : " + intuitRequest.getSerializedData());
			
			//connect
			httpUrlConnection.connect();
			
			// Send the payload (if any).
			if (methodtype.equals(MethodType.POST.toString())) {
				byte[] compressedData = intuitRequest.getCompressedData();
				if (compressedData != null) {					
					DataOutputStream  output = new DataOutputStream(httpUrlConnection.getOutputStream());					
					output.write(compressedData);
					output.flush();
					output.close();
				}
			}
			
			setResponseElements(intuitMessage, httpUrlConnection);
			
		} catch (URISyntaxException e) {
			throw new FMSException("URISyntaxException", e);
		} catch (IOException e) {
			throw new FMSException("IO Exception", e);
		} catch(Throwable e){
			throw new FMSException("Unexpected expection", e);
		}
		finally{
			// Make sure to always disconnect.
			httpUrlConnection.disconnect();
		}		
		
		LOG.debug("Exit HTTPURLConnectionInterceptor.");
	}
@ Override public void execute ( IntuitMessage intuitMessage ) throws FMSException { LOG . debug ( "Enter HTTPURLConnectionInterceptor..." ) ; RequestElements intuitRequest = intuitMessage . getRequestElements ( ) ; URI uri = null ; HttpURLConnection httpUrlConnection = null ; String methodtype = intuitRequest . getRequestParameters ( ) . get ( RequestElements . REQ_PARAM_METHOD_TYPE ) ; Proxy proxy = setupProxy ( ) ; try { uri = new URI ( intuitRequest . getRequestParameters ( ) . get ( RequestElements . REQ_PARAM_RESOURCE_URL ) ) ; URL url = uri . toURL ( ) ; httpUrlConnection = proxy == null ? ( HttpURLConnection ) url . openConnection ( ) : ( HttpURLConnection ) url . openConnection ( proxy ) ; httpUrlConnection . setRequestMethod ( methodtype ) ; setTimeout ( httpUrlConnection ) ; populateRequestHeaders ( httpUrlConnection , intuitRequest . getRequestHeaders ( ) ) ; authorizeRequest ( intuitRequest . getContext ( ) , httpUrlConnection ) ; if ( intuitRequest . getCompressedData ( ) != null ) { httpUrlConnection . setDoOutput ( true ) ; } LOG . debug ( "Request URI : " + uri ) ; LOG . debug ( "Request Method : " + methodtype ) ; LOG . debug ( "Request Headers : " + httpUrlConnection . getRequestProperties ( ) ) ; LOG . debug ( "Request Body : " + intuitRequest . getSerializedData ( ) ) ; httpUrlConnection . connect ( ) ; if ( methodtype . equals ( MethodType . POST . toString ( ) ) ) { byte [ ] compressedData = intuitRequest . getCompressedData ( ) ; if ( compressedData != null ) { DataOutputStream output = new DataOutputStream ( httpUrlConnection . getOutputStream ( ) ) ; output . write ( compressedData ) ; output . flush ( ) ; output . close ( ) ; } } setResponseElements ( intuitMessage , httpUrlConnection ) ; } catch ( URISyntaxException e ) { throw new FMSException ( "URISyntaxException" , e ) ; } catch ( IOException e ) { throw new FMSException ( "IO Exception" , e ) ; } catch ( Throwable e ) { throw new FMSException ( "Unexpected expection" , e ) ; } finally { httpUrlConnection . disconnect ( ) ; } LOG . debug ( "Exit HTTPURLConnectionInterceptor." ) ; }
{@inheritDoc}}