Tag Archives: http

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest

Questions: I’m developing a servlet that receives a multipart request with content of multiple files, and I’m using apache commons file upload libraries. When I call parseRequest(request); method servlet throws following exception: GRAVE: Servlet.service() for servlet DiffOntology threw exception java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest at org.apache.commons.fileupload.servlet.ServletRequestContext.getContentType(ServletRequestContext.java:73) at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:882) at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331) at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:349) at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126) at DiffOntology.doPost(DiffOntology.java:38) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)… Read More »

How to modify the header of a HttpUrlConnection

Questions: Im trying to improve the Java Html Document a little but i’m running into problems with the HttpUrlConntion. One thing is that some servers block a request if the user agent is a Java VM. Another problem is that the HttpUrlConnection does not set the Referrer or Location header field. Since several sites use… Read More »

How can I read an HttpServletReponses output stream?

Questions: I want to make a Servlet filter that will read the contents of the Response after it’s been processed and completed and return that information in XML or PDF or whatever. But I’m not sure how to get any information out of the HttpServletResponse object. How can I get at this information? Answers: Add… Read More »

Preemptive Basic Auth with HttpUrlConnection?

Questions: What is the best way to use preemptive basic http authentication using HttpUrlConnection. (Assume for now I can’t use HttpClient). EDIT for clarification: I’m setting the un/pw correctly in the request header using Base64 encoding. Are there any additional flags or properties that need to be set, or is the fact that I’m setting… Read More »

Disable HttpClient logging

Questions: I am using commons-httpclient 3.1 in an integration test suite. The default logging for HttpClient is extremely noisy and I can’t seem to turn it off. I’ve tried following the instructions here but none of them make any difference. Mostly I just need to make the org.apache.http.wire logger shut up. Part of the problem… Read More »

Parse JSON from HttpURLConnection object

Questions: I am doing basic http auth with the HttpURLConnection object in Java. URL urlUse = new URL(url); HttpURLConnection conn = null; conn = (HttpURLConnection) urlUse.openConnection(); conn.setRequestMethod(“GET”); conn.setRequestProperty(“Content-length”, “0”); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.setConnectTimeout(timeout); conn.setReadTimeout(timeout); conn.connect(); if(conn.getResponseCode()==201 || conn.getResponseCode()==200) { success = true; } I am expecting a JSON object, or string data in the format of… Read More »

How do I parse JSON from a Java HTTPResponse?

Questions: I have an HttpResponse object for a web request I just made. The response is in the JSON format, so I need to parse it. I can do it in an absurdly complex way, but it seems like there must be a better way. Is this really the best I can do? HttpResponse response;… Read More »

how to get a client's MAC address from HttpServlet?

Questions: I was asked to write a servlet that collects client’s details such as ip, mac address etc. getting his IP is pretty straight-forward (request.getRemoteAddr()) but I dont find an elegant way to get his MAC address. seems reasonable that the web server has access to data such as Mac address etc, since it gets… Read More »

Persistent HttpURLConnection in Java

Questions: I am trying to write a java program that will automatically download and name some of my favorite web comics. Since I will be requesting multiple objects from the same domain, I wanted to have a persistent http connection that I could keep open until all the comics have been downloaded. Below is my… Read More »