Hiding WSDL in JAX-WS - wsdl

I'm, using JAX-WS in order to build and deploy web-services.
Everything is working properly, however I need to hide the WSDL. In other words, If the user goes to the following URL: http://foo.com/wm-ws/WMService2?wsdl, i don't want the WSDL to show.
I read that we could use the #WSDL annotation so i did that as follows:
#WebService(serviceName = "WMService2",
targetNamespace = "http://test.wmservice.soap/",
portName = "WMService2")
#WSDL(exposed = false)
public class WMService2
{
...
}
But this doesn't change anything..The WSDL is still showing. I've seen work-around where a filter is created, but i think it's an overkill.
Any ideas?

For starters, your client will likely require the WSDL at runtime. It is possible to get around this with hand-crafted client code or by including a local copy of the WSDL (which requires a bit of magic in an EE environment, namely packaging the WSDL in your artifact and specifying a wsdl-location in your wsimport (I can provide more info if desired; this is also a valid solution: JAX-WS client : what's the correct path to access the local WSDL?). This explains more about the dependency but it's also a good idea to have it available for interoperability: Why is WSDL required for Java Client at runtime?
With that said, it sounds like what you're actually trying to accomplish is restrict access to web resources, which is easily accomplished with a web.xml. Specifically you can add a security constraint,
<security-constraint>
<web-resource-collection>
<url-pattern>*?wsdl</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
although this will mean that you must set up authentication in your container and authenticate in your client (what is your container? client?). The url-pattern can be anything and the role-name * indicates any authenticated user may access the resource.
About security contraints: http://docs.oracle.com/cd/E19798-01/821-1841/bncbk/index.html

Related

Dropwizard: customize health check address and format

Is it possible to customize Dropwizrd's healthcheck output so that, e.g.: /health for healthchecks instead of /healthcheck and some output like {“status”: 200}.
I realise I could simply write a new resource that does what ever I need, I was just wondering if there is a more standard way to do this.
From what I have read on the 0.7.1 source code it's not possible to change the resource URI for healthchecks unfortunately, I highly doubt you can change the healthcheck format. I also remember people complaining about not being able to add REST resources to admin page, only servlets. Maybe on 0.8.0?
Here are the details of what I've tracked so far on the source code. Maybe I have misread or misunderstood something, so somebody could fix it.
Metrics has actually written AdminServlet to add healtcheck servlet in a way that it checks the servlet config whether the URI is defined or not.
this.healthcheckUri = getParam(config.getInitParameter(HEALTHCHECK_URI_PARAM_KEY), DEFAULT_HEALTHCHECK_URI);
But dropwizard doesn't provide a way to inject this configuration in any way on AbstractServerFactory.
handler.addServlet(new NonblockingServletHolder(new AdminServlet()), "/*");
NonblockingServletHolder is the one which is providing the config to AdminServlet but is created by AbstractServerFactory with empty constructor and provides no way to change the config.
I've thought of and tried to access the ServletHolder from the Environment object on Application.run method but the admin servlets are not created until after run method is run.
environment.getAdminContext().getServletHandler().getServlets()[0].setInitParameter("healthcheck-uri", "/health");
Something like this in your run() function will help you control the URI of your healthchecks:
environment.servlets().addServlet(
"HealthCheckServlet",
new HealthCheckServlet(environment.healthChecks())
).addMapping("/health");
If you want to actually control what's returned you need to write your own resource file. Fetch all the healthchecks from the registery, run them and return whatever aggregated value you want based on their results.

How can I automate my tests for Java application without using UI?

I have access to the Code base (checked out to my local machine from SVN). It is written using Java and Groovy using Grails framework (MVC architecture). I am a tester and as part of automating my tests, I want to write code that will make calls to the controllers and in return i can check the result in terms of looking at response or entries in data base. I basically want to skip the UI part.
How can I start? I probably cannot write my code inside the dev project (i am not allowed to i suppose). Do i need to create a separate framework for it? Or can I take all the jar files and include then in a project and write code on top of it?
The answer in this post is actually what I am looking for but for a Java application. Is there any API i can use?
Please let me know if you need additional information.
If the application does not provide Json, XML or similar APIs, you can use a test library like HtmlUnit within jUnit test methods.
A example from "Getting Started" section:
#Test
public void homePage_Firefox() throws Exception {
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17);
final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
Assert.assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());
webClient.closeAllWindows();
}
Note that HtmlUnit tries to work like a virtual browser (written 100% in Java), but it is a bit limited in executing Javascript, for example.
Then, use another library like jsoup or Jericho HTML Parese to inspect the code and get the values you want to check in the database.
In the other hand, if the application does provide methods to obtain the data, you can use Jersey Client API to make REST requests and get the values. It is very simple. Look at this example:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:9998").path("resource");
Form form = new Form();
form.param("x", "foo");
form.param("y", "bar");
MyJAXBBean bean =
target.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(form,MediaType.APPLICATION_FORM_URLENCODED_TYPE),
MyJAXBBean.class);

