How do I send HTTP request to a server via a proxy server in JDK 1.4?
JDK 1.5 's URL class provides an overloaded version of openConnection() which accepts an object of type Proxy using which we can establish connection with a remote server via a proxy server, but JDK 1.4 doesn't provide any such overloaded version. How do I do that in JDK 1.4? Even if I had a class that can create HTTP packets for me, then I could have established Socket connection with the proxy server and sent the HTTP packet to it. Is there a way to do that also?
There are some system properties, which can be set with System.setProperty [http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html]
Similar Messages
-
I am using ActionScript 2.0 for my app development. I have checked XML and LoadVars class. These classes by default send/receive data either in XML or name/value pair format. I want to send data in JSON format and receive the response in JSON format. How can I achieve this behavior using AS2.0. I have noticed that AS3.0 has the capabilities to do so. My client platform doesn't support AS3.0. Can anybody suggest a way to achieve this?
Thanks in Advance.Atlast I am able to find the solution for this problem. In the end solutioin is very simple.
Following steps will help in sending request in JSON format.
1. extend LoadVars class
2. override toString method. (It should return JSON format )
3. Use subclass to send the request. -
How 2 pass a request from a broswer to remote server via a proxy server
hi my program is on a proxy server it will be lisenting in port 9876
i have configured in a way that all browsers request pass thro this proxy server
so when user request for www.yahoo.com in the browser the
resquest is passed 2 this proxy server. so i got the host name and created a socket.
i read all the request that has come from the browser such as "GET www.yahoo.com HTTP/1.1 ,,"
I got the outputstream for the remote socket and i passed all these request to the remote host.. but i could nt get any response frm server can any one help me out?
===
import java.io.*;
import java.net.*;
class Proxyserver
ServerSocket ser;
Socket myclient;
BufferedReader br;
String cf1="\r\n",cf2="\r\n\n",lf="\n";
OutputStream o_remote;
public Proxyserver()
try
ser=new ServerSocket(9876);
myclient=ser.accept();
// read inital requst from browser
br=new BufferedReader(new InputStreamReader(myclient.getInputStream()));
String req=br.readLine();
String temp=req;
int val=temp.indexOf((int)'/',11);
String host=req.substring(11,val);
//connect 2 host
Socket remote=new Socket(host,80);
System.out.println(remote.toString());
o_remote=remote.getOutputStream();
while(req!=null)
System.out.println(req);
o_remote.write(req.getBytes(),0, req.length());
o_remote.write(cf2.getBytes());
o_remote.flush();
req=br.readLine();
o_remote.write(lf.getBytes());
o_remote.write(lf.getBytes());
o_remote.flush();
// wait for response from remote server
InputStream in=remote.getInputStream();
int response=in.read();
while(response!=-1)
System.out.println((char)response);
response=in.read();
//close all sockets
remote.close();
myclient.close();
ser.close();
}catch(Exception e){}
public static void main(String a[])
new Proxyserver();
===
op i got all the req from the broswer and wrote 2 op stream of remote server but i could nt get the response
==
output"
Socket[addr=javaworld.com/130.94.4.230,port=80,localport=3225]
GET http://javaworld.com/ HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: en-us
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)
Host: javaworld.com
Proxy-Connection: Keep-AliveHi
Just look for JspSmartUpload classes ..
this will help u
U can use
<input type=file name=f >
thanks
regds -
Problem in sending HTTP request to the server.
Hi,
i dveloped an ant script for sar deployment.
i deployed a sar to my local soa server with ant script. it got deployed succesfully..
but when i try to deploy to a remote server, getting the below error..
"Problem in sending HTTP request to the server. Please make sure the server is up and/or check standard HTTP response code for 404"
but the server is up and runnig and i am able to ping it from my machine and also access the console...
below is my script
build.properties
wn.bea.home=C:/Oracle/Middleware
all.needed.jars.path=D:/SourceCode/neededJAR
oracle.soa.home=C:/Oracle/Middleware/Oracle_SOA1
java.passed.home=C:/Oracle/Middleware/jdk160_24
#Deployment environment
deployment.plan.environment=DEV
#Deploy Action
deployAction =redeploy
#credentials
user=weblogic
password=welcome1
#For Composite deployment
serverURL=http://10.177.154.6:7001
forceDefault=true
server=10.177.154.6
port=7001
sarLocation=D:/SourceCode/JAR
build.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<project name="soaDeployAll" default="deployAll">
<echo>basedir ${basedir}</echo>
<property environment="env"/>
<echo>current folder ${basedir}</echo>
<property file="${basedir}/build.properties"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${all.needed.jars.path}/ant-contrib.jar"/>
</classpath>
</taskdef>
<target name="init">
<tstamp>
<format property="timestamp" pattern="yyyy-MM-dd_HH-mm-ss"/>
</tstamp>
<property name="build.log.dir" location="${basedir}/buildlogs"/>
<mkdir dir="${build.log.dir}"/> <property name="build.log.filename" value="build_${timestamp}.log"/>
<record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
<echo message="Build logged to ${build.log.filename}"/>
</target>
<target name="deployAll" depends="init">
<echo>Deploy for environment ${deployment.plan.environment}</echo>
<antcall target="deployAllComposites"/>
</target>
<!-- Following Actions are performed for Composite files in Managed Server - Deploy,Redeploy -->
<target name="deployAllComposites" depends="init">
<foreach target="deployComposites" param="Files">
<fileset dir="${sarLocation}" casesensitive="no" includes="*.jar"/>
</foreach>
</target>
<target name="deployComposites" depends="init">
<basename file="${Files}" property="basename"/>
<echo>Deploy Project ${basename} for environment ${deployment.plan.environment}</echo>
<if>
<equals arg1="${deployAction}" arg2="deploy" />
<then>
<echo message="Deploying composites in Managed server........." />
<ant antfile="${oracle.soa.home}/bin/ant-sca-deploy.xml" inheritAll="true" target="deploy">
<property name="serverURL" value="${serverURL}"/>
<property name="user" value="${user}"/>
<property name="password" value="${password}"/>
<property name="overwrite" value="false"/>
<property name="forceDefault" value="${forceDefault}"/>
<property name="sarLocation" value="${sarLocation}/${basename}"/>
</ant>
</then>
<else>
<echo message="ReDeploying composites in Managed server........." />
<ant antfile="${oracle.soa.home}/bin/ant-sca-deploy.xml" inheritAll="true" target="deploy">
<property name="serverURL" value="${serverURL}"/>
<property name="user" value="${user}"/>
<property name="password" value="${password}"/>
<property name="overwrite" value="true"/>
<property name="forceDefault" value="${forceDefault}"/>
<property name="sarLocation" value="${sarLocation}/${basename}"/>
</ant>
</else>
</if>
</target>
</project>
please help....Hi,
Give the serverURL as http://<host>:<managed.server.port>/soa-infra/deployer and try.
e.g . http://10.177.154.6:8001/soa-infra/deployer
Regards,
Neeraj Sehgal -
How to transfer the http request from applet to servlet/jsp
I use the JTree component to create a navigation of a website,but i don't
know how to connect the tree's nodes with the jsp/servlet.
I mean how to transfer the http request from the applet to a jsp.
I use the "<frameset>" mark which will divide the web browse into 2 blocks.
The left side is Applet,and the right side is the linked jsp page.
what I say is as the weblogic console layout.
who can help me!!!
Thank You!I use the JTree component to create a navigation of a website,but i don't
know how to connect the tree's nodes with the jsp/servlet.
I mean how to transfer the http request from the applet to a jsp.
I use the "<frameset>" mark which will divide the web browse into 2 blocks.
The left side is Applet,and the right side is the linked jsp page.
what I say is as the weblogic console layout.
who can help me!!!
Thank You! -
ExecutorService creating tasks to send HTTP requests - time out
In my java application, I have introduced ExecutorService to create tasks. The tasks consist of sending HTTP requests to an application server, to process transactions. The ExecutorService will process about 1000 requests.
The executor process the transactions and terminates OK, but some of the transactions timed out (before introducing ExecutorService, I was just sending one transaction at time, all the transactions were processed OK; but, it was taking a long time to process).
See the code below.
private ExecutorService threadExecutor;
threadExecutor = Executors.newFixedThreadPool(30);
threadExecutor.execute(transaction);
try
//Shutting down the ThreadExecutor
threadExecutor.shutdown();
threadExecutor.awaitTermination(30, TimeUnit.SECONDS);
threadExecutor.shutdownNow();
catch (InterruptedException e)
System.out.println("ERROR - cannot shutdown the ThreadExecutor - exception is: " + e);
Is this the best way to implement this use case?
Thank you.From the above code, it seems like you are starting only a single transaction in a thread pool. Or does the transaction object you pass to the threadExecutor spawn more tasks for the executor?
If you are indeed still making all HTTP requests from the single transaction object, then yes, it will 'time-out' after 30 seconds, since the ExecutorService was instructed to stop its threads after that period of time.
Your description of the use case is actually a good example of the usage of an ExecutorService, since it is faster to do 1000 HTTP requests in parallel than it is to do them sequentially.
Consider this:
ExecutorService threadExecutor = Executors.newFixedThreadPool(30);
for (int i = 0; i < 1000; i++)
threadExecutor.execute(new Transaction());
try
threadExecutor.shutdown();
threadExecutor.awaitTermination(30, TimeUnit.SECONDS);
threadExecutor.shutdownNow();
catch (InterruptedException e)
// Ignore
}This will spawn 1000 transactions that will execute in parallel, with max. 30 running at any single point in time. Any transactions still not executed after 30 seconds will be terminated.
Hope this helps.
--JH
Edited by: Kramor_dude on Nov 5, 2009 6:55 AM -
HTTP connection from OSB web service to external system via a Proxy Server
Dear experts,
May I know has anyone tried to use HTTP protocol to send a request from OSB web service to external system via a proxy server? Heard that we need to establish some sort of tunnel (socket) to talk to Proxy Server. Can you please any have sample code or configuration steps to share?
Thank you very much!!http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/consolehelp/global_resources.html#wp1137294
Adding Proxy Servers
Use the Summary of Proxy Servers page to add and configure Proxy Server resources and make them available in Oracle Service Bus as a system resource. You must be in an active session to configure or reconfigure Proxy Server resources.
1. If you have not already done so, click Create to create a new session or click Edit to enter an existing session. See Using the Change Center.
2. Select System Administration > Proxy Servers.
3. Click Add.
4. In the Name field, enter a name for the Proxy Server resource. This is a required field.
5. In the Description field, enter a short description for the Proxy Server resource.
6. In the Host-Port Parameters section, enter the following information:
1. In the Server Host field, enter the host name or IP address of the Proxy Server. This is a required field.
The Server Host name for the Oracle Service Bus proxy server must be identical to the server host name of the actual proxy server.
2. In the Clear Text Port field, enter the Proxy Server clear-text port number.
3. In the SSL Port field, enter the Proxy Server SSL port number. You must enter either a clear text or SSL port number.
4. Click Add.
You can configure multiple Proxy Servers for each Proxy Server resource. This enables Oracle Service Bus to perform load balancing and offer fault tolerance features for the Proxy Server resource.
7. If the Proxy Server performs proxy authentication, enter a user name in the User Name field, and the associated password in the Password and Confirm Password fields.
These fields are optional, and required only if the Proxy Server is secured.
8. Click Save to create and save the Proxy Server resource in the current session.
9. To end the session and deploy the configuration to the run time, click Activate under Change Center. -
How do you stop my iphone keep asking for my works proxy server name and password
how do you stop my iphone keep asking for my works proxy server name and password
Having been in IT for close to 30 years what they actually thought was, "whether you can connect your phone to our network isn't out problem, please go away".
They don't want to troubleshoot it. And, honestly, if it's your personal phone, they shouldn't have to. it's not their problem unless their boss says it is. -
Guys,
i need to implement a program that will send request to the server and recieve the http response from the server.
Some of information will attached in the http response from the server.
My application must able to catch out this info in the http response header.
I had use the httpClient jar to send the request and i able to recieve http response 200 or 400 only from the server.
Can any one of you give me some idea on how to retrieve the attached info in the response header?
Thanks in advance.See http://jakarta.apache.org/commons/httpclient/apidocs/index.html
package org.apache.commons.httpclient.methods methods: GetMethod PostMethod : getResponseHeaderGroup, getResponseHeaders, getResponseHeaders... -
Sending HTTP request to an unknown URL
How to set timeout and continue the flow in plsql when a http request is sent to an unknown ip(fake ip). I am sending request using utl_http package. i tried setting timeout using utl_http.set_transfer_timeout but no luck.I would like to know some suggestions on this. im really bugged on this for the past 2 weeks. I posted this twice. But there was no satisfactory answers.
please help.Here's what i tried using exception handlers. but it does not work
IF (cou > 0) THEN
DECLARE
l_url VARCHAR2(256) ;
l_http_request UTL_HTTP.req;
l_http_response UTL_HTTP.resp;
l_url := hostname;
UTL_HTTP.set_transfer_timeout(5);
l_http_request := UTL_HTTP.begin_request(l_url);
l_http_response := UTL_HTTP.get_response(l_http_request);
UTL_HTTP.end_response(l_http_response);
CASE WHEN l_http_response.status_code = 200 THEN
proc('Success')
WHEN l_http_response.status_code in(401,403,500,503) THEN
proc('Error')
END CASE;
EXCEPTION WHEN OTHERS THEN
Result := 'continue';
END;
END IF; -
How can I send a request over a Proxy Server
When I try to send a request to www.microsoft.com, there is a HOST_NOT_Found Exception. Because I'm using a Proxy Server, where I have to fill in my Username + Password...
How to do??
Thx for your helpSearch is your friend. Check out this thread:
http://forum.java.sun.com/thread.jsp?forum=31&thread=324894
Source code and all...
Good Luck!
Grant -
How do you redirect HTTP requests to HTTPS?
Update to my question:
My original question didn't include all of the complexity of what I'm trying to do.
I have a virtual server with two listening ports, 80 and 443. I have a certificate installed for port 443 and that works fine when I specifically type in https://myserver
I also have a reverse proxy setup for a URI- /myapp -> remoteserver.
I'd like to configure my webserver to do a redirect from /myapp to the URL https:/myserver/myapp
and then have the reverse proxy kick and send me over to my remote server.
Everything works fine if I browse to https://myserver/myapp. I just want for requests from http://myserver/myapp to be turned into https://myserver/myapp before the reverse proxy takes effect.
Any ideas?
Thanks-
Edited by: bisbell on Sep 13, 2010 12:16 PMIt would go into whichever obj.conf file is specified for this virtual server (probably <server>-obj.conf, but double-check your server.xml to be certain).
I tend to process redirects early in the obj.conf. I usually try to have them processed before the other NameTrans statements. Here's how I've done it with other kinds of conditionals:
<Object name=default>
<If $urlhost = "www.foo.baz.com">
NameTrans fn="redirect" from="/" url-prefix="http://foo.baz.com/"
</If>In my case someone had created published a link to my server with a FQDN that was incorrect. Since they had done it in printed material a fix for them was not trivial. To address the problem I created a DNS entry that matched their typo, and created the redirect here to bounce from the bad FQDN to the proper FQDN. You're doing basically the same thing, except you want to redirect accesses to a particular URI that are not SSL enable to the same URL with SSL.
Please note that I haven't checked any of the syntax I gave you in the prior post. I already see one typo (~= should be =~). The variables being evaluated should be checked for correctness too (e.g. security!="true" might in fact be something like "not defined $security").
Check the docs. :) -
How to pass a HTTP request from a simple java class
Is it possible to pass an HTTP request from a simple java class.if yes how?
Is it possible to pass an HTTP request from a simple
java class.if yes how?If you're talking about creating a HttpRequest object and passing it to a servlet, that would be a red flag to me that your design is flawed. You shouldn't have to do that - the application server (Tomcat, Weblogic, etc) should be the only thing that has to worry about creating that kind of object and passing it to you. -
File.upload on Air SDK for iOS devices failed to send http request to server.
I am trying to use ActionScript's File.upload to upload a file on Air SDK for iOS8 environment, but the File.upload does not work properly. No handler about the file upload is executed after File.upload is invoked, and no exception is caught. When I check the network traffic of the server side, I found that no http request even hit the server after File.upload is executed. The code snippet here is very simple.
private var file:File;
private var dir:File;
//This method is executed to create a file and upload it when the Upload Button is pressed.
protected function OnUploadButtonPressed(event:MouseEvent):void{
var str:String = 'This is test';
var imageBytes:ByteArray = new ByteArray();
for ( var i:int = 0; i < str.length; i++ ) {
imageBytes.writeByte( str.charCodeAt(i) );
try{
dir = File.applicationStorageDirectory
var now:Date = new Date();
var filename:String = "test" + now.seconds + now.milliseconds + ".txt";
file = dir.resolvePath( filename );
var stream:FileStream = new FileStream();
stream.open( file, FileMode.WRITE );
stream.writeBytes( imageBytes );
stream.close();
file.addEventListener( Event.COMPLETE, uploadComplete );
file.addEventListener( IOErrorEvent.IO_ERROR, ioError );
file.addEventListener( SecurityErrorEvent.SECURITY_ERROR, securityError );
file.addEventListener(ErrorEvent.ERROR, someError);
file.addEventListener(ProgressEvent.PROGRESS, onProgress);
file.upload( new URLRequest("http://10.60.99.31/MyPath/fileUploadTest.do"));//This line does not work. No handler is executed. No http request hit the server side.
} catch( e:Error ) {
trace( e );
//Complete Handler
private function uploadComplete( event:Event ):void
trace( "Upload successful." );
//IOError handler
private function ioError( error:IOErrorEvent ):void
trace( "Upload failed: " + error.text );
//SecurityError handler
private function securityError(error:SecurityErrorEvent):void{
trace( "Security error:" + error.text );
//Other handler
private function someError(error:ErrorEvent):void{
trace("some error" + error.text);
//Progress handler
private function onProgress(event:ProgressEvent):void{
trace("progressHandler");
When executed on Air Simulator, it works fine as expected, and the file is successfully uploaded to the server. But When executed on iOS devices(in my case, iPad), as I explain early, no handler about the file upload is executed, and no the http request even hit the server. So I think the problem may be in the client side. It seems that the Air SDK for iOS just failed to send the http request for some reason.
To make my problem more clear, I list my environment below:
Development Environment: Windows7 (64bit) / Mac os 10.9.4 (Tested on OS platforms.)
IDE: Flash Builder 4.7
Air SDK: 3.8 / 16.0.0 (After I updated to the lastest Air SDK 16.0.0 , the problem still exists.)
Application Server: Tomcat7 + Spring
Target OS: iOS 8
I have been struggling for this for days. So I really appreciate it if anyone has any idea about this.
Thanks in advance.Hi bluewindice ,
As you have quoted ( ActionScript's File.upload does not work on Air SDK for iOS devices ) , this issue has been replicated at our end, and our team will be working on it.
Thanks,
Tushar -
How to make an HTTP request via SSL
Hi,
I´m using an instance of the class CL_HTTP_CLIENT to make an HTTP request to a https server. as long as it requires an SSL authentication, it returns an ICM_HTTP_SSL_ERROR error message.
How do I tell my program to ask for user´s certificate, and use it in the http request?
I´m supossed to have hundreds of users online running this application (it´s over SRM 5.0). How can I reach this?
Thanks you very much.
Federico.Hello Frederico,
>1. By creating a new client, you mean go to "Environment->SSL Client Identitites" in STRUST, right? >Can I use a previously existing one?
I meant to create a new client SSL PSE. By default in a new Netweaver abap system, you have 3 of them : ANONYM, DFAULT and WSSE.
If you need more of them, you can create them with the menu "Go to-->Environment->SSL Client Identitites".
>2. I need this PSE client to have several 'identitites', I mean, to include several certificates from all my >users. Is it possible? If it´s not; how should I do so?
It seems that you want a different certificate per user. These client certificates in STRUST are designes to identify a SAP abap system, not human users. If you have 1000 users, you will not create 1000 certificates in STRUST !
Usually, you use only 2 entries here, one for anonymous HTTPS access and one authenticated HTTPS access. It is unusual to have several different identities for the same abap server. But it might be possible : for exemple, one identity on the intranet and an other one on the Internet.
>3. When I had my new PSE client, and my HTTP RFC destination of type 'G' configured to use that >PSE client, and when in abap I instantiate my http client (using CREATE_BY_DESTINATION method, >from CL_HTTP_CLIENT class): How does SAP knows which certificate to use? Because there will be >several users (hundreds) running this code to retrieve their specific data from a third party server.
>How does SAP knows whom certificate must use?
The certificate used will be the one defined in the HTTP destination.
You still seem to make the confusion between server client certificates and users client certificates.
a users client certificate is stored in the user's PC (or smartcard) and is used for HTTPS connections from the user's browser to the SSL server, not for an HTTPS connection from the ABAP server to another server.
Regards,
Olivier
Maybe you are looking for
-
Please, please PLEASE help. I don't want to loose my pics of my sons birth and the newest update is directing me to restore my phone. I can't get out of the "conect to itunes screen" Can I still save my pics???
-
Hi I need to throw a popup in Opportunity while saving with the text '........You cannot save' .It should have a 'OK' button. This way i should stop user from saving the application depends on a condition. I'm planning to use 'ORDER_SAVE' BADI to sh
-
I have a fillable PDF that I created with Formscentral, now I want my employees to be able to distribute it with their own emails. When they try to upload the form, it says it can't because it was "already distributed by forms central." Any ideas?
-
can i install i cloud on my pc? Can i receive remeinder?
-
Problem with printing (Epson Stylus Pro 4800)
All of a sudden, my black and white photos are printing in sepia tone. I have Photoshop CS3 and an Epson Sylus Pro 4800. Interestingly, in the printer profile drop-down menu, it used to say "Pro 4800 PLPP". Now it defaults to "Working RGB - sRGB I