Glassfish request compression - java

We have a legacy app that uses Java Web Services (JAX-WS) and runs on Glassfish 4.1.1. We want to implement compression of both the response and request. (We know that compressed requests can be a security risk but we are willing to accept this because the clients are all internal.) Turning on the GF setting for compression only compresses the response. If I send a compressed request body I get an error that indicates the SOAP message contained an invalid character, which tells me that GF did not decompress the request body.
Since GF won't automatically decompress the request I have been trying to modify the legacy app itself to do the decompression. I have tried the following:
A SOAP message handler. This does not work because the handler is invoked too late; at that point the unmarshalling of the SOAP message has already failed, because the unmarshaller received binary data.
A servlet filter. I tried setting up one that was invoked on any URL, but it never trips for the web service calls. I am not too familiar with the plumbing here, but it does not appear that the web service is implemented as a servlet.
My next option is to try setting up a proxy server that takes the raw request, unzips it, and forwards it to the web service.
Before I go down that path, does anyone have a simpler recommendations? Is what I'm try to do even possible? Much thanks in advance!

Related

A Warning Error of Response with BEPL SOAP Connection with SAAJ

I am trying to consume IBM BPEL web service, which is published on a live server and consumer using core java, working fine but the code have a warning message:
Dec 10, 2013 10:18:31 AM
com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
WARNING: SAAJ0014: Invalid reply message. Content length of reply was
zero.
NOTE: As designed this web service does not reply anything (response is empty). How can I disable calling party SAAJ client not to expecting a reply from the web service response?
I suppose that BPEL has nothing to do with the web service part. From your message I understand that when you call the web service from your client, the response is empty. Therefore, the probable cause could be in the following points:
The specific web service function gets nothing from the business logic layer to return.
You have to debug using breakpoints to find if this is true.
The web service function gets something from the business logic layer but it returns nothing due to an error in the specific function. You have to debug using breakpoints to find if this is true. Maybe the flow control of the function has a bug. Or maybe a data serialization exception throws and gets lost.
The web service endpoint is not configured properly. Double check the web service endpoint configuration. IP, port, credentials, authorization. Perhaps the web service is configured to return nothing when an anonymous user is calling it.
The client calls another endpoint. Double check that the client executes the correct request. Try using another client (eg SOAP UI) to see if it gets the same response. If the response is not the same, then the problem is on the client side.
You have the setup and the code, so you have to find out what is going wrong.
Hope I helped!

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

Getting post data from request

I'm writing a server side app in Java using the HttpCore library.
I have an HttpRequest and I'm trying to get the postdata sent from a form. The problem is- when I use request.getEntity() it returns a null object, even though when I look through HTTPFox on what kind of request I'm sending the post data is clearly there.
What am I doing wrong?
There seems to be some confusion. You are sending requests from a browser to the server. The server is likely using the servlet API. There you handle requests using the doPost(..) method of an HttpServlet. You have an HttpServletRequest from which you can get the parameters - request.getParameter("paramName")
HttpCore on the other hand is used to make requests, not to handle requests. It is used as an http client (in the role of the browser).

Call an external web service from a servlet

I'm developing a servlet that gets a name of a web service and could be forward the request to an external web service, for example: http://www.webservice.com/...
I have build a response wrapper that intercept response output but I can't forward request to an external web service, it works only if I redirect the request to a servlet that is on same server.
Example:
request.getRequestDispatcher("aMyServlet").forward(request, response) // WORKS
request.getRequestDispatcher("http://www.webservice.com/...").forward(request, response)
Doesn't because Tomcat searches http://www.webservice.com/... on the server as a local resource.
How can I do external request?
Thanks
forward method that you are using is used for communicating between server resources, (eg: servlet to servlet as you have found out) If you want to redirect to another location, you can use the HttpServletResponse's sendRedirect method.
Better option is to
Perform your own HTTP request and stream the results back to the
browser. This sounds harder than it is. Basically you create a
java.net.HttpURLConnection with the URL of the web site you want to
"redirect" to. This can actually contain the query parameters (as long as
they're not too large) since it will never be sent to the user's browser
either and will not appear in the browser URL bar. Open the connection, get
the content and write it to the Servlet's OutputStream.
To make any request to an outside service, you'll have to explicitly make a new HTTP request and handle its response. Take a look at the HttpUrlConnection class.
You don't mention what kind of service you want to invoke, but either way, your servlet is functioning as a service client, so you should be looking at service client technologies.
For invoking REST style services, java.net.URL or Apache Commons HttpClient can be used to send a request for a URL and fetch the reponse.
For invoking SOAP services, you can use Apache Axis, or Java WSIT.

Google protocol buffers and servlets

I am wondering how I can use google protocol buffers to accept a request and send a response back to a client? I am thinking about writing a servlet which will take a request.
Is the following trail of thought the correct way to implement this:
1. Have a .proto file which is the message definition for the incoming request.
2. Write a servlet which accepts this request, does various tasks like querying database
and then sends a response. Will this response require a separate .proto message definition with all the fields that make up the response?
3. Will the client just invoke the doGet() method of my servlet and pass the request, it should then return a response as a protobuff object?
Any suggestion or idea will be very much appreciated.
Typically you'd want a request message and a response message, yes. You'd also probably want a method name to describe the action - that's certainly how the built-in PB services work.
The client wouldn't invoke doGet() - it would make a request (probably a POST rather than a GET) and your servlet would receive it.
Now, ideally you could have a general "ProtocolBufferServlet" which could service the requests by handing them off to services implementing the appropriate interfaces.
I suggest you look at the documentation for Protocol Buffer services and the Java services generated code for more information. You could implement an RpcChannel which worked over servlets, or get the client to make the HTTP post directly. You'd probably use dependency injection of some kind at the server side to tell the servlet what was implementing the service.
HI,
I have this up and running. I ended up posting a http request as a post to my servlet. I was able to take the request protocol buffer, read the request, do some processing and then send back a response. It was actually really simple once I got it working. We used the 1 .proto file to define the request and response message structure.

Categories

Resources