Solved

Java Client to call Weblogic WebService

Posted on 2006-06-15
9
1,345 Views
Last Modified: 2012-06-22
Hi guys,

I have a webservice that is deployed, running and working on a Weblogic Server (lets for now use my localhost and port 7001).

I want to create a simple client in Java to test it (not just test, but also use the info that it returns). I used the same code on another service and it worked, but this service accepts a string and returns a string - easy.

My webservice returns a List of objects. The objects are of a type that I defined as SchemeExclusionApplicabilityVO. I read that I need to use the "MapTypes" and "QName" methods in order to define my types, but I can't get it right. I don't know where to look up the values to pass as parameters. I have the wsdl file and also the xml that gets returned as result. Pasted my test code below. Also an extract of the result xml.

This is the error that I get:
SOAP-ENV:Client, No Deserializer found to deserialize a ':result' using encoding style 'http://schemas.xmlsoap.org/soap/encoding/'

CODE:
  URL url = new URL( "http://localhost:7001/XXX/ExclusionService/ChronicExclusionService" );
     String urn = "urn:demo1:exchange"; //NOT SURE OF THIS ONE - LEFT IT LIKE THE EXAMPLE I FOUND
     Call call = new Call();
     SOAPMappingRegistry smr = new SOAPMappingRegistry();
     BeanSerializer beanSer = new BeanSerializer();
     //DONT KNOW IF THE STATEMENT BELOW IS CORRECT - DOUBT IT
     smr.mapTypes(Constants.NS_URI_SOAP_ENC,
     new QName("java:za.co.xxxx.benefitScheme.services.vo", "SchemeExclusionApplicabilityVO"),
     SchemeExclusionApplicabilityVO.class, beanSer, beanSer);

     call.setTargetObjectURI( urn );
     call.setMethodName( "getAllApplicableExclusionsPerDiagnosis" );
     call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
     call.setSOAPMappingRegistry(smr);

     Vector params = new Vector();
     params.addElement( new Parameter( "string", String.class, "80000", Constants.NS_URI_SOAP_ENC ) );
     params.addElement( new Parameter( "string0", String.class, "0", Constants.NS_URI_SOAP_ENC ) );
     params.addElement( new Parameter( "string1", String.class, "7777", Constants.NS_URI_SOAP_ENC ) );
     params.addElement( new Parameter( "string2", String.class, "20060610", Constants.NS_URI_SOAP_ENC ) );
     call.setParams( params );
     
    Response response = call.invoke( url, "" );

XML -
<!--RESPONSE.................-->
<env:Envelope  xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <env:Body>
  <m:getAllApplicableExclusionsPerDiagnosisResponse    xmlns:m="http://localhost:7001/"
    env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <result     soapenc:arrayType="xsd:anyType[1]">
    <xsd:anyType      xmlns:ns100="java:za.co.xxxx.benefitScheme.services.vo"
      xsi:type="ns100:SchemeExclusionApplicabilityVO">
     <definitePossibleFlag       xsi:type="xsd:string">P</definitePossibleFlag>
     <exclusionType       xsi:type="xsd:string">37</exclusionType>
     <exclusionTypeDescription       xsi:type="xsd:string">An Exclusions</exclusionTypeDescription>
     <reasonCode       xsi:type="xsd:string">3145</reasonCode>
     <reasonDescription       xsi:type="xsd:string">This is a descr</reasonDescription>
    </xsd:anyType>
   </result>
  </m:getAllApplicableExclusionsPerDiagnosisResponse>
 </env:Body>
</env:Envelope>

0
Comment
Question by:Zenoe
  • 3
  • 3
  • 2
9 Comments
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 65 total points
ID: 16911020
I would use WSDL 2 Java from Apache Axis and create proxy/ stubs for the web-service. Then create a stub object and call its methods locally like any normal object/ method, it will result in calls to the web-service and will take care of serialization/ de-serialization itself.

