Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 15641 invoked from network); 24 Nov 2005 12:57:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Nov 2005 12:57:19 -0000 Received: (qmail 59421 invoked by uid 500); 24 Nov 2005 12:57:16 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 59312 invoked by uid 500); 24 Nov 2005 12:57:15 -0000 Mailing-List: contact axis-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-dev@ws.apache.org Received: (qmail 59301 invoked by uid 99); 24 Nov 2005 12:57:15 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Nov 2005 04:57:15 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [209.68.5.16] (HELO relay02.pair.com) (209.68.5.16) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 24 Nov 2005 04:58:46 -0800 Received: (qmail 13179 invoked from network); 24 Nov 2005 12:56:51 -0000 Received: from unknown (HELO ?127.0.0.1?) (unknown) by unknown with SMTP; 24 Nov 2005 12:56:51 -0000 X-pair-Authenticated: 220.247.240.73 Message-ID: <4385B891.4020703@wso2.com> Date: Thu, 24 Nov 2005 18:56:49 +0600 From: Thilini User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: axis-dev@ws.apache.org Subject: REST support for Axis2 client side Content-Type: multipart/mixed; boundary="------------000400040404050806070409" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------000400040404050806070409 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi all, I've started to implement REST for Axis2 client side using the rules found on WSDL 2.0. I completed implementing parts within the CommonsHTTPTransportSender with several test cases. The test cases however run against the yahoo endpoint so I've excluded these test cases from the build for the time. I would appreciate if somebody can review this and apply this attached patch. Thanks, Thilini --------------000400040404050806070409 Content-Type: text/plain; name="patch-24-11.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-24-11.patch" Index: modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java =================================================================== --- modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (revision 348719) +++ modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (working copy) @@ -28,6 +28,7 @@ import org.apache.axis2.description.TransportOutDescription; import org.apache.axis2.handlers.AbstractHandler; import org.apache.axis2.i18n.Messages; +import org.apache.axis2.om.OMAbstractFactory; import org.apache.axis2.om.OMAttribute; import org.apache.axis2.om.OMElement; import org.apache.axis2.om.impl.OMOutputImpl; @@ -59,12 +60,14 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.Iterator; public class CommonsHTTPTransportSender @@ -104,7 +107,69 @@ public CommonsHTTPTransportSender() { } //default - + + public RequestData createRequest(MessageContext msgContext) { + //This used to obtain two strings to go with the url and to pass in the body when doing + //POST with application/x-www-form-urlencoded + RequestData data = new RequestData(); + String contentType = findContentType(true,msgContext); + OMElement dataOut = msgContext.getEnvelope().getBody().getFirstElement(); + + Iterator iter1 = dataOut.getChildElements(); + ArrayList paraList = new ArrayList(); + ArrayList urlList = new ArrayList(); + + //String[] s = new String[] {"abc","def","pqr"}; + String[] s = new String[] {}; + String ns = "http:/rwrfr"; + OMElement bodypara = OMAbstractFactory.getOMFactory().createOMElement("dummy", null); + + while(iter1.hasNext()){ + OMElement ele = (OMElement)iter1.next(); + boolean has = false; + + for(int i = 0;i**org/apache/axis2/mail/*.java **org/apache/axis2/soap12testing/soap12testsuite/*.java **/ScenarioST1Test.java + + **/GetTest.java + **/PostTest.java + **/RESTGetTest.java **/*Test.java Index: modules/integration/test/org/apache/axis2/rest/GetTest.java =================================================================== --- modules/integration/test/org/apache/axis2/rest/GetTest.java (revision 0) +++ modules/integration/test/org/apache/axis2/rest/GetTest.java (revision 0) @@ -0,0 +1,73 @@ +package org.apache.axis2.rest; + +import java.io.ByteArrayInputStream; + +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Call; +import org.apache.axis2.engine.util.TestConstants; +//import org.apache.axis2.clientapi.RESTCall; +import org.apache.axis2.om.OMAbstractFactory; +import org.apache.axis2.om.OMElement; +import org.apache.axis2.om.OMFactory; +import org.apache.axis2.om.OMNamespace; +import org.apache.axis2.om.impl.OMOutputImpl; +import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.TestCase; + +public class GetTest extends TestCase implements TestConstants { + + public void testRESTGet() throws Exception{ + + String epr = "http://localhost:8080/axis2/services/MyService"; + + String xml = + ""+ + "Hello"+ + ""; + + byte arr[] = xml.getBytes(); + ByteArrayInputStream bais = new ByteArrayInputStream(arr); + + XMLStreamReader reader = null; + try { + XMLInputFactory xif= XMLInputFactory.newInstance(); + reader= xif.createXMLStreamReader(bais); + } catch (XMLStreamException e) { + e.printStackTrace(); + } + StAXOMBuilder builder= new StAXOMBuilder(reader); + OMElement data = builder.getDocumentElement(); + + OMFactory fac = OMAbstractFactory.getOMFactory(); + /*OMNamespace omNs = fac.createOMNamespace("http://example1.org/example1", "example1"); + OMElement payload = fac.createOMElement("echo", omNs); + OMElement value = fac.createOMElement("Text", omNs); + value.addChild(fac.createText(value, "Hello")); + payload.addChild(value);*/ + + //RESTCall call = new RESTCall(); + //OMElement val = fac. + Call call = new Call(); + call.setTo(new EndpointReference(epr)); + call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP, false); + call.set(Constants.Configuration.ENABLE_REST,Constants.VALUE_TRUE); + call.set(Constants.Configuration.ENABLE_REST_THROUGH_GET,Constants.VALUE_TRUE); + + //if post is through GET of HTTP + //OMElement response = call.invokeBlocking("webSearch",data); + OMElement response = call.invokeBlocking("webSearch",data); + //OMElement response = call.invokeBlocking(); + XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out); + response.serialize(new OMOutputImpl(writer)); + writer.flush(); + } +} + Index: modules/integration/test/org/apache/axis2/rest/PostTest.java =================================================================== --- modules/integration/test/org/apache/axis2/rest/PostTest.java (revision 0) +++ modules/integration/test/org/apache/axis2/rest/PostTest.java (revision 0) @@ -0,0 +1,108 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.axis2.rest; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Call; +import org.apache.axis2.engine.util.TestConstants; +import org.apache.axis2.om.OMAbstractFactory; +import org.apache.axis2.om.OMElement; +import org.apache.axis2.om.OMFactory; +import org.apache.axis2.om.OMNamespace; +import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import java.io.ByteArrayInputStream; +import java.io.StringWriter; + +import junit.framework.TestCase; + +/** + * Sample for synchronous single channel blocking service invocation. + * Message Exchage Pattern IN-OUT + */ +public class PostTest extends TestCase implements TestConstants{ + //private static EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/MyService"); + //private static EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:80/axis2/services/MyService"); + private static EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:8070/onca/xml"); + + public void testRESTPost() throws Exception{ + try { + // OMElement payload = ClientUtil.getEchoOMElement(); + /*OMFactory fac = OMAbstractFactory.getOMFactory(); + OMNamespace omNs = fac.createOMNamespace("http://example1.org/example1", "example1"); + OMElement payload = fac.createOMElement("echo", omNs); + OMElement value = fac.createOMElement("Text", omNs); + value.addChild(fac.createText(value, "Hello")); + payload.addChild(value);*/ + + String xml = + ""+ + "AWSECommerceService"+ + "03WM83XFMP0X52C7A9R2"+ + "ItemSearch"+ + "Books"+ + "Sanjiva,Web,Services"+ + "Request,Small"+ + ""; + + byte arr[] = xml.getBytes(); + ByteArrayInputStream bais = new ByteArrayInputStream(arr); + + XMLStreamReader reader = null; + try { + XMLInputFactory xif= XMLInputFactory.newInstance(); + reader= xif.createXMLStreamReader(bais); + } catch (XMLStreamException e) { + e.printStackTrace(); + } + StAXOMBuilder builder= new StAXOMBuilder(reader); + OMElement websearch = builder.getDocumentElement(); + + Call call = new Call(); + call.setTo(targetEPR); + call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP,false); + call.set(Constants.Configuration.ENABLE_REST,Constants.VALUE_TRUE); + //call.set(Constants.Configuration.ENABLE_REST_THROUGH_GET,Constants.VALUE_TRUE); + call.set("content Type","application/x-www-form-urlencoded"); + + //Blocking invocation + //OMElement result = call.invokeBlocking("echo",payload); + OMElement result = call.invokeBlocking("echo",websearch); + + StringWriter writer = new StringWriter(); + result.serialize(XMLOutputFactory.newInstance() + .createXMLStreamWriter(writer)); + writer.flush(); + + System.out.println(writer.toString()); + + } catch (AxisFault axisFault) { + axisFault.printStackTrace(); + } catch (XMLStreamException e) { + e.printStackTrace(); + } + } + } + Index: modules/integration/test/org/apache/axis2/rest/RESTGetTest.java =================================================================== --- modules/integration/test/org/apache/axis2/rest/RESTGetTest.java (revision 0) +++ modules/integration/test/org/apache/axis2/rest/RESTGetTest.java (revision 0) @@ -0,0 +1,92 @@ +/* + * Created on Nov 24, 2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.apache.axis2.rest; + +import java.io.ByteArrayInputStream; + +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.TestCase; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Call; +//import org.apache.axis2.client.*; +import org.apache.axis2.engine.util.TestConstants; +import org.apache.axis2.om.OMElement; +import org.apache.axis2.om.impl.OMOutputImpl; +import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder; + +/** + * @author Thilini + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ + +//This Sample test Client is written for Yahoo Web Search + +public class RESTGetTest extends TestCase implements TestConstants{ + + public void testRESTGet(){ + //String epr = "http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=ApacheRestDemo&query=finances&format=pdf"; + //String epr = "http://127.0.0.1:8080/WebSearchService/V1/webSearch"; + //String epr = "http://webservices.amazon.com/onca/xml"; + String epr = "http://api.search.yahoo.com/WebSearchService/V1/webSearch"; + + String xml = + ""+ + "ApacheRestDemo"+ + "finances"+ + "pdf"+ + ""; + + byte arr[] = xml.getBytes(); + ByteArrayInputStream bais = new ByteArrayInputStream(arr); + + XMLStreamReader reader = null; + try { + XMLInputFactory xif= XMLInputFactory.newInstance(); + reader= xif.createXMLStreamReader(bais); + } catch (XMLStreamException e) { + e.printStackTrace(); + } + StAXOMBuilder builder= new StAXOMBuilder(reader); + OMElement data = builder.getDocumentElement(); + + try { + //RESTCall call = new RESTCall(); + Call call = new Call(); + call.setTo(new EndpointReference(epr)); + call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP, false); + call.set(Constants.Configuration.ENABLE_REST,Constants.VALUE_TRUE); + call.set(Constants.Configuration.ENABLE_REST_THROUGH_GET,Constants.VALUE_TRUE); + + //if post is through GET of HTTP + OMElement response = call.invokeBlocking("webSearch",data); + //OMElement response = call.invokeBlocking(); + XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out); + response.serialize(new OMOutputImpl(writer)); + writer.flush(); + } catch (AxisFault e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (XMLStreamException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (FactoryConfigurationError e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } +} --------------000400040404050806070409--