Howto access registry in WSO2 ESB

Howto reference WSDL files from the registry when defining a new proxy service? I am using WSO2 ESB.
Q1: Can I use the localEntry element to define the WSDL in my proxy service? For example:
localEntry key="my_wsdl" src="file:/wsdl/MyServiceSOAP.wsdl"
Provided that I have previously used Management Console > Add Collection > create "wsdl", and Add Resource > MyServiceSOAP.wsdl.
I have a problem with the "src" value, both
"/wsdl/MyServiceSOAP.wsdl"
and
"wsdl/MyServiceSOAP.wsdl"
do not work. I follow the documentation but they do not show howto upload WSDLs into the registry.
Q2: What if MyServiceSOAP.wsdl imports MyService.wsdl? I need to use Add Resource for MyService.wsdl as well but do I need to do anything else to make the Proxy compile?
I think you are referring to the registry here. The Registry space in each product contains three major partitions.
Local
Configuration
Governance
The configuration registry contains product specific configuration that can be shared across multiple instances of the same product (a cluster of ESB nodes for example). So you can create the WSDL collection inside the Config registry and refer to it like..
"conf:/wsdl/MyServiceSOAP.wsdl"
By uploading the resources to Registry, you can pick them easily when creating the proxy service too.
I think you can refer to resources as "file:/wsdl/MyServiceSOAP.wsdl" only when they are inside a directory named 'wsdl' in the local file system.
BTW, about the error messages.. If you look at ESB server logs you'll see the following error when you try to update the proxy referring to a non existing file.
Caused by: java.io.FileNotFoundException: ./wsdl/MyServiceSOAP.wsdl (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
at org.apache.synapse.config.SynapseConfigUtils.getObject(SynapseConfigUtils.java:197)
... 46 more
I found a simple solution for it from a blog:
In my Scenario I had a wsdl, that imported another wsdl that imported a xsd. The actual structures were in the second wsdl.
Import line in the original wsdl:
<wsdl:import namespace="http://www.somedomain.com/interface/v1_0" location="service_interface_1_0.wsdl"/>
Import line in the second wsdl:
<xsd:import namespace="http://www.somedomain.com/data/v1_0" schemaLocation="data_types_1_0.xsd"/>
Required xml on the proxy:
<publishWSDL key="file_required_service_1_0.wsdl">
<resource location="service_interface_1_0.wsdl"
key="file_service_interface_1_0.wsdl"/>
<resource location="data_types_1_0.xsd"
key="file_data_types_1_0.xsd"/>
Where I have local entries for "file_required_service_1_0.wsdl" etc named local entries that contain the original wsdl and xsd files.

Delphi 2005 Web Services problem

I'm having an issue trying to access a web service through Delphi. I've consumed a java WSDL with the 2007 version of the WSDLimp tool and it looks like it's created all of the objects correctly. When I make a tester program however that calls the service every object is empty. If I dump the SOAPResponse object in the HTTPRIOAfterExecute method I can see that I've gotten back a properly formatted XML Soap packet that contains all the data I would expect, but I can't access it through the objects. So is there something I'm missing?
The web service response contains aliased namespaces for each attribute. These aliases are not defined in the WSDL. For example, the WSDL contains a namespace of "http://www.example.com/SomeService" and the request aliases that on-the-fly as xmlns:ns3="http://www.example.com/SomeService" in the top level node. So attributes in the response look like ns3:somePropertyName="[value]".
In the OPToSOAPDomConv unit, in the TSOAPDomConv.InitObjectFromSOAP, it's attempting to look up an attribute name without the namespace prefix. This is causing the look up to fail and the object property to be left blank. This is happening even with the 2007 source files.
The best fix I can see is to modify the InitObjectFromSOAP routine.
Around line 4181, add:
RemTypeRegistry.InfoToURI(PropList[i].PropType^, NS, PropName, IsScalar);
and change the AttrNode.HasAttribute to pass the NS variable as a second parameter so it looks like:
if AttrNode.HasAttribute(ExternalPropName, NS) then
Also, a few lines down is a SetObjectPropFromText call. The last parameter is the attribute value, and you'll need to change Attr.Attributes[ExternalPropName] to
SetObjectPropFromText(Instance, PropList[I], AttrNode.GetAttributeNS(ExternalPropName, NS))
And of course declare the NS, PropName and IsScalar vars.
Delphi dropped the ball on web service support after Delphi 7 and didn't get their act together again until Delphi 2007 (though 2006 was an improvement).
If it works for you in Delphi 2007, you can probably get this working in Delphi 2005 by using the updated SOAP runtime.
http://cc.embarcadero.com/Item/24535
You could try the solution discussed at http://www.borlandtalk.com/1-vt102378.html?start=0
I re-read the question and the fact that it's a Java web service made me remember something.
Making sure you use the latest WSDLImp and SOAP units. Look in the imported unit for the call to RegisterInvokeOptions. The second parameter should be ioDocument. What happens if you change this to ioDefault.
I remember a post somewhere that suggested this for Java NetBeans (maybe?) web services, but haven't tried it.

Scaffolding Web Services in Grails

I need to implement a web app, but instead of using relational database I need to use different SOAP Web Services as a back-end. An important part of application only calls web services and displays the result. Since Web Services are clearly defined in form of Operation: In parameters and Return Type it seems to me that basic GUI could be easily constructed just like in the case of scaffolding based on Domain Entities.
For example in case of SearchProducts web service operation I need to enter search parameters as input, so the search page can be constructed. Operation will return a list of products, so I need a page that will display this list in some kind of table.
Is there already some library in grails that let you achieve this. If not, how would you go about creating one?
Probably the easiest approach is to use wsimport on the WSDL files to generate the client-side stubs. Then you can call methods in the stubs from Groovy just as you would have called them from Java.
For example, consider the WSDL file for Microsoft's TerraServer, located at http://terraservice.net/TerraService.asmx?wsdl . Then you run something like
wsimport -d src -keep http://terraservice.net/TerraService.asmx?WSDL
which puts all the compiled stubs in the src directory. Then you can write Groovy code like
import com.terraserver_usa.terraserver.*;
TerraServiceSoap sei = new TerraService().getTerraServiceSoap()
Place home = new Place(city:'Boston',state:'MA',country:'US')
def pt = sei.convertPlaceToLonLatPt(home)
println "$pt.lat, $pt.lon"
assert Math.abs(pt.lat - 42.360000) < 0.001
assert Math.abs(pt.lon - -71.05000) < 0.001
If you want to access a lot of web services, generate the stubs for all of them. Or you can use dynamic proxies instead.
The bottom line, though, is to let Java do what it already does well, and use Groovy where it makes your life easier.
You should be able to use XFire or CXF Plugins. For automatic scaffolding, modify your Controller.groovy template in scaffolding templates so it auto-generates methods you need.

Resources