Can .jar get POST params? - java

Can .jar file recieve POST params? I know with command line arguments I can pass data, but as I realise, this data is sent as string:
java -jar mylibrary.jar somepostdata
I am asking this because I know main class in Java recieves String[] args.. Now, I want to pass POST object, not just plain string. Can it be done?

Based on your comment below you would require a Jetty Web Server. A Jetty Web Server is a JAR file. So basically you would expose an endpoint. Your application jQuery or whatever you decide to do will send to this JAR at the endpoint and port number.
I hope that makes sense.

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.

Converting documents via HTTP

With the documents4j-server running and listening at http://localhost:9998 is it possible to convert a document with a direct HTTP command?
Example:
http://localhost:9998?source=C:\Test.doc?target=C:\Test.pdf
More info:
I was a few steps ahead of myself...
I am using Apache FOP servlet running on Apache-Tomcat as a service to generate PDF documents from XML / XSLT.
Once running a PDF can be generated via http.
Example:
http://localhost:8080/fop/
?xml=C:/temp/Test.xml
&xslt=C:/temp/Test-Style-Sheet.xsl
&pdf=C:/temp/Test.pdf
I execute this command from my database application (which sets up the XML source and manages the resultant PDF).
I was looking for the ability to do something similar with documents4j for Word Doc to PDF conversion.
So I now realise that what I actually need is the ability to pass the name/type of the source document and the type of conversion (plus any other required parameters) to an external program / http port which can then package the request appropriately and then initiate the formal conversion process.
Would anyone be able to provide advice or a solution?
Not the way you attempt it, the conversion server would not be able to read from or write to your file system. No server can do that, this would be a severe security breach.
Instead, you can send the file via HTTP POST as the body of the message, that is what the client does. The answer then contains the converted file as the body of the response. You are using the request headers to specify your request:
For defining the input type, you are using the HTTP Content-Type header.
For defining the requested type, you are using the HTTP Accept header.
As an example, for converting a file from MS Word to PDF, you would for example use application/vnd.com.documents4j.any-msword as an input and application/pdf as the accept header's type.
You can also use the the client implementation that ships with documents4j and which is described under Converter client in the readme. This client sends exactly such a request.
Edit: You would need to set up your own minimal client application for that. A minimal application would look like this:
class MyApp {
public static void main(String[] args) {
IConverter converter = LocalConver.make();
converter
.convert(new File(args[0])).as(DocumentType.MS_WORD)
.to(new File(args[1])).as(DocumentType.PDF)
.execute();
converter.shutDown();
}
}
Given that you hand over the first and second command via the command line. Alternatively, you can connect to a server via the RemoteConverter. Of course, you can also use the built in command line tool for that which is however not available via HTTP. You could write a small app that delegates to that command line tool if this was your requirement.

Access Web service from java when wsdl file is known

I am trying to access a web service in the remote system by using java code. I take the WSDL URL from the XMethods registry and download the WSDL file from that location. I parse the WSDL file and display the list of operations and their Input and Output parameters and type. I will get the Input from the user according to the Information I got from the WSDL file. Now What I am need is I need to display the user the corresponding output from the Webservice. For this what is the easiest method to consume the Webservice. I dont have any Idea. Please anyone can help me??? Thanks in advance.
you can user axis2 jar framework to consume the webservice. Axis2 jar's generate the dependency files to consume the web service. Use this link to create client files.
http://javapapers.com/web-service/axis2-web-service-using-eclipse/

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.

Is there a way to get the raw SOAP request from a SOAP based Web Service in a Java application

I am working on an application, that will pass client input to a vendor using web services. As phase I of the project, the vendor provided us with the XSD's and WSDL information. I used apache CXF to build the client jar. Now the issue I am facing is that, as part of the requirement, I need to send them the SOAP Request in an encrypted(I have taken care of the encryption part) XML file, that they will manually process, and send me back the response in another XML file that I need to parse and retrieve the response object.
Is there anyway to use the client jar in a dummy mode or something, where it looks like we are calling the client, but all we are doing is getting the raw SOAP request to a file
I kind of a hit a dead end and I am not totally sure how to proceed here, any help or suggestions would be appreciated
You might try SoapUI, it's a free web service testing tool. I know you can view the raw data of your soap request and response with it. soapUI

Categories

Resources