I am trying to make a ajax call to other domain locally from my computer by writing some proxy code in jsp. And this is my jQuery AJAX code that is calling proxy.jsp page.
var search_agile_metadata = 'https://search.xyz.com/rest-services/services/ag/get?id=';
var on_show_info = function() {
var outOfDomainCall = search_agile_metadata + current_doc_info.id;//An XML document
request_meta_info = $.ajax({
url: "proxy.jsp?url=" + outOfDomainCall ,
type: 'GET',
success: on_get_metadata,
error: on_get_metadata_agile
});
};
var on_get_metadata = function(data, text_status, XMLHttpRequest) {
console.log(data);
}
Any my proxy.jsp file is:-
<%@ page language="java" import="org.w3c.dom.*,javax.xml.parsers.DocumentBuilder,javax.xml.parsers.DocumentBuilderFactory,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
final String login ="user";
final String password ="pass";
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (login, password.toCharArray());
}
});
String a_Url = request.getParameter( "url" ) ;
String l_Content = "" ;
if( a_Url!=null && a_Url.length()>0 )
l_Content = GetContent( a_Url ).toString() ;
out.println( l_Content );
%>
<%!
StringBuffer GetContent( String a_Url ) throws Exception
{
URL l_URL = new URL(a_Url);
BufferedReader l_Reader = new BufferedReader( new InputStreamReader( l_URL.openStream()));
StringBuffer l_Result = new StringBuffer("") ;
String l_InputLine = null ;
while ((l_InputLine = l_Reader.readLine()) != null)
//System.out.println("Print3" +l_InputLine );
l_Result.append( l_InputLine );
l_Reader.close();
return( l_Result ) ;
}
%>
And When I get the response back from this proxy.jsp file, I get this error:-
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>302 Found</title></head><body><h1>Found</h1><p>The document has moved <a href="HTTP://search.xyz.com/rest-services/se/agile/get?id=CD90">here</a>.</p></body></html>
And if I check the status code in that above jQuery AJAX code then it is 200. So that means something is happening in the proxy.jsp page. Why it is not able to get the contents of url. Any suggestions will be appreciated...