I need to catch all SOAP request messages. The purpose of inspecting SOAP request messages is reading specific value (such as IP adress).
I read this tutorial
http://www.mkyong.com/webservices/jax-ws/jax-ws-soap-handler-in-server-side/
But as far as I can understand, when I need to add handler on my project,
an annotation must be added like
#HandlerChain(file="handler-chain.xml")
And also handler-chain.xml must be implemented.
--
So, I'm going to implement a library to get all soap request IP adress and log them all. But if I use soap handler, I have to make some configuration on project that I added my library.
My purpose is creating Plug and Play library. If I add my library into a project, it must be start reading Ip adress from request message without making as above.
So, is it possible? How can I do it?
No it is not possible. Think about this logically. If your service does not make any call, does not create any objects (i.e. does not reference it the library in any way) then no code from that library will be run and therefore it will not be able to do anything. Using the message handler is the most minimalistic and least intrusive way I have found (and it is the way I do it) do handle such problem.
Related
I've been attempting to create a port of an existing JAX-WS Web Service in Spring, using Spring WebService (following their guide loosely at https://spring.io/guides/gs/producing-web-service/).
I've got an endpoint working, using both the XSD the existing application (with JAX-WS) uses, and by generating a new set with SoapUI.
For some reason, the Web Service seems to be publishing with the Type of 'Notification', rather than 'Request-Response' like the original, existing methods on the pre-existing JAX-WS endpoint. The Spring WS also has an 'Output' with a Response-suffixed class stated, where the JAX-WS one does not. This is visually different in SoapUI with the Spring wsdl having a red 'left arrow' next to each method, instead of the contraflow arrows.
I think this is manifesting itself as an issue I'm seeing when I call the one endpoint I have set up - an error is logged stating 'No endpoint mapping found for [SaajSoapMessage .... myEndpointMethodResponse" (e.g. the response object from the endpoint method, not the endpoint method itself).
As mentioned, I feel like the 'Type' on the methods is the smoking gun, but I can't see what is causing it. I have looked up the issue but can't find anything common?
Update The following helped with the request-response (Invalid wsdl generated by spring-ws when the request element doesn't end with 'Request'), but I'm now getting a response back in SOAPUI of 'No adapter for endpoint' referencing my Response class. The PayloadRoot and ResponsePayload match the wsdl objects exactly.
OK, as the only 'help' on here was a close vote (thanks, very helpful), I've managed this myself now and will post the solution. There were two parts:
As per the 'update' in the question, the Request methods in the XSD were named after the method, and weren't suffixed 'Request'. This meant that I had to make a custom WSDL11Definition class that would allow the setRequestSuffix to be null (empty). The question link has more details.
The objects on the method needed to be wrapped in JAXBElement<> in order to recognise the input and output successfully.
One all the above had been done, my breakpoint was hit in my IDE using SOAPUI.
So, I'm currently developing an app for a service which has a json-based (unfortunately) read only API. Retrieving content is no problem at all, however the only way to post content is using a form on their site which location is a PHP script. The service is open source so I know which fields the form expects, but whatever I send, it always results in a BAD REQUEST.
I captured the network traffic inside my browser and as far as I can see, the browser constructs a multipart form request, however when I copy the request and invoke it again using a REST client, a BAD REQUEST gets returned.
Is there a way to construct a http request in Android that simulates a form post?
If it's readonly I think you wouldn't be able to make requests with POST (it's assume for editing or adding things).
If you let me make you an advise, I recommend you using this project as a Library.
https://github.com/matessoftwaresolutions/AndroidHttpRestService
It makes you easy deal with apis, control network problems etc.
You can find a sample of use there.
You only have to:
Build your URL
Tell the component to execute in POST mode
Build your JSON
As I told you, I don't know even if it will work.
I hope it helps!!!
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
So what I need is basically to create a java program that runs from command line and will continue to run until I decide to stop it. The goal of this program is to read email from a particular email address and create JIRA tickets using the contents of the email.
IE: subject of email will be title. Body will be description. Etc...
I am getting confused with how to go about with the design of how to do this. I know I can use JavaMail to gain access to the emails right? Then I just have to parse the email. But other than that I am a little stuck on how I should be making the JIRA Ticket
Thanks!
Your problem is an ideal use case for esb like mule or spring-integration. Basically these eip frameworks provide all building blocks you just need to connect.
First you need to define mail inbound. This component will automatically connect to an mail inbox and fetch all new messages.
Then define a transformation from e-mail message to json object. Finally POST that object using HTTP outbound. You can create ticket in JIRA using /rest/api/2/issue API method.
whole workflow can be implemented almost without coding. Of course you can do everything manually (using javamail and httpclient), but then threading, error handling and retrying is up to you.
For the future - if you're confused what requests are sent and so on - use Google Chrome.
Press Ctrl+Shift+I->Network and make request. If you need to login before etc. it is the same.
For handling HTTP requests (POST, GET, etc.) I recommend to use HttpClient or if you need to use JavaScript HtmlUnit.
So answer is this:
- Track what requests are made when you do certain things via web browser
- implements the same in Java code using HttpClient or HtmlUnit
I have a class that I want to hook and redirect HTTP requests in.
I also have a loader class already written, but all it does it replace the functions that contain the HTTP requests I want to change.
Is there a way to hook HTTP requests in Java so that I can redirect them all more easily?
Sort of like a proxy-wrapper.
Clarification:
The app sends out a GET or POST request to a URL.
I need the content to remain the same, just change the URL.
DNS redirects won't work, the Host HTTP header needs to be correct for the new server.
PS: This is a Desktop App, not a server script.
A cumbersome but reliable way of doing this would be to make your application use a proxy server, and then write a proxy server which makes the changes you need. The proxy server could be in-process in your application; it wouldn't need to be a separate program.
To use a proxy, set a couple of system properties - http.proxyHost and http.proxyPort. Requests made via HttpURLConnection will then use that proxy (unless they specifically override the default proxy settings). Requests made using some other method like Apache HttpClient will not, i think, be affected, but hopefully, all your requests are using HttpURLConnection.
To implement the proxy, if you're using a Sun JRE, then you should probably use the built-in HTTP server; set up a single handler mapped to the path "/", and this will pick up all requests being sent by your app, and can then determine the right URL to send them to, and make a connection to that URL (with all the right headers too). To make the connection, use URL.openConnection(Proxy.NO_PROXY) to avoid making a request to the proxy and so getting caught in an infinite loop. You'll then need to pump input and output between the two sockets.
The only other way i can think of to do this would be to override HttpURLConnection with a new handler which steers requests to your desired destination; you'd need to find a way to persuade the URL class to use your handler instead of the default one. I don't know how you'd do that in a clean way.
While an older post, this should give some ideas of some kinds of bytecode injects which can be peformed: Java Programming: Bytecode Injection. Another tool is Javassist and you may be able to find some links from the Aspected-oriented programming wiki article (look at the bytecode weavers section).
There are some products which extensively dynamically modify code.
Depending upon what is desired, there may be ... less painful ... methods. If you simply want to 'hook' HTTP requests, another option is just to use a proxy (which could be an external process) and funnel through that. Using a proxy would likely require control over the name resolution used.
you can use servlet filters which intercept the requests, the requests can further be wrapped, redirected, forwarded or completed from here.
http://www.oracle.com/technetwork/java/filters-137243.html
Do you control all of the code? If so, I suggest using Dependency Injection to inject the concrete implementation you want, which would allow you to instead inject a proxy class.
If you can change the source code, just change it and add your extra code on each HTTP request.
If you can't change the source code, but it uses dependency injection, perhaps you can inject something to catch requests.
Otherwise: use aspect-oriented programming and catch to URL class, or whatever you use to do HTTP requests. #AspectJ (http://www.eclipse.org/aspectj/doc/next/adk15notebook/ataspectj.html ) is quite easy and powerful.