IOException send pdf by Javamail via webservice - java

Guys I got a problem to send a PDF on java mail on webservice. When I try to run my class for test the email is send sucessful, but somehow when I try to send via webservice the same method can't find the File and shows IOException (The path is not found). So how shall I describe the file path on the method to run it on web service?
Project Build and code.

It look like you have use wrong path.
You should try use absolute path instead of relations path,
Use following code to debug:
String tHomeArquiovo = ...
System.out.println(new File(tHomeArquiovo).getAbsoluteFile());

Related

java - send a file to client by file URL without download on the server

In my web application I have a link which, when clicked, invokes an external web service to retrieve a download URL for a file.
I need to send back to client the file which is beyond this URL, instead of the download URL retrieved from the web service. If possible, I would also like to do it without having to download the file on my server beforehand.
I've found this question about a similar task, but which used PHP with the readfile() function.
Is there a similar way to do this in Java 8?
If you doesn't even want to handle that file you should answer the request with a redirect (eg HTTP 301 or 302). If you want to handle the file you should read the file in a byte buffer and send it to the client which would make the transfer slower.
Without seeing your implementation so far, this is my best suggest.

Web service client cannot be created error

I am making a currency converter using netbeans, using a wdsl/soap
http://currencyconverter.kowabunga.net/converter.asmx?op=GetConversionAmount
Whenever i try to retrieve the information i get the error shown on the picture above, does anyone know what the problem is?
As I am not using Netbeans so I cannt tell about the perticular issue.
But if you want to generate the client side code for webservice.
Just run the following commend
wsimport -keep wsdlUrl
for wsdl url deploy your application and open in browser the copy the url from browser.
this will generate all the source code for client java file as well as .class files.
wsimport commend has many other options check if you want more.

How to save/open files on server with GWT

I have a BIRT report that I've created in GWT and I'd like to save it to the server and then open it back up. I feel like hardcoding the url is the wrong route to go (ie C:/files/foo/foo.html) but I'm not having much luck figuring out another way of doing it. I tried using GWT.getModuleBaseForStaticFiles() but if i use that I get an unsatisfied link error in BIRT. What can I use to save/open a file, what is considered the best practice? Thanks.
edit: bad wording, the BIRT report is generated server-side. I'd like to be able to save it server side and then open it up in a new browser window (using window.open I'd imagine?). Nothing is uploaded from the client side.
If your BIRT report is a static file (Not generated during the runtime of your application) You can create a simple Servlet that read the file and copy the data to the OutputStream of the response. If it's generated at the runtime, the client will request it to the server, the server will generate it and return the URL location of the report. The client can open the report with that URL.
Example:
If your BIRT is located under foo/foo.bar you can map a servlet as /foo/*. After mapping it the user will request the url www.yourselver.com/foo/foo.bar The servlet at the doGet method can read the file and stream the content back to the client.

Java http server and web folder

does anyone know how to create HTTP server in Java, but set default folder for web and than load files from it? I want to use com.sun.net.httpserver class.
For example, I have folder named abc next to my java file. The java file runs HTTP server under port 8080. And if I open address http://123.123.123.123:8080/ I want to see list of files from folder abc. In folder abc are some files, eg. image.jpg. So I want to open in my browser address to image file, like http://123.123.123.123:8080/image.jpg. This way I can open all other files from folder abc (also subfolders, files in subfolders etc.).
Is it possible to create this HTTP server?
Would it be somehow possible to run PHP files in the folder?
Thank you very much for your answers.
Why not using embedded Jetty? I am pretty sure that with it you can accomplish what you are looking for.
If you want to execute PHP from within Jetty, refer to http://docs.codehaus.org/display/JETTY/Jetty+and+PHP
Once you have created your server object, you need to register some handlers for the path you want the user to use to fetch documents.
HttpServer server = HttpServer.create(new InetSocketAddress("localhost",8080));
HttpHandler myDocsHandler = new MyDocsHandler();
server.createContext("/abc", myDocsHandler);
There are no built in default handlers, so you will need to write the MyDocsHandler class that implements the HttpHandler interface to handle any requests coming into your server at http://localhost:8080/abc.
The handler requires a single handle method that takes an HttpExchange argument that gives access to the request data and the response stream. It is your responsibility at this point to do what needs doing. So if you wanted the actual files to be located on your hard driver at /usr/local/abc your handler would need to open the requested file using standard file io and stream it back to the user.

What is the equivalent of PHP's $_SERVER['DOCUMENT_ROOT'] in Java

I need to know the Java equivalent of PHP's $_SERVER['DOCUMENT_ROOT'].
I am writing a Java backend program that will take an uploaded image as a byte[] and save the image to the server where my Java program is running. Then I want to send the image url to the user (front-end) or as email; so that the user can click on the url I send to view the image.
In PHP, I use $_SERVER['DOCUMENT_ROOT'] plus the relative path of the file. How do I do that in Java?
I am not using servet. I am using Jersey to return the url. (If that's important)
I need the returned path to be "http://localhost:8080/mypics/pic1.jpg" when the server is localhost and "http://www.mysite.com/mypics/pic1.jpg" when running on a live server. The new File("./") code is not returning "http..."; netbeans cannot find the method ServletContext.getContextPath(), after importing
import javax.servlet.ServletContext;
You can use ServletContext.getContextPath() to get context path or use ServletContext.getRealPath(String path) to get real path for a given virtual path.
The simplest way if you not use servlet API is to create File object point to the ./:
System.out.println(new File("./").getAbsolutePath());
In this case you should see in console path to your application directory. This could be your $_SERVER['DOCUMENT_ROOT'] for this application.

Categories

Resources