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.
Related
This is going to be running on a server which will then send the xml request to another server (over which I have no control). I can't afford to write an xml to the hard drive for every request. So ideally I'd like to create an xml without creating the file.
This shows how to send an xml file (not an object) over https: http://pic.dhe.ibm.com/infocenter/iisinfsv/v9r1/index.jsp?topic=%2Fcom.ibm.swg.im.iis.ia.restapi.doc%2Ftopics%2Fr_restapi_sending_https_java.html I've got that part working, problem is even after changing the content type to xml I think it was simply sending the content of the xml as plain text which seems very inelegant.
I'd rather avoid third party jars as much as possible but I do have access to the apache.axiom and axis 2 library.
So long story short: how do I make an xml object and then send it via HTTPS to a third party web-service that is not using SOAP or REST.
The HTTP request is generally correct to send XML as text, with the correct content type.
If you have a DOM object of some sort, you would just serialize it to XML, as text, either on disk or in a buffer or a string, and then send that, as per the link, to the other server. The other server will parse the XML string and get whatever form of object it wants.
I am new to Jmeter. Currently i have tested web service calls in Jmeter. I have sent a request to server through web service calls. My input is xml file and its encrypted form. So i given encrypted string in PostBody.
My problem is I'm not able to do the encryption process in Jmeter.
So i have decided to connect jmeter to my java class and send to server.
Jmeter--->Java class--->server.
I have used Jmeter 2.8
Is there any possible to connect Jmeter to java class?
I am not sure to understand but if what you want to do is the following:
Encrypt some XML
Pass it as Raw Post Body to the HTTP Sampler which will call your webservice
Then the answer to do that is the following:
Add groovy-all.jar in JMETER_HOME/lib folder
Use a JSR223 Pre Processor on your HTTP sampler, and put the following Groovy code:
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.protocol.http.util.HTTPArgument;
HTTPSamplerBase httpSamplerBase = (HTTPSamplerBase) sampler;
HTTPArgument argument =
httpSamplerBase.getArguments().getArgument(0);
String valueToEncrypt = argument.getValue();
// Do you encryption here, in this example I put ENC for testing
valueToEncrypt = "ENC"+valueToEncrypt;
httpSamplerBase.getArguments().clear();
httpSamplerBase.addNonEncodedArgument("", valueToEncrypt, "");
In the HTTP Sampler, put your original XML to be encrypted in Raw Post Body text area
Plan will have following structure (HTTP mirror server is just for my test):
Note: I use current JMeter nightly build so I have Script Compilation caching part which is not yet available and will be in 2.9. Instead put your script in an external file and reference it in File Name field.
jMeter can talk to a lot of things (see this list at Apache). One is JMS and that could probably be used to connect to your java server. Or http (which it's normally used for). It all depends on what your java class is able to respond to.
You can also make a jar of your java class, and append it to your test plan. You can then reference them from the JSR223 preprocessor with the groovy engine.
I have the following scenario:
JSP -> Servlet -> ServiceAPI -> Service Servlet
I enter some cyrilic symbols in the JSP page, which is the start of the scenario. On the next step, the Servlet, I read the data from the JSP in UTF-8. So for, so good. Everything is OK.
Then I pass the data to a ServiceAPI, which sends it to a Service Servlet. Here comes the problem. The data in the Service Servlet is read as '??????'. So, I guess the problem is in the Service API which does not send the data correctly. ServiceAPI implementation uses Apache Http Client to send the data to the Service Servlet.
As I read in Apache Http Client documentation (http://hc.apache.org/httpclient-3.x/preference-api.html#HTTP_method_parameters) there is a way to set a character encoding in the request. But I am not able to apply this, becuase of a the following error: "Access restriction: The method setParameter(String, Object) from the type HttpParams is not accessible due to restriction on required library ...". So I am kind of stuck. Do you have any idea if the problem is really in Apache Http Client and I how can I fix it.
Thanks in advance.
To correctly implement Character Encoding in web apps consists of 4 steps
1.First you have to configure your web server.
2.Then you have to force your web app to use UTF-8 encoding for all requests/responses.
3.Third you have to use JSP page encoding.
4.And last you must use HMTL-meta tags.
In your case the problem lies most probably on step 2 IMO
Here is the perfect article for you How to get UTF-8 working in Java webapps? that describes how to do all these extensively
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
i want to invoke a web service based on the url and method name,when given the input parament in xml format ,i need to invoke the web service ,but i can't generate the client stub using tools like wsdl2java because the url and method name are given dynamically so these class aren't compiled.
for example,http://localhost:9090:/hello?wsdl there have a method
string sayhello(String []names); the input param likes <arg0>john</arg0> <arg0>lucy</arg0>
it seems that i need to generate soap request in code so is there any library can help me do this?
thank you for giving any recommendation!
That's possible and yes, you will need to generate the SOAP request yourself and also parse the reply yourself.
Some links to help with this including source code etc.:
SoapUI (complete source code of a generic SOAP client including a nice UI)
http://anshu-manymoods.blogspot.com/2009/10/how-to-simple-generic-soap-test-client.html
http://www.java-tips.org/other-api-tips/httpclient/how-to-send-an-xml-document-to-a-remote-web-server-using-http-5.html
http://biomoby.open-bio.org/CVS_CONTENT/moby-live/Java/docs/soapServlet.html
http://www.soapuser.com/ngx_22jul01.html
IF JavaScript is an option you can check this out...
There's SAAJ but it's pretty verbose.
If you can use Spring, Spring-WS has a number of client options.
You can always just build up the XML by hand, too (and parse the returned XML).