You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Kumar, Amit {PBSG}" <am...@pbsg.com> on 2007/07/31 18:26:36 UTC
Axis 1.3 webservice client
Hi,
I am new to Axis. I am trying to work on a poc where I need to invoke a
web service using Axis 1.3. The webservice is developed using TIBCO
Businessworks. I need to write the Axis client to invoke this service
and get the result. I have the wsdl. I developed a client but getting
few tomcat 404 errors.. I am sure that I am missing some steps.
Can anybody please help me understand the steps I need to write a Axis
client?
When do I need to WSDL2Java?
If possible pls provide a Axis 1.3 client sample?
Thanks in advance...
Best regards
The client code is below:
----------------------------
The client code is :
------------------------------
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBody;
import org.apache.axis.message.SOAPEnvelope;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
/**
public class webserviceCall {
private static DocumentBuilder db;
public static void main(String [] args) throws Exception {
String endpoint =
"http://localhost:7989/Processes/ProvideSTAR2Owner/";
// initialize variables
Document reqDoc = null;
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();
Document reqDoc2 = db.newDocument();
SOAPEnvelope se = new SOAPEnvelope();
SOAPBody sb = (SOAPBody) se.getBody();
@SuppressWarnings("unused")
SOAPEnvelope result;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
Element e = null;
Element f = null;
Node n = null;
reqDoc =
impl.createDocument("","inputMessage",reqDoc2.getDoctype());
Element root=reqDoc.getDocumentElement();
String[] id =
{"ns0:BusinessID","ns0:SourceSystemID","ns0:SourceSystemName","ns0:Reque
stType"};
String[] desc = {"STAR2","STAR2","STAR2","OWNER"};
f = reqDoc.createElement("ns0:Header");
f.setAttribute("xmlns:ns0","http://www.ABC.com/NorthAmerica/PCNA/STAR2/R
equest");
for (int i=0;i<id.length;i++) {
e = reqDoc.createElement(id[i]);
n = reqDoc.createTextNode(desc[i]);
e.appendChild(n);
f.appendChild(e);
}
root.appendChild(f);
OutputFormat format = new OutputFormat (reqDoc);
XMLSerializer output = new XMLSerializer(System.out,format);
//XMLSerializer output = new XMLSerializer(new
BufferedWriter(new StringWriter()),format);
output.serialize(reqDoc);
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(endpoint));
//call.setPortName(new
QName("/Processes/ProvideSTAR2Owner","GetSTAR2Owner"));
call.setOperationName(new QName("GetSTAR2Owner"));
//sb.setQName(new
QName("http://localhost:7989/Processes/ProvideSTAR2Owner","ProvideSTAR2O
wner"));
sb.addDocument(reqDoc);
result = call.invoke(se);
}
}
-------------------
Below is the WSDL
-------------------
<?xml version="1.0" encoding="UTF-8"?>
<!--Created by TIBCO WSDL-->
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.ABC.com/NorthAmerica/PCNA/STAR2OwnerList/GetSTAR2O
wnerImpl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns0="http://www.ABC.com/NorthAmerica/PCNA/STAR2/Request"
xmlns:ns1="http://www.ABC.com/NorthAmerica/PCNA/STAR2/Owner"
name="Untitled"
targetNamespace="http://www.ABC.com/NorthAmerica/PCNA/STAR2OwnerList/Get
STAR2OwnerImpl">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.ABC.com/NorthAmerica/PCNA/STAR2/Owner"
targetNamespace="http://www.ABC.com/NorthAmerica/PCNA/STAR2/Owner"
elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xsd:element name="Owner">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OwnerID" type="xsd:string"/>
<xsd:element name="AddressID"
type="xsd:string"/>
<xsd:element name="MSANumber"
type="xsd:string"/>
<xsd:element name="OwnerINITNGSouce"
type="xsd:string"/>
<xsd:element name="OwnerType"
type="xsd:string"/>
<xsd:element name="OwnerName"
type="xsd:string"/>
<xsd:element name="OwnerStatus"
type="xsd:string"/>
<xsd:element name="OwnerCD" type="xsd:string"/>
<xsd:element name="CustomerGLN"
type="xsd:string"/>
<xsd:element name="CustomerToLINXNumber"
type="xsd:string"/>
<xsd:element name="InfoUSANumber"
type="xsd:string"/>
<xsd:element name="FedEXTaxID"
type="xsd:string"/>
<xsd:element name="DUNSPlusFour"
type="xsd:string"/>
<xsd:element name="MSAHGHROwnerNumber"
type="xsd:string"/>
<xsd:element name="OwneNumber"
type="xsd:string"/>
<xsd:element name="DistributorFlag"
type="xsd:string"/>
<xsd:element name="Status" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="OwnerGroup">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns1:Owner"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="STAR2Owner">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns1:OwnerGroup"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.ABC.com/NorthAmerica/PCNA/STAR2/Request"
targetNamespace="http://www.ABC.com/NorthAmerica/PCNA/STAR2/Request"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="BusinessID" type="xsd:string"/>
<xsd:element name="Header">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns0:BusinessID"
minOccurs="0"/>
<xsd:element ref="ns0:SourceSystemID"
minOccurs="0"/>
<xsd:element ref="ns0:SourceSystemName"
minOccurs="0"/>
<xsd:element ref="ns0:RequestType"
minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RequestType" type="xsd:string"/>
<xsd:element name="SourceSystemID" type="xsd:string"/>
<xsd:element name="SourceSystemName" type="xsd:string"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="OwnerRequest">
<wsdl:part name="HeaderInput" element="ns0:Header"/>
</wsdl:message>
<wsdl:message name="OwnerResponse">
<wsdl:part name="ResponseOutput" element="ns1:STAR2Owner"/>
</wsdl:message>
<wsdl:portType name="OwnerPortType">
<wsdl:operation name="GetSTAR2Owner">
<wsdl:input message="tns:OwnerRequest"/>
<wsdl:output message="tns:OwnerResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SOAPEventSourceBinding"
type="tns:OwnerPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetSTAR2Owner">
<soap:operation style="document"
soapAction="/Processes/ProvideSTAR2Owner"/>
<wsdl:input>
<soap:body use="literal" parts="HeaderInput"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" parts="ResponseOutput"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ProvideSTAR2Owner">
<wsdl:port name="SOAPEventSource"
binding="tns:SOAPEventSourceBinding">
<soap:address
location="http://localhost:7989/Processes/ProvideSTAR2Owner"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org