sending http request over a secured connection java - java

I have .war on the server which contains servlets. When I send an HTTP request through the browser, I am able to connect and retrieve files. Now, I want to do this programmtically in Java. In order to connect, I am first sending a get request that contains the user name and the password. Now assuming that I will stay logged in, I am sending another get request with its parameters to get the file, but I am unable to retrieve the file. Is there any way to do this? Currently, I use HttpClient and HttpGet to connect and execute the get requests.
Eventually what I am trying to do is to have an application, deployed on a server call a servlet on the same server but under a .war (i.e. implemented as another application) and retrieve a file. I have tried to call the servlet directly but also I have been able to figure that out.

Related

Receiving a differnet HttpServletRequest from the same client?

I am currently trying Java Jersey 2.23.2 for my restful service
When both of the web client and tomcat web service runs on the same device, The session was handled perfectly.
However, when the an external client (another website) that runs on a different machine, there will always be new session introduced after an API call instead of sticking to just one session.
Is there anyway I could let the external client to call the webservice just like the local client does?
I can assume that your remote client does not care about JSESSIONID cookie. When session created, server sends HTTP header Set-Cookie with it.
Client must take it and then send it back with each subsequent requests.
All browsers do it automatically.
But as long as your client is another service it needs to care about it.

Implementing a client to download file over HTTPS using commons-httpclient

I'm trying to implement a client application over https using commons-httpclient.
I have implemented a servlet at the server end to send data to client as blocks (chunks of data). each block contains 4MB. now my problem is, If i download using http url, i.e like http://localhost:8080/DownloadServlet/post it works fine. If I use https, some times I'm receiving 500 error and download stops in the middle. Can some one tell me what might be the problem.
thanks.

Post message on a specific session ID

I have a situation here .. maybe someone can help me with this.
I'm trying to provide a service where clients can "analyze" a specific URL. So I use a web service in Tomcat to work with the clients. The user accesses the web service webpage, inputs a URL and presses analyze. I now have to receive the URL in the web service, send it to a process that is running on the same server as Tomcat ( I do this through a pipe right now ).
The process adds the URL's in a queue, starts consuming it and analyzes every URL.
After the processing is done, I want to post a message from this process to the same session ID that sent me that URL ( lets' say I send the session ID through the pipe, together with the URL ).The URL after analyze, has to get to the client that pressed Analyze in the end.
Will what I want be possible?
I tried to find a solution where I would use only pipe communication between the web service and the local process, but a lot of complications appear when we are taking about multiple users connecting on the same time.

Can we read cookies using core-java that has been written using .NET MVC code?

Can we read cookies using core-java, that has been written using .NET MVC code? I have not find any help how to read cookies using core java code?
More Background Details -
Actually we have a java desktop application and we are planning to launch that java desktop application using JWS and that is working absolutely fine.
The issue is -- we ask some user related information from user on web page and launch java desktop application using JWS. Now we would like to have that information provided by user on web page in our java application.
We have write that information into cookies and how can we read that information from java code ?
Yes, you can receive cookies that have been set by another application (as long as the path value in the cookie matches). Cookies are part of the HTTP protocol and it does not matter how thay were defined. The client sends them in future requests depending on the URL path.
To access cookies in Java, have a look at getCookies() in HttpServletRequest.
update
The cookies set by your web-application that launches the Java client will have been set in the context of the browser client. Cookies are added to a HTTP response and cached by the client receiving them.
In the case that you describe you cannot access the same server-session from the Java client without trickery.
The solution I would use is to generate a unique ID in the web-app that is passed as argument to the Java client which can in turn request the values needed from the other session using a fetch of a URL using the generated ID as parameter. (This in essence connects the two HTTP sessions as being part of the same user process.)
For instance you could use a HttpURLConnection and a URL like <web-app>/data?id=<ID> to fetch/download the values as XML from your web application.
Core-java? Then try java.net.*:
A cookie is just a header line with "Set-Cookie: " before the URL content.
http://www.hccp.org/java-net-cookie-how-to.html

Open PDF file on client's browser directly from Java Servlet Class

Hey Folks, So this is the rundown:
Essentially, what I want: PL/SQL Procedure call(using UTL_HTTP) --> Java Web Application, Servlet --> opens up a browser window and renders a PDF.
We use the package UTL_HTTP within our PL/SQL Procedure for this, as it has an option to send requests to external urls via the POST method. The only reason we use this package is to ensure our data is passed as POST parameters (apparently, there is no other way to open up external sites directly from PL/SQL procedures while passing parameters through the POST method). There are other means to provide urls directly and pass get parameters as part of the request url string, but this would expose sensitive parameters like username, password, serial id etc.
This http request from the PL/SQL procedure is intercepted by a servlet in our Java Web Application. Our Java Web Application is a Document Management Application and handles all the document management logic.
We managed to reach the servlet and also get a hold of the PDF and put it in the response.
Here's the catch: Since the originating application was a PL/SQL Procedure that sends the HTTP request directly to our Web Application, at no point is a browser window opened. So in our Java servlet class, we get hold of the PDF and write it onto the response. But we need to spawn a browser window to render the pdf. I found this neat site that provides Java Code to open up a browser window directly from a java class. But the problem is that the browser window opens up at the server directly and not on the client.This browser window ought to open up in our client machine from where the http request was issued not at the server.
Any suggestions?
Cheers
If you are using an PL/SQL Web aplication (using APEX or webToolkit) you can send to the browser the blob that you get from the UTL_HTTP call to the servlet

Categories