http://ws.apache.org/axis/java/ant/axis-wsdl2java.html

http://ws.apache.org/axis/java/reference.html
0
 
LVL 4

Expert Comment

by:astorer
ID: 16918212
mayankeagle is absolutely right.  This is the best solution.
0
 

Author Comment

by:Zenoe
ID: 16932015
Hi guys,

Thanks for the reply, but even though I read somewhere else that this might be the fastest way, I don't think it will work in my situation. Firstly, the environment I am working in - I can't just use any other technology, it is not just my own application where I can pick and choose. Then I also had a very quick read through this site and what it does. I am not sure whether the fact that it recreates the objects locally is such a viable solution in my case (does it regenerate the source locally?), as the people who owns this webservice might change it at any time (without me being notified). Doesn't that mean that my service will be incorrect until I regenerate the code?

If anyone knows, I basically need to know what to pass to the following statements in the case of a LIST of objects being returned (Can I get the parameter values from the wsdl or result soap message?):

1) String urn = "urn:demo1:exchange";

2) smr.mapTypes(Constants.NS_URI_SOAP_ENC,
     new QName("java:za.co.xxxx.benefitScheme.services.vo", "SchemeExclusionApplicabilityVO"), SchemeExclusionApplicabilityVO.class, beanSer, beanSer);

Thanks :)
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 16932030
>> I can't just use any other technology

The technology being recommended is from Apache and is also free of cost, and its used in production systems too. Instead of you handling the serialization/ de-serialization of messages, you are letting it handle all that for you - and its tried/ tested.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Zenoe
ID: 16936823
mayankeagle, I didn't mean the statement in a negative light. After your posts I read up a bit on it, but unfortunately it is not my call. The environment I am involved in is much larger than me and to get the decision made by the right people will take too long. I was hoping to solve this thing quickly. The code that I posted is suppose to solve the problem according to a couple of sites and forums on the internet, but I cannot figure out where to get the precise values to pass to the mapping methods. If there is no other way, I can probably put a suggestion forward to the "powers that be", but I am still curious as to the correct usage of the above mentioned code :)
0
 
LVL 4

Accepted Solution

by:
astorer earned 65 total points
ID: 16938319
Looking at your code, you use  SOAPMappingRegistry and  BeanSerializer. Can you check what packages they are in?

I think you might find that they are Apache Axis.  It would appear that you are already using Apache Axis but maybe not in the best way.  The best way to use Axis (or any soap toolkit) on the client side is:
1. start with the WSDL from your server
2. run it through a tool such as WSDL2Java (Axis gives that to you) - this generates mappings XML to/from java and a clientside stub.  That stub looks after all (de)serialization for you.
3. call that client stub.

You don't need to worry about any code involving serializers or Map Types.
good luck
Andrew
0
 

Author Comment

by:Zenoe
ID: 17120637
I don't fully agree with the point split. I feel that my question hasn't been adequately answered. I never wanted to know how to create a webservice client, I wanted to know how the code that I posted works when dealing with complex types. I tried to bring this across everytime - it might not have been the ideal solution, but in the environment I was coding this is what I wanted to do. I know it can work, because I tried it on a simple type. I appreciate the input from mayankeagle & astorer, but I didn't get the information I needed. Any other suggestions?
0
 
LVL 4

Expert Comment

by:astorer
ID: 17120819
It appears to me your question has been answered.  If you want to consume web services , use Apache Axis.  It appears (from some of your posts) that you are using it, but then you appear to be using it incorrectly.

So, the answer is that if you want complex types in your interface, use Apache Axis correctly.

If you insist that you have no choice there and that you will use Axis in a way that it was not designed, then the next investigation is to look how Apache Axis handles complex types.  You can find that level of information:
 - in the classes generated by Axis's WSDL2Java
 - in the WSDD (the deployment descriptor) generated by Axis's WSDL2Java

This is non trivial.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now