I've inherited a project that contains many jaxws services. I want to add another one and am trying to duplicate a similar working example. I can test that one like this
./soapget.sh soap_serial.xml r.xml
where soapget.sh is
#!/bin/bash
wget "http://localhost:5032/VCWH_QueryService/soap/SettopChannelMapResourceService" --post-file=$1 --header="Content-Type: text/xml" -O $2
This produces a good response, captured in r.xml.
Like the working service, my new service uses three classes. The code compiles ok, assembles into a .war file, and deploys. Now when I try the same thing for the new service I wrote
./bsg.sh soap_rate.xml r2.xml
where bsg.sh is
#!/bin/bash
wget "http://localhost:5032/VCWH_QueryService/soap/BsgHandleResourceService" --post-file=$1 --header="Content-Type: text/xml" -O $2
I get the useless error
2015-11-23 20:26:52 ERROR 500: Internal Server Error
The log files for the project do not contain any more info either.
There are just too many black boxes interacting that I can't figure out what's going on... Maven-Enunciate-Plugin, jax-ws, Java, etc.
For example, how does calling BSGHandleResourceService find its way to the actual code, one of which is called BSGHandleResource.java? Normally I would make those hooks in the web.xml file but that has been taken over by the black boxes.
Are there any jax-ws/maven experts out there that can shed some light?
I was able to find and fix the problem by sending a soap request to the service using SoapUI. That returned useful error messages whereas the other method did not.
Related
I have a web app which I would like to test using Selenium, with this app communicating with the backend using a REST API.
It is my understanding that Selenium is mainly used to test the flows through an application and the appearance/presence of widgets for each of these states. This would suggest to me that it makes a lot of sense when writing Selenium tests to simulate the backend. Python is my language of choice but I am also familiar with node.js, javascript and JAVA. What approach would you recommend with regard to simulating the REST API. I was thinking of writing a server using Python. I can create this server within my test environment and configure how it responds to requests from the front-end on a test by test basis. Are there any tools, libraries you might recommend me?
I should also add that I am using raml to define my api.
So with my simulation of the backend, the tests would look something like this:
def test_no_table_for_one_user():
# configure reply for api request
rest_sim.get_users_response = (200, [{name: "Foo Bar", address: "West side"}])
navigate_to_users_page()
# test that this users details are presented without the use of a table
...
def test_table_for_multiple_users():
# configure reply for api request
rest_sim.get_users_response = (200, [{name: "Foo Bar", address: "West side"}, {name: "Foo Baz", address: "East side"}])
navigate_to_users_page()
# test that the two users are presented in the form of a table
...
For mocking simple REST API you can try node.js-based json-server.
It's easy to setup, you just need to create JSON file with some data to simulate db, json-server will create all common REST API routes for you.
There are many libraries and tools available to help you with this. What you are talking about is creating a test harness, or emulator/simulator. In most situations, it is generally recommended that the person who builds and develops the backend, provide you with the harness since they are owners of the API and control different versions and change. Reciprocally, you can provide them with your client so they can understand how you use the API.
If they cannot do this, then you will need to create a harness yourself. The best tool to help you do this for HTTP API's is WireMock
http://wiremock.org/
In your example you will probably want to run this as Stand Alone:
http://wiremock.org/docs/running-standalone/
And then using JSON file configuration to define the behaviour.
My preference is to also wrap and deploy you WireMock test harness as a Docker image and publish to a Docker repository so that other people can use it. In this case its simply a case of creating a Dockerfile with the following and running a docker container:
Dockerfile
FROM java:8
WORKDIR /opt
RUN apt-get install wget
RUN wget http://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.5.0/wiremock-standalone-2.5.0.jar
RUN mkdir mappings
VOLUME /opt/mappings
EXPOSE 8080
CMD java -jar wiremock-standalone-2.5.0.jar
command line
docker build -t wiremock/apiname:[version] .
docker run -d -p [exposedport]:8080 -v /directory/with/json:/opt/mappings --name apiname wiremock/apiname:[version]
I would choose Python without any problems.
Please have a look at the requests module:
http://docs.python-requests.org/en/master/
It is really easy to install and to make requests by using REST messages.
No matter what you have to do, I will continue with Python.
How to use REST API from requests after installation (with pip for instance):
import requests
class RESTIF():
'''
Class to handle a connection towards your server
'''
def __init__(self):
'''Initialization of a single Session and header dictionary to be used for REST requests.'''
self.nSession = requests.Session()
# Default header values to get initial connection:
self.header = {"Content-Type":"application/json",
"KeepAlive":"true",
"Authorization":"Basic ",
"Cookie": None}
def action(self, URL, JSONdata):
myCreate = self.nSession.post(URL, headers=self.header, data=JSONdata)
The header is quite useful in case of Cookie exchange. Requests will take care of that.
You can handle login to a rest api or send PUT/POST/DELETE/GET messages easily!
Everything is possible and no need to switch to Java or other languages.
Please let me know if you have additional queries or that solved your question. Have a great one!
My code:
curl -X POST http://localhost:54321/3/ParseSetup --data 'source_frames=["/root/documents/my_file.csv"]'
Error:
java.lang.IllegalArgumentException: Key not loaded: Key at
water.api.ParseSetupHandler.guessSetup(ParseSetupHandler.java:31)
Help:
Could anyone help to resolve this? Am I missing any parameter?
Used H2O version: h2o-3.10.0.10
My suggestion is to open Flow (http://localhost:54321) in a browser, then start Firebug (or the equivalent in your browser of choice), and the network tab. Then do a file import from Flow, then the parse, and make a note of exactly what it is sending.
(Alternatively do the import from R or Python with a packet sniffer going, but that sounds like harder work.)
Did you do the /3/ImportFiles calls first?
(I actually see three calls: ImportFiles, ParseSetup, Parse.)
In my quick test I'm seeing the "nfs://" prefix on all the paths. Don't know if that is important.
But, my first guess would be that you should be using --data-urlencode instead of --data. Or manually URL-encode your data.
I have developed one web service for order management. This web service takes many complex objects as input parameters. I used curl to test and it works fine. Now I am writing a client but having issue when for ArrayList (e.g. the items are coming as ArrayList) objects. It's sending as String. It's seems the limitation the client framework I am using. I have tried one or two open frameworks but they are not working as expected. It will be great if you can suggest some framework with some examples.
Below is the sample curl request, I have removed some extra parameters to keep it simple.
curl -L -v -b agent_cookies.txt -H "Content-Type: application/json" -d
"{"items":{"atg-rest-class-type":"java.util.ArrayList","atg-rest-values":
[{"atg-rest-class-type":"com.bean.CommerceItemInfo","tinSkuNumber":"41589367","itemNumber":
280594,"color": 9,"size":
94,"salePrice":50.00,"taxAmount":3.5,"stateTax":0.48,"countyTax":0.08,"currencyCode":"USD"},{"atg-rest-class-type":"com..bean.CommerceItemInfo",
"tinSkuNumber":"41589375","itemNumber": 280594,"color": 9,"size":
96,"salePrice":100.00,"taxAmount":7,"stateTax":0.96,"countyTax":0.16,"currencyCode":"USD"}]},orderInfo:{...},"clientAddress":{"atg-rest-class-type":"java.util.ArrayList","atg-rest-values":
[{"atg-rest-class-type":"com.bean.ClientAddress",\"firstName\":\"John\",\"lastName\":\"Dao\",\"state\":\"FL\",\"country\":\"US\",\"postalCode\":\"33606\",\"address1\":\"100
S Edison Avenue\",\"address2\":\"Suite
D\",\"city\":\"Tampa\",\"addressType\":\"BOTH\"}]},{......}}"
http://localhost:8080/rest/model/com/web/actor/CartActor/testOrder
Thank you
After some research I found the limitation of ATG client and no way we can send List.I changed the arguments to accept individual beans only.
As a premise, I am not very experienced yet, but I have tried to read and search everything I possibly could, related to this topic, and still no luck.
I was given a simple client to call a webservice but once it was fully setup (which included the use of a certificate and a couple more properties to set) I got the error mentioned in the title:
javax.xml.ws.WebServiceException: {http://http://cert.controller.portaapplicativa.ictechnology.it//}MyService is not a valid service. Valid services are:
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:187)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:159)
at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:82)
at javax.xml.ws.Service.<init>(Service.java:56)
at package.client.wsimport.MyService..<init>(MyService.java:46)
at package.client.Client.doRicercaDEN(Client.java:55)
at package.client.Client.main(Client.java:36)
I tried generating the client again with JAX-WS:
java -classpath C:\Programmi\Java\jdk1.6.0_38\lib\tools.jar com.sun.tools.internal.ws.WsImport -verbose C:\WsdlFile.wsdl -p package.client.wsimport -s C:\tmp\ws\
And I get the same issue. I am using a local copy of the wsdl because wsimport doesn't seem to like the certificate I'm trying to set in the properties (I'm most likely doing something wrong, but I opted for the simple workaround, given I have more pressing issues).
Trying to use SoapUI to test the service, everything works fine, though I need to set the preferences for the proxy to "None".
So I tried to make sure the connection doesn't use any proxy in my client as well:
(...)
systemSettings.remove("http.proxyHost");
systemSettings.remove("http.proxyPort");
systemSettings.remove("https.proxyHost");
systemSettings.remove("https.proxyPort");
System.setProperty("http.nonProxyHosts","*");
System.setProperty("https.nonProxyHosts","*");
(BTW, before "*", which as I understand it should work as a wildcard for "every domain", I have tried specifying the specific domains as well)
Anyway, the result is always the same.
Is there something I am doing wrong, something left to try?
I doubt this is a proxy issue. If you can share the code you are using to create the Service object it might help.
As a kick start try reading the below thread Is not a valid service exception in JAX-WS
What I think is that the QName you have provided when creating the Service is not proper. To get the correct QName you might try to open the generated stub.
As it turns out, what I was missing was importing the certificate in my local truststore (or better, when I first tried doing so, I thought I was using the correct truststore, but I wasn't).
For anyone who may need it, here is an explanation of how to do that using keytool: http://javarevisited.blogspot.it/2012/03/add-list-certficates-java-keystore.html
Another option is to use specific GUI like Portecle.
I am trying to use wsdl2js to generate the client-side handler of a SOAP request for a WSDL file but running into a few problems. If I use:
>wsdl2js -p [projectName] [wsdlFile]
it only generates a javascript file, which isn't what I need.
If I use
wsdl2js -client [wsdlFile]
like they demonstrate, I get an "Unexpected option: -client"
Any help would be greatly appreciated, thanks
There is no -client option in wsdl2js. That's why you're getting the last-mentioned error.
The javascript file that is generated from a call like
>wsdl2js -p soap http://link.to/webservice?wsdlfile
will generate the stubs you need in order to communicate with the referenced webservice