473,378 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

JCIFS and Tomcat

Hello,

I am trying to read a web page from within a tomcat servlet, using my
company Proxy server (NTLM). When I try to do this, I get a 407. What
means that my servlet did not pass the proxy. When I run the program
stand alone every thing works fine. Can someone help me with this.

Here some sample code:

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jcifs.Config;

public class AccessWebService extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.getWriter().print(readWeb()); //result: HTTP 407
}

public static void main(String[] args) throws IOException {
AccessWebService service = new AccessWebService();
System.out.print(service.readWeb());
//result: requested web page
}
public String readWeb() throws IOException {
enableProxy();
byte[] response = read(new URL("http://groups.google.com/"));
disableProxy();
return new String(response);
}

private byte[] read(URL url) throws IOException {
HttpURLConnection httpConn =
(HttpURLConnection)url.openConnection();

byte[] result = getResponse(httpConn);
httpConn.disconnect();

return result;
}

private byte[] getResponse(HttpURLConnection httpConn) throws
IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
transfer(httpConn.getInputStream(), out);

return out.toByteArray();
}

private void transfer(InputStream in, OutputStream out) throws
IOException {
byte[] buffer = new byte[2048];
int bytesRead = 0;

while ((bytesRead = in.read(buffer)) > -1) {
out.write(buffer, 0, bytesRead);
}

in.close();
}

private void enableProxy() {
Config.setProperty("jcifs.smb.client.domain","mydo main");
Config.setProperty("jcifs.smb.client.username","my username");

Config.setProperty("jcifs.smb.client.password","my password");

Properties systemProperties = System.getProperties();

systemProperties.setProperty("http.proxyHost","myp roxyhost");

systemProperties.setProperty("http.proxyPort","myp roxyport");

Config.registerSmbURLHandler();
}

private void disableProxy() {
Config.setProperty("jcifs.smb.client.domain", "");
Config.setProperty("jcifs.smb.client.username", "");
Config.setProperty("jcifs.smb.client.password", "");

Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost", "");
systemProperties.setProperty("http.proxyPort", "");
systemProperties.setProperty("java.protocol.handle r.pkgs",
"");
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Jul 17 '05 #1
0 4197

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: SamMan | last post by:
We are getting new computers at work and I got the word today that pc-lan (network admins) do not want IIS installed on ANY machine. We are primarily a Java development house, so they will not balk...
5
by: nmac | last post by:
Hi all, hopefully someone can offer some sagely advice regarding Production use of Jakarta's Tomcat. First, some brief background. My company have a servlet application that connects to a MySQL...
2
by: kimbuba | last post by:
Hi all, i'm writing cause i'm not able to find any good resources about this topic. I'm programming on tomcat and i have my browser open to see changes i made. The problem is that i'd like to see...
6
by: DaiIchi | last post by:
I'm using Tomcat in standalone mode. When a URL without a filename is entered into the browser (ie. "http://myhost.mydomain.com"), and the default path does NOT have an index.html, but rather an...
5
by: D E | last post by:
When using my web application manager (http://localhost:8080/admin) I forgot my password. Is there an XML file i can look at to remember/obtain (possibly even set). Thanks
3
by: danish | last post by:
hi everyone..sorry everyone if ive posted on the wrong group but i really needed help.... i wan tto start jakarta-tomcat-5.5.3 from the webbrowser using the sheel scripts...i normally use the...
4
by: Edward V. Berard | last post by:
People, I am having problems developing Java applications on a Mac using Eclipse, MyEclipse, and Tomcat 5.5+. My current configuration: Mac OS X (10.4.5) Eclipse (3.1+) MyEclipse (4.0+)
1
by: ashok2006 | last post by:
Hi everybody, Here is my problem:- When I start tomcat the command prompt for tomcat openes but closes within seconds. I've following environment varibles set:- CATALINA_HOME ...
0
by: Arun21084 | last post by:
Hi, Recently I installed an application HP SIP(Service Information Portal) on a Windows 2000 server.The application comes along with an installation of Tomcat 5.0.19. Already there was an Apache...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.