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 Vibhor_Sharma <vs...@gryphonnetworks.com> on 2007/05/01 18:58:48 UTC

Rest Support on Axis2 (Need urgent help)

Hi 
     I have been sucessfully able to invoke a web service deployed on Axis2 using the Axiom API. This was achived using the REST interface. 
One thing that really confuses me is that even if we are sending a POST request why do i see a soap request (refer to The HTTP Post Request that reaches the web server section at the end of the mail) reaching the server ?  
 
So does the AXIOM API convert the request to a SOAP request?  and the engine only understands the SOAP request?
 
Now if i have to send this request from a web application/HTML page then can i just create a string object with the following section and the REST interface should still work right? The axis2 engine should not complain that it expects some information that is not there in the incoming request.
This is just one of the simple request. There are more complex XML requests that i have to send through REST.
 

<ns2:validateLicense xmlns:ns2="http://webservices.gryphonnetworks.com/clientadmin">

<ns2:validateInfo>

<ns1:clientUserID xmlns:ns1="http://valueobjects.webservices.gryphonnetworks.com/xsd">2</ns1:clientUserID>

<ns1:licenseID xmlns:ns1="http://valueobjects.webservices.gryphonnetworks.com/xsd">xyz</ns1:licenseID>

</ns2:validateInfo>

</ns2:validateLicense>

 
 
 
Code to generate the Post request
 

public class TestHttpPOSTClient {

 private static String toEpr = "http://localhost:8080/axis2/services/ClientAdmin";
 public static void main(String[] args) throws AxisFault, InterruptedException {
   ServiceClient client = new ServiceClient();
         Options options = new Options();
         
         options.setTo(new EndpointReference(toEpr));
      options.setAction("urn:validateLicense");
 
         options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
         options.setProperty(Constants.Configuration.HTTP_METHOD,
    Constants.Configuration.HTTP_METHOD_POST);
    client.setOptions(options);
   OMElement result = client.sendReceive(getPayload());
   try {
             XMLStreamWriter writer = XMLOutputFactory.newInstance()
                     .createXMLStreamWriter(System.out);
             result.serialize(writer);
             writer.flush();
         } catch (XMLStreamException e) {
             e.printStackTrace();
         } catch (FactoryConfigurationError e) {
             e.printStackTrace();
         }
} 

private static OMElement getPayload() {
  OMFactory fac = OMAbstractFactory.getOMFactory();
  //ns1="http://valueobjects.webservices.gryphonnetworks.com/xsd <https://outlook.boston.gryphonnetworks.com/exchweb/bin/redir.asp?URL=http://valueobjects.webservices.gryphonnetworks.com/xsd> "
  //ns2="http://webservices.gryphonnetworks.com/clientadmin <https://outlook.boston.gryphonnetworks.com/exchweb/bin/redir.asp?URL=http://webservices.gryphonnetworks.com/clientadmin> "
  OMNamespace ns1 = fac.createOMNamespace("http://valueobjects.webservices.gryphonnetworks.com/xsd","ns1 <https://outlook.boston.gryphonnetworks.com/exchweb/bin/redir.asp?URL=http://valueobjects.webservices.gryphonnetworks.com/xsd%22,%22ns1> ");
  OMNamespace ns2 = fac.createOMNamespace("http://webservices.gryphonnetworks.com/clientadmin","ns2 <https://outlook.boston.gryphonnetworks.com/exchweb/bin/redir.asp?URL=http://webservices.gryphonnetworks.com/clientadmin%22,%22ns2> ");
  OMElement validateLicenseRequest  =  fac.createOMElement("validateLicense", ns2);
   OMElement validateInfo = fac.createOMElement("validateInfo", ns2);
  
   OMElement clientUserIDValue = fac.createOMElement("clientUserID", ns1);
   clientUserIDValue.setText("2");
   validateInfo.addChild(clientUserIDValue);
   
   OMElement licenseIDValue = fac.createOMElement("licenseID", ns1);
   licenseIDValue.setText("xyz");
   validateInfo.addChild(licenseIDValue);
   validateLicenseRequest.addChild(validateInfo);
   return validateLicenseRequest;
 }

 
The HTTP Post Request that reaches the web server.
 
<?xml version='1.0' encoding='utf-8'?>
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

<soapenv:Header />

<soapenv:Body>

<ns2:validateLicense xmlns:ns2="http://webservices.gryphonnetworks.com/clientadmin">

<ns2:validateInfo>

<ns1:clientUserID xmlns:ns1="http://valueobjects.webservices.gryphonnetworks.com/xsd">2</ns1:clientUserID>

<ns1:licenseID xmlns:ns1="http://valueobjects.webservices.gryphonnetworks.com/xsd">xyz</ns1:licenseID>

</ns2:validateInfo>

</ns2:validateLicense>

</soapenv:Body>

</soapenv:Envelope>