how to pass parameter to WebService in Spring DSL - web-services

I am new to apache Camel. I am trying to invoke a simple calculator WebService which I have created netbeans using Metro JAXWS . The Calculator has one webmethod with following signature:
int add int a, int b
Now, my goal is to invoke this webservice using Apache camel, cxf component. After reading multiple tutorials and examples, I completed following steps:
1) Used wsdl2java tool to generate WebService stub in the project.
2) Defined CXFEndpoint in camel-cxf.xml.
<cxf:cxfEndpoint id="calEndPoint"`
address="http://localhost:8080/Calculator/Calculator"
serviceClass="com.test.calculatorbeanws.Calculator"
wsdlURL="wsdl/calculator.wsdl"/>
3) Now, I am trying to create a route in camel-context.xml to call this web-service. It should look something like this.
<camel:route>
<camel:from ....." />
<camel:to uri="cxf:bean:calEndPoint"/>
<camel:to uri="file:someoutputfile"/>
</camel:route>
So, the problem is defining this route. How can I pass parameters a and b to calEndPoint, and how can I write the output to some output file or display it on console using Spring DSL.
Hopefully, I have explained the problems in detail. If anybody has any suggestion, please let me know.
Thanks

Related

Creating webservice and client with JBossWS using Complex objects as arguments and return types

I am developing a WebService and Client for it using JBoss 5.1.0GA. The JBossWs stack was already preinstalled with the binary that I downloaded and as I understand it is JBossWs 3.1.2GA
I have developed a web service using this setup and have also created a client successfully. This is what I have.
A pojo web service deployed as a war file.
#WebService
public class Service{
#WebMethod
public CompleObj getConfiguration() {
CompleObj oConf = new CompleObj ();
for (int i = 0; i < 10; i++) {
NestObj oInst = new BOpRepoInstance("Val1", "Val2", "Val3", "Val4");
oConf.addRepoInstance(oInst);
}
return oConf;
}
}
Here,
CompleObj => is a Complex Object that has a list of type NestObj. Its
getter/setters, toString and some other methods.
NextObj => has 4 variables of Type String. Its getter/setters,
toString, hashCode, equals and some other methods.
Got this web service deployed successfully.
Later created a client using the eclipse wizard for generating Web Service Client using WSDL document. It also created a sample client file which would call the webservice and fetch the return value. This also worked like a charm.
Now my problem is, when eclipse generated stubs for clients it created classes for CompleObj and NestObj. These classes only has the variables and its getters/setters (this make sense as these are being generated from WSDL doc). Thus i loose a lot of other methods that includes toString, hasCode, equals etc, which I want to use at the Client side as well.
Now how can I make use of the actual class files defined in the WebService project directly and avoid the client to use the generated ones. I can provide the class files as .jar binary for the Client project, I cant really get how to achieve this.
Another question is, the web service location is embedded in the stubs directly, what can i do to have the webservice location passed as part of the argument to the invocation code?
The classes which are generated in the client side are just place
holders it is not deserilized version of your own classes,When you
invoke the service it is used to carry your object to server then
the JBOOSWS will do the JAXB mapping to the actual classes. So you
can not make the your own classes to be used in the client side
though they are look same.
URL will be fixed in the stub code, since in eclipse while generating WS client the first
thing you must provide is, the WSDL URL,then eclipse will generate the
client code accordingly,so generated code is specific to the WSDL
you provided. If you want to pass the WSDL dynamically,then you
need to have your own code to generate the client stubs by passed
WSDL URL using any WSDLtoJAVA or any other utility.

Flex Webservice

I'm using Flash Builder 4.5 and flex 4.5 language.
I'm using a webservice to retrieve data in json calling a .php.
<webservice:Webservice id="webservice" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="testResult" result="onTestResult(event)"/>
...
private function onTestResult(e:ResultEvent):void{
Alert.show(ObjectUtil.toString(testResult.lastResult));
}
In the "Test Operation" window of Flash Builder I made my call and the return is a json Object made by arrays.
If I call the same webservice from the code instead, it returns a (object)#0 so an empty Object. No errors thown, just an empty Object.
Anyone has some tips?
The ns prefix of your Webservice class susggests you're using a custom implementation, rather than the framework WebService class. However, you don't provide any specifics, so I'm gonna take a swing in the dark:
If your custom service is based off the HTTPService class, make sure you're setting the resultFormat='text'. The default is XML, which will be causing you problems.
If you're using the Framework WebService class, well - you can't, as it's designed for SOAP webservices, not JSON. (From the Docs for mx.rpc.soap.WebService:)
The WebService class provides access to SOAP-based web services on
remote servers.
If it's some other implementation, please provide more details.

Add custom SOAP header in PowerShell using New-WebServiceProxy

In C# I can do the following:
var header = MessageHeader.CreateHeader("MyHeader", "http://mynamespace", "Header value");
OperationContext.Current.OutgoingMessageHeaders.Add(header);
That adds the following to the SOAP message:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<MyHeader xmlns="http://mynamespace">Header value</MyHeader>
....
</s:Header>
...
How can I similarly add a custom outgoing SOAP message header when calling methods on a proxy generated by the New-WebServiceProxy PowerShell commandlet?
Edit:
To clarify, I can make the same calls in PowerShell that I show in the C# above, but OperationContext.Current is always null. I get around that in C# by creating an OperationContextScope, but that requires the inner channel of the web service proxy, which PowerShell's proxy doesn't seem to provide.
Your C# code is using the OperationContext class from WCF. PowerShell's New-WebServiceProxy cmdlet does not use WCF, instead it creates classes based on the System.Web.Services.Protocols.SoapHttpClientProtocol class.
To get an instance of SoapHttpClientProtocol to send custom SOAP headers, you use SoapExtension, as described here:
http://blogs.msdn.com/b/kaevans/archive/2007/08/06/programmatically-insert-soapheader-into-soap-request-with-asmx-soapextensions.aspx
Due to the need to create a new class inheriting from SoapExtension, porting the content of the blog post to PowerShell will most likely involve use of embedded C# via the Add-Type cmdlet's TypeDefinition parameter.

Generating stub classes for 3rd party WS

I need to incorporate a pretty complex 3rd party web service into my Grails app. My plan was to use WSDL2Java to generate the stub classes from the wsdl, and this was the method recommended in the 3rd party's documentation (complete with examples). First i tried to use the Axis2 codegen plugin for Eclipse but eventually came up against an InvocationTargetexception. I debugged the plugin and found it was because the wsdl is defined with RPC encoding.
Some people have recommended using Axis 1.4 instead, so I've now installed that too but have come up against an IO Exception - Type {http://xml.apache.org/xml-soap}DataHandler is referenced but not defined.
Can anyone suggest a method for creating the java classes from this wsdl without having to hack the wsdl apart?
I ended up using the Axis2 wdsl2java and copying the required annotated code into the service and used the CXF plugin. I also put in my service the following code
static expose=['cxfjax']
The reason why I had to do this was because there was a "complicated" (for grails) structure my methods look like
#WebMethod(operationName = "authenticate", action = "http://betterhidethis/authenticate")
#WebResult(name = "authenticateResult", targetNamespace = "http:/betterhidethis/")
public ArrayOfString authenticate(
#WebParam(name = "strUserName", targetNamespace = "http://betterhidethis/")
String strUserName,
#WebParam(name = "strPassword", targetNamespace = "http://betterhidethis/")
String strPassword) {
Of cause the Geneerator also created the ArrayOfString class which I use later.
Hope this helps.

Is there a usable standards-compliant (168/286) portlet testing framework? (especially one that works with Spring PortletMVC)

I've not seen anything in this area I would recommend to a client. If you've used Spring PortletMVC, how did you test it?
It's easy to test under the level of portlet code, and relatively easy to test on the client side through HtmlUnit, Selenium and the like, but I haven't seen anything that is a "Gray Box" test in the spirit of JSFUnit (which looks to me to be the way forward).
Apache's Pluto driver could theoretically be used to bootstrap a test harness. Has anyone tried this?
Any stub or data provider approaches?
Any approach to address two-phase processing concerns?
I don't know anything about portlets but here it goes.
There's portletUnit.
portletUnit is a testing framework
used to test JSR-168 portlets outside
portlet container just as servletUnit
is used to test servlets outside a
servlet container. The projected is
architected to map the functionally of
servletUnit onto portlets with
servletUnit itself providing the
foundation for portletUnit.
Some more related info could be found on his Project PortletUnit blog, including PortletUnit and Spring Portlet: Checking form validation errors.
When testing with portletUnit, it is
not obvious how to check if there were
any form errors. Fortunately, using
the render listener feature of
PortletRunner, there is a simple way
to check for validator errors.
There's also a blog article written by Nils-Helge Garli Hegvik in 2007 titled Testing Portlets with Jetty, Pluto and JWebUnit.
Remembering an excellent article from
Johannes Brodwall's blog about
integration testing with Jetty and
JWebUnit, I wanted to extend his
approach to use the embedded
jetty-pluto setup I have created. This
turned out to be to be quite easy.
Finally, Spring Framework documentation 10.2 Unit testing.
The
org.springframework.mock.web.portlet
package contains a set of Portlet API
mock objects, targeted at usage with
Spring's Portlet MVC framework.
[...] The org.springframework.test.web
package contains ModelAndViewAssert,
which can be used in combination with
any testing framework (e.g., JUnit 4+,
TestNG, etc.) for unit tests dealing
with Spring MVC ModelAndView objects.
[...] To test your Spring MVC Controllers, use
ModelAndViewAssert combined with
MockHttpServletRequest,
MockHttpSession, etc. from the
org.springframework.mock.web package.
Here's a related article written by John Ferguson Smart titled
Unit testing your Spring-MVC applications.
One of the great things about this
framework is how testable it is. In
Spring-MVC, any custom validators (for
field and form validation) and
property editors (for converting text
fields to specific Java types) are
dead-easy to test - you can just test
them as if they where isolated POJOs.
Spring-MVC also comes with a full set
of mock objects that you can use (with
a bit of practice) to test your
controllers to your heart's content.
For example, you can use classes like
MockHttpServletRequest and
MockHttpServletResponse to simulate
your HTTP request and response
objects. This is also made easier by
the fact that Controllers can be
instanciated as normal Java classes.
For example, imagine you are testing a
controller class for a page that
updates a client details record. You
could do this very simply as follows:
public class UpdateClientTest {
//
// Prepare your request
//
request.setMethod("POST");
request.setParameter("id", "100");
request.setParameter("firstName", "Jane");
request.setParameter("lastName", "Doe");
//
// Invoke the controller
//
controller = new ChoosePeriodController();
ModelAndView mav = controller.handleRequest(request, response);
//
// Inject any service objects you need
//
controller.setClientService(clientService);
...
//
// Inspect the results
//
assert mav != null;
assertEquals("displayClient",mav.getViewName());
Client client = (Client) mav.getModel().get("client");
assertEquals("Jane",client.getFirstName());
assertEquals("Doe",client.getLastName());
...
}
...
Checkout spring-test-portlet-mvc (https://github.com/markusf/spring-test-portlet-mvc), which exposes the features of MockMvc to the Portal context and lets you integration test your Spring Portlets easily.