ksoap2 complex parameter - java

I need to call a web service using ksoap2, I have been doign this successfully up till the point where I need to pass a more complex type to the web service.
Does anybody have an example of passing a complex type to a webservice, preferably, only using SoapObject (the object in question is only Strings and dateTimes.
Thanks
in advance

Here is a working tutorial for complex types and arrays with KSOAP . Hope it helps.

Figured out how to do it. Simply used a SoapObject as a property.

I think you can use this android web service client open source tool.
Where you needn't use the soap Object or think with the soap envelop its just like call a method of a service.
say, for a service say ComplexReqService with param ComplexRequest you have to just write :
ComplexReqService service = new ComplexReqService();
CoplextReqPort port = service.getPort();
String resp = port.getResponse ( new ComplexRequest() );
In this way, It will support the complex response as well.

Related

Odata with Olingo or Odata4j

I'm in over my head.
At the broadest level, I'm trying to expose an Odata interface to an existing pool of data exposed by a service written using Mule. When my Mule service is invoked, if I detect that the URL is Odata format, I want to delegate processing down to something written in Java and then feed the response from that component back to my caller.
I found the Olingo and OData4j libraries. My problem is that these start from building a Web service. But that's too far upstream for me. I have a Web service. What I need to understand are what components I need to implement in order to pass the URL (which I have in hand) onward to an Odata parser which will, in turn, invoke a data provider.
I'm a bit lost with this technology. Can someone point me to a very basic tutorial that clearly delineates this. Or, can they give me a couple steps like: "You have to implement A, B & C and then pass your URL into C.foo()"?
I've tried the Getting Started doc for both libraries but they both start with "first we'll implement a Web service" and don't clearly delineate (to me, at least) where that leaves off and pure Odata sets in.
Thanks.
The following is the code that will help you to get started for using data from a service exposing via OData.(using Apache Olingo).
URL url=new URL(/*your url*/);
HttpURLConnection conn=(HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty(HttpHeaders.ACCEPT,HttpContentType.APPLICATION_XML);
conn.connect();
InputStream content=conn.getInputStream();
Edm edm = EntityProvider.readMetadata(content, false);
After this you can use static methods of EntityProvider class for carrying out various operations like read,update,write
If you are using odata4j go with the following code
ODataConsumer demo_consumer= ODataConsumers.create(/*your URL*/);
Enumerable<EntitySetInfo> demo_entitySetList = demo_consumer.getEntitySets();
for (EntitySetInfo entitySet : entitySetList) {
System.out.println(entitySet.getHref());
}
this sounds very like how we read rss or other data feeds
Since you have a url, this can be read by a Http Connector or even a polling http connector.
The data can be streamed using a Java input stream the default behavior or converted to a string (object to string).
A simple java component using (OData4j) can process your content .. it sounds like 2 simple components on a mule flow.
R

Using webservice created in wsimport JAX-WS

This is a pretty basic question but I don't really see an answer anywhere. I created a webservice using wsimport and a wsdl.
It created a large number of files. Most of them appear to be beans representing the methods of the webservice. There are also classes called Gateway, Gateway SOAP, and ObjectFactory. How exactly do you go about actually calling the web-service with these methods?
You should do something like this:
Gateway svc = new Gateway();
GatewaySOAP port = svc.getGatewaySOAP();
MyRequestClass rq = new MyRequestClass();
rq.setSomething(2);
MyResponseClass rs = port.doMyVeryOwnJob(rq);
System.out.println("Result is: " + rs.getSomethingElse());

Java: Send POST request to different website from backend

I'm working on a Java application using Seam and I need to forward to a page on a different site, sending some POST data along with it. It needs to occur from the backend.
Any ideas how I can accomplish this?
EDIT: I don't merely need to receive the response - I need to actually direct the user to the new page.
Take a look at HttpClient, you should be able to generate your POST request programatically from the backend, e.g:
PostMethod post = new PostMethod("http://myserver/page.jsp");
post.addParameter("parameter1", "value1");
post.addParameter("parameter2", "value2");
More details here:
http://weblogs.java.net/blog/2006/11/01/quick-intro-httpclient

Restlet response to POST request

First off, I'm using an older version of Restlet (1.1).
Secondly, I'm not sure I'm doing the correct thing. Here's what I'm trying to do...
I'm creating a reporting service (resource). I'd like my service to listen for POST requests. The body of the request will contain the report definition. I'd like the response to be the CSV file generated by the service (the report). Is responding to a POST request in this manner OK from a REST standpoint (if not, then how to refine this resource)?
I can't seem to figure out how the acceptRepresentation() generates the response. I've tried setting the Representation parameter passed into the method to a new FileRepresentation. I've also tried to utilize the represent() method, but it doesn't seem like that method is called as part of the POST processing.
How can I accomplish this seeming easy task?
Calling the getResponse().setEntity() method from acceptRepresentation() will accept the new FileRepresentation and accomplish what I'd like to.

How to make a SOAP call in Java

This seems like it should be simple, but maybe I'm missing something. I just want to make a SOAP call in Java, preferrably using only built-in APIs. I'm a little overwhelmed looking at javax.xml.soap package in the Java documentation. I have tried searching Google, but it seems like all the results are from 2000-2002, and they are all talking about libraries that can be used for SOAP calls (before SOAP libraries were built in, I guess).
I don't need to handle the SOAP request; only make one. This site has an example that is pretty simple, but it doesn't use the built-in Java SOAP libraries. How would I do basically the same thing using core Java?
// Create the parameters
Vector params = new Vector( );
params.addElement(
new Parameter("flightNumber", Integer.class, flightNumber, null));
params.addElement(
new Parameter("numSeats", Integer.class, numSeats, null));
params.addElement(
new Parameter("creditCardType", String.class, creditCardType, null));
params.addElement(
new Parameter("creditCardNumber", Long.class, creditCardNum, null));
// Create the Call object
Call call = new Call( );
call.setTargetObjectURI("urn:xmltoday-airline-tickets");
call.setMethodName("buyTickets");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setParams(params);
// Invoke
Response res = call.invoke(new URL("http://rpc.middleearth.com"), "");
// Deal with the response
Soap has changed a lot since the early days. You can do things like what you describe, but it is not common.
A more common practice now is to use a wsdl2java tool to generate a client API from a WSDL description of the service. That will give you a nice, clean, API to call.
Apache CXF is one place to go for this sort of thing.
One proviso is rpc/encoded. If you are dealing with an old service, it might be rpc/encoded, and in that case your best bet is Apache Axis 1.x. Everything else has run away from rpc/encoded.
The simplest way is soap-ws library:
https://github.com/reficio/soap-ws
SoapClient client = SoapClient.builder()
.endpointUrl("http://rpc.middleearth.com")
.build();
client.post(envelope);

Categories