Month: May 2014

Proxy tunneling failed: ForbiddenUnable to establish SSL connection.

When ever your are tying to access a web-service URL using browser or curl or through elinks  command (In LINUX OS) which is hosted in different machine over intranet we may face this problem.
In our case we are trying to get the WSDL file using wget command,
Connecting to X.X.X.X:8085… connected. Proxy tunneling failed: ForbiddenUnable to establish SSL connection.
Where Y.Y.Y.Y stands for valid IP address and 7443 is port on which web-service is running .
We are getting “Proxy tunneling failed” exception, To overcome this issue we need to add the proxy server details as shown below in /etc/environment file.
Use vim /etc/environment  command and add the below entries for http_proxy and https_proxy with valid IP and port number in that file.
environment.
Ex :
http_proxy="http://X.X.X.X:8085/"
https_proxy="https://X.X.X.X:8085/"

The other way is you can use no-proxy in /etc/environment file which you can add the ip to be excluded from proxy server.

export no_proxy=”localhost,127.0.0.1,Y.Y.Y.Y”
Continue reading “Proxy tunneling failed: ForbiddenUnable to establish SSL connection.”

Program to apply water mark to an image

Requirement:
Need to apply a water mark for a given image.
</pre>
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ApplyWaterMark
{
    
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        BufferedImage bufferedImage;
        try
        {
            
            bufferedImage = ImageIO.read(new File("/home/krishna/WP_20_025.jpg"));
            Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
            
            //Create an alpha composite of 50%  
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.5f);  
            g2d.setComposite(alpha);  
            
            
            g2d.setColor(Color.RED);  
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,  
                                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);  
              
            g2d.setFont(new Font("Arial", Font.BOLD, 30));  
              
            String watermark = "Copyright © 2014";  
              
            FontMetrics fontMetrics = g2d.getFontMetrics();  
            Rectangle2D rect = fontMetrics.getStringBounds(watermark, g2d);  
              
            int centerX = (bufferedImage.getWidth() - (int) rect.getWidth()) / 2;  
            int centerY = (bufferedImage.getHeight() - (int) rect.getHeight()) / 2;  
            g2d.drawString(watermark, centerX, centerY);  
              
            //Free graphic resources  
            g2d.dispose();
            
            ImageIO.write(bufferedImage, "jpg", new File("/home/Desktop/dsc0027.jpg"));
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        
    }
    
}

<pre>

Input File:

WP_20140420_025

Output File:
dsc0027