ฉันกำลังพยายามส่งข้อมูลการบันทึกจากแอปเพล็ตการสแกนเอกสารไปยังเว็บเซิร์ฟเวอร์ที่ขับเคลื่อนด้วย django
ฉันกำลังทดสอบโดยใช้เว็บเซิร์ฟเวอร์ของ django เอง ฉันได้สร้างคำขอ POST แบบง่าย ๆ ด้วย java แต่เซิร์ฟเวอร์ django กำลังส่งข้อผิดพลาด 500 ฉันไม่สามารถรับข้อมูลใดๆ เกี่ยวกับข้อผิดพลาดได้ ดูเหมือนว่าฉันจะใช้ pydevd เพื่อทำลายโค้ดในมุมมอง django ของฉันไม่ได้ (URL ของฉันได้รับการตั้งค่าอย่างถูกต้อง - ฉันสามารถอ่านโค้ดได้หากไปที่ URL ด้วยเบราว์เซอร์) ฉันไม่มีการตั้งค่าการดีบักในแอปเพล็ต แต่มีข้อมูลมากมายที่จะไปที่คอนโซล ฉันรู้ว่า django ส่งข้อมูล html จำนวนมากพร้อมกับข้อผิดพลาด 500 แต่แอปเพล็ต java ของฉันกำลังส่งข้อยกเว้น (เพื่อตอบสนองต่อข้อผิดพลาด 500) ก่อนที่จะสามารถอ่านข้อความได้
นี่คือรหัสในแอปเพล็ตของฉัน -
private boolean log(String scanURL) {
try {
String data = "log=" + buffer.toString();
URL url = new URL(scanURL);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(data);
writer.flush();
// Handle the response
int responseCode = ((HttpURLConnection) conn).getResponseCode();
addItem("Http response code " + new Integer(responseCode).toString());
addItem("creating BufferedReader");
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
addItem("reading response");
while ((line = reader.readLine()) != null) {
addItem(line);
}
addItem("Closing Writer");
writer.close();
addItem("Closing Reader");
reader.close();
if (responseCode == 200) {
return true;
}
else {
return false;
}
} catch (Exception e) {
addItem("Error - writing to log failed. " + e);
return false;
}
}
และมุมมอง django ของฉันคือ -
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from cache.shortcuts import permission_required
@login_required
@permission_required('documents.add_documentindex', raise_exception=True)
def save_log(request):
import pydevd;pydevd.settrace()
log_text = request.POST['log']
with open("scanning.log", "a") as f:
f.write(log_text)
return HttpResponse('ok')
ฉันสงสัยว่าฉันต้องทำงานบางอย่างกับส่วนหัว http แต่ถ้าไม่มีข้อมูลเพิ่มเติมอีกเล็กน้อยจาก django ความรู้ของฉันเกี่ยวกับ http ก็เป็นอุปสรรคอย่างมาก
ข้อเสนอแนะใด ๆ ในการทำให้สิ่งนี้ใช้งานได้หรือแม้แต่รับข้อมูลเพิ่มเติมเล็กน้อยเกี่ยวกับข้อผิดพลาดเซิร์ฟเวอร์ 500 ของ django จะได้รับการชื่นชมอย่างมาก!
อัปเดต stacktrace จากข้อยกเว้น Java เป็นดังนี้
java.io.IOException: Server returned HTTP response code: 500 for URL: http://10.0.0.68:8000/scanning_log
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at co.altcom.cache.scanner.CacheScan.log(CacheScan.java:408)
at co.altcom.cache.scanner.CacheScan.createLog(CacheScan.java:385)
at co.altcom.cache.scanner.CacheScan.destroy(CacheScan.java:70)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://10.0.0.68:8000/scanning_log
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at co.altcom.cache.scanner.CacheScan.log(CacheScan.java:405)
... 4 more
"Error - writing to log failed." + e
เอ่อ?.. แกล้งทำเป็นว่าเราไม่ได้กำลังดูคอมพิวเตอร์ของคุณและลองเพิ่มe.printStackTrace();
และคัดลอก/วางเอาต์พุต - person Andrew Thompson   schedule 29.08.2012creating BufferedReader
- มันปรากฏที่ไหนกันแน่? บรรทัดที่ 405 ของCacheScan.java
คืออะไร - person Andrew Thompson   schedule 29.08.2012