my arcgis js api submit a GP service request but 403 forbidden occurs

638
0
07-29-2011 05:42 PM
billchuang
New Contributor
Hi,I encountered a thorny trouble,Now I publish a GP toolbox in the arcgis server in order that I can request GP service from the client browser.I use the "submitJob" method of esri.tasks.Geoprocessing object to request service.But unfortunately,my params exceed 2k character,so I have to use the proxy,I config the proxy.jsp and proxy.ashx,proxy.config according the arcgis js api help doc.But when I use the proxy.jsp as the proxy to submit the job,the firefox remindered that
"http://localhost:8080/AgriService7.28/observationPlatform/proxy/proxy.jsp?http://localhost:8399/arcgis/rest/services/IsosurfaceAnalyze/GPServer/IsosurfaceAnalyze/submitJob 403 Forbidden"
when I use the proxy.ashx,the firefox remindered that "SyntaxError: illegal XML character",
when my params didn't exceed the limited characters ,I can succeed submitting the job,so I think the problem is my proxy configs,can anyone help me?

below is my proxy.jsp(in the code I don't know how to find the token,so I don't add it):
<%@page session="false"%>
<%@page import="java.net.*,java.io.*" %>
<%!
String[] serverUrls = {
//"<url>[,<token>]"
//For ex. (secured server): "http://myserver.mycompany.com/arcgis/rest/services,ayn2C2iPvqjeqWoXwV6rjmr43kyo23mhIPnXz2CEiMA6rVu0x..."
//For ex. (non-secured server): "http://sampleserver1.arcgisonline.com/arcgis/rest/services"
"http://BILL:8399/arcgis/rest/services",
"http://BILL:8399/arcgis/rest/services" //NOTE - no comma after the last item
};
%>
<%
try {
String reqUrl = request.getQueryString();
boolean allowed = false;
String token = null;
for(String surl : serverUrls) {
String[] stokens = surl.split("\\s*,\\s*");
if(reqUrl.toLowerCase().contains(stokens[0].toLowerCase())) {
allowed = true;
if(stokens.length >= 2 && stokens[1].length() > 0)
token = stokens[1];
break;
}
}
if(!allowed) {
response.setStatus(403);
return;
}
if(token != null) {
reqUrl = reqUrl + (reqUrl.indexOf("?") > -1 ? "&" : "?") + "token=" + token;
}
URL url = new URL(reqUrl);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setRequestMethod(request.getMethod());
if(request.getContentType() != null) {
con.setRequestProperty("Content-Type", request.getContentType());
}
con.setRequestProperty("Referer", request.getHeader("Referer"));
int clength = request.getContentLength();
if(clength > 0) {
con.setDoInput(true);
InputStream istream = request.getInputStream();
OutputStream os = con.getOutputStream();
final int length = 5000;
byte[] bytes = new byte[length];
int bytesRead = 0;
while ((bytesRead = istream.read(bytes, 0, length)) > 0) {
os.write(bytes, 0, bytesRead);
}
}
else {
con.setRequestMethod("GET");
}
out.clear();
out = pageContext.pushBody();
OutputStream ostream = response.getOutputStream();
response.setContentType(con.getContentType());
InputStream in = con.getInputStream();
final int length = 5000;
byte[] bytes = new byte[length];
int bytesRead = 0;
while ((bytesRead = in.read(bytes, 0, length)) > 0) {
ostream.write(bytes, 0, bytesRead);
}
} catch(Exception e) {
response.setStatus(500);
}
%>

below is the proxy.config:
<?xml version="1.0" encoding="utf-8" ?>
<!-- Proxy config is used to set the ArcGIS Server services that the proxy will forward to.

mustMatch: true to only proxy to sites listed, false to proxy to any site -->
<ProxyConfig mustMatch="false">
<serverUrls>
<!-- serverUrl options:
url = location of the ArcGIS Server, either specific URL or stem
matchAll = true to forward any request beginning with the url
token = (optional) token to include for secured service
dynamicToken = if true, gets token dynamically with username and
password stored in web.config file's appSettings section.
-->
<serverUrl url="http:/BILL:8399/arcgis/rest/services/"
matchAll="true"></serverUrl>
<serverUrl url="http://sampleserver1.arcgisonline.com/arcgis/rest/services/"
matchAll="true"></serverUrl>
<serverUrl url="http://sampleserver2.arcgisonline.com/arcgis/rest/services/"
matchAll="true"
token=""></serverUrl>
<serverUrl url="http://server.arcgisonline.com/arcgis/rest/services/"
matchAll="true"></serverUrl>
<serverUrl url="http://orthogonal.esri.com/arcgis/rest/services/"
matchAll="true"></serverUrl>
<serverUrl url="http://hummer/ArcGIS/rest/services"
matchAll="true"
dynamicToken="true"
></serverUrl>
</serverUrls>

</ProxyConfig>

notesï¼?I use arcgis 10
0 Kudos
0 Replies