├── .gitignore ├── ksoap2-base ├── .gitignore ├── src │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── ksoap2 │ │ │ ├── serialization │ │ │ ├── package.html │ │ │ ├── FwdRef.java │ │ │ ├── AttributeInfo.java │ │ │ ├── MarshalDate.java │ │ │ ├── MarshalBase64.java │ │ │ ├── DM.java │ │ │ ├── KvmSerializable.java │ │ │ ├── Marshal.java │ │ │ ├── SoapPrimitive.java │ │ │ ├── MarshalHashtable.java │ │ │ ├── PropertyInfo.java │ │ │ └── SoapObject.java │ │ │ ├── package.html │ │ │ ├── transport │ │ │ ├── ServiceConnection.java │ │ │ └── Transport.java │ │ │ ├── SoapFault.java │ │ │ └── SoapEnvelope.java │ └── test │ │ └── java │ │ └── org │ │ └── ksoap2 │ │ ├── serialization │ │ ├── PropertyInfoTest.java │ │ ├── DMTest.java │ │ ├── SoapPrimitiveTest.java │ │ ├── MarshalDateTest.java │ │ ├── MarshalHashtableTest.java │ │ ├── MarshalBase64Test.java │ │ └── SoapObjectTest.java │ │ ├── transport │ │ ├── TransportTestCase.java │ │ └── mock │ │ │ ├── ComplexParameter.java │ │ │ ├── MockTransport.java │ │ │ ├── ComplexResponse.java │ │ │ ├── MockXmlSerializer.java │ │ │ └── MockXmlPullParser.java │ │ ├── SoapEnvelopeTest.java │ │ └── SoapFaultTest.java └── pom.xml ├── ksoap2-j2se ├── .gitignore ├── pom.xml └── src │ ├── test │ └── java │ │ └── org │ │ └── ksoap2 │ │ ├── transport │ │ └── HttpTransportSETest.java │ │ └── serialization │ │ └── MarshalFloatTest.java │ └── main │ └── java │ └── org │ └── ksoap2 │ ├── serialization │ └── MarshalFloat.java │ └── transport │ ├── ServiceConnectionSE.java │ └── HttpTransportSE.java ├── ksoap2-midp ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── ksoap2 │ └── transport │ ├── ServiceConnectionMidp.java │ └── HttpTransport.java ├── ksoap2-android ├── .gitignore ├── src │ ├── test │ │ └── java │ │ │ └── org │ │ │ └── ksoap2 │ │ │ └── NewApiSample.java │ └── main │ │ └── java │ │ └── org │ │ └── ksoap2 │ │ └── transport │ │ ├── AndroidServiceConnection.java │ │ └── AndroidHttpTransport.java └── pom.xml ├── ksoap2-extras ├── .gitignore ├── pom.xml └── src │ ├── test │ └── java │ │ └── org │ │ └── ksoap2 │ │ └── transport │ │ └── HttpTransportBasicAuthTest.java │ └── main │ └── java │ └── org │ └── ksoap2 │ └── transport │ └── HttpTransportBasicAuth.java ├── ksoap2-samples ├── .gitignore ├── src │ └── main │ │ └── java │ │ └── org │ │ └── ksoap2 │ │ └── samples │ │ ├── amazon │ │ ├── search │ │ │ ├── messages │ │ │ │ ├── BaseObject.java │ │ │ │ ├── Request.java │ │ │ │ ├── ItemSearchResponse.java │ │ │ │ ├── LiteralArrayVector.java │ │ │ │ ├── Book.java │ │ │ │ ├── BookItems.java │ │ │ │ └── BookAttributes.java │ │ │ └── AmazonSearchClient.java │ │ └── AmazonDemo.java │ │ ├── soccer │ │ ├── StadiumNamesResult.java │ │ ├── LiteralArrayVector.java │ │ └── WorldCupSoccer2006Client.java │ │ ├── axis │ │ └── quotes │ │ │ └── AxisStockQuoteExample.java │ │ └── quotes │ │ └── StockQuoteDemo.java └── pom.xml ├── ksoap2-servlet ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── ksoap2 │ └── servlet │ └── SoapServlet.java ├── ksoap2-samples-axis ├── .gitignore ├── src │ └── main │ │ ├── resources │ │ └── AxisService.wsdd │ │ └── java │ │ └── net │ │ └── wessendorf │ │ ├── ws │ │ ├── AxisService.java │ │ └── CustomObject.java │ │ └── j2me │ │ └── SoapDemo.java └── pom.xml ├── LICENSE.txt ├── ksoap2-android-assembly └── pom.xml ├── eclipseTemplates.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-base/.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-j2se/.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-midp/.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-android/.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-extras/.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-samples/.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-servlet/.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-samples-axis/.gitignore: -------------------------------------------------------------------------------- 1 | # Project output 2 | bin/ 3 | target*/ 4 | *.log 5 | 6 | # Project config files 7 | .settings/ 8 | .project 9 | .classpath 10 | 11 | -------------------------------------------------------------------------------- /ksoap2-android/src/test/java/org/ksoap2/NewApiSample.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2; 2 | 3 | /** 4 | * Just a scratchpad for some API ideas. 5 | */ 6 | public class NewApiSample 7 | { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

This package contains support for the Soap Serialization 8 | specification. Please refer to the documentation of 9 | SoapSerializationEnvelope for more detailed information.

10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/search/messages/BaseObject.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon.search.messages; 2 | 3 | import org.ksoap2.serialization.*; 4 | 5 | public abstract class BaseObject implements KvmSerializable { 6 | 7 | protected static final String NAMESPACE = "http://webservices.amazon.com/AWSECommerceService/2006-05-17"; 8 | 9 | public BaseObject() { 10 | super(); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /ksoap2-samples-axis/src/main/resources/AxisService.wsdd: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

This package contains basic classes required for 8 | handling SOAP Envelopes and literal XML content. 9 | Please refer to the documentation of SoapEnvelope 10 | for more detailed information.

11 | 12 |

Support for the SOAP Serialization XML 13 | content format is contained in the package 14 | org.ksoap2.serialization. Support for performing 15 | SOAP calls via the network (sending and receiving 16 | SoapEnvelopes) is available in the package org 17 | .ksoap2.transport.

18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ksoap2-android/src/main/java/org/ksoap2/transport/AndroidServiceConnection.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.transport; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * This is a simple extension of the {@link HttpTransportSE} class. It provides the exact same functionality 7 | * as that class and is provided purely for backwards-compatibility purposes. It will likely be deprecated at 8 | * some point in the near future. 9 | */ 10 | public class AndroidServiceConnection extends ServiceConnectionSE 11 | { 12 | /** 13 | * @see ServiceConnectionSE#ServiceConnectionSE(String) 14 | */ 15 | public AndroidServiceConnection(String url) throws IOException 16 | { 17 | super(url); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/serialization/PropertyInfoTest.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.serialization; 2 | 3 | import junit.framework.*; 4 | 5 | public class PropertyInfoTest extends TestCase { 6 | 7 | public void testClearingValues() { 8 | PropertyInfo info = new PropertyInfo(); 9 | info.type = new Integer(1); 10 | info.name = "propertyName"; 11 | info.namespace = "namespaceName"; 12 | info.flags = 12; 13 | 14 | info.clear(); 15 | 16 | assertEquals(PropertyInfo.OBJECT_CLASS, info.type); 17 | assertEquals(0, info.flags); 18 | assertEquals(null, info.name); 19 | assertEquals(null, info.namespace); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/soccer/StadiumNamesResult.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.soccer; 2 | 3 | import org.ksoap2.serialization.*; 4 | 5 | public class StadiumNamesResult extends LiteralArrayVector { 6 | 7 | // in the resultant xml message, the array elements can 8 | // be described with different tags depending on a number 9 | // of factors (doc literal, rpc, etc...). This tells 10 | // our parent class to look for "string" 11 | protected String getItemDescriptor() { 12 | return "string"; 13 | } 14 | 15 | // This describes what type of objects are to be contained in the Array 16 | protected Class getElementClass() { 17 | return PropertyInfo.STRING_CLASS; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /ksoap2-samples-axis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-samples-axis 11 | ksoap2-samples-axis 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | com.google.code.ksoap2-android 21 | ksoap2-midp 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ksoap2-android/src/main/java/org/ksoap2/transport/AndroidHttpTransport.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.transport; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * This is a simple extension of the {@link HttpTransportSE} class. It provides the exact same functionality 7 | * as that class and is provided purely for backwards-compatibility purposes. It will likely be deprecated at 8 | * some point in the near future. 9 | */ 10 | public class AndroidHttpTransport extends HttpTransportSE 11 | { 12 | /** 13 | * @see HttpTransportSE#HttpTransportSE(String) 14 | */ 15 | public AndroidHttpTransport(String url) 16 | { 17 | super(url); 18 | } 19 | 20 | /** 21 | * @see org.ksoap2.transport.HttpTransportSE#getServiceConnection() 22 | */ 23 | @Override 24 | protected ServiceConnection getServiceConnection() throws IOException 25 | { 26 | return new AndroidServiceConnection(super.url); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ksoap2-midp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-midp 11 | ksoap2-midp 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | com.google.code.ksoap2-android 21 | ksoap2-base 22 | 23 | 24 | 25 | net.sourceforge.me4se 26 | me4se 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /ksoap2-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-samples 11 | ksoap2-samples 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | com.google.code.ksoap2-android 21 | ksoap2-j2se 22 | 23 | 24 | com.google.code.ksoap2-android 25 | ksoap2-midp 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /ksoap2-servlet/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-servlet 11 | ksoap2-servlet 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | com.google.code.ksoap2-android 21 | ksoap2-base 22 | 23 | 24 | 25 | servletapi 26 | servlet-api 27 | 2.4 28 | jar 29 | compile 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ksoap2-samples-axis/src/main/java/net/wessendorf/ws/AxisService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 The Apache Software Foundation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.wessendorf.ws; 17 | 18 | /** 19 | * @author Matthias Webendorf 20 | */ 21 | public class AxisService { 22 | 23 | public CustomObject getObject(String value){ 24 | CustomObject ret = new CustomObject(); 25 | ret.setValue("Hello World "+value); 26 | return ret; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ksoap2-samples-axis/src/main/java/net/wessendorf/ws/CustomObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 The Apache Software Foundation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.wessendorf.ws; 17 | 18 | /** 19 | * @author Matthias Webendorf 20 | */ 21 | public class CustomObject { 22 | 23 | public CustomObject(){} 24 | 25 | private String value; 26 | public String getValue() { 27 | return value; 28 | } 29 | public void setValue(String value) { 30 | this.value = value; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006, James Seigel, Calgary, AB., Canada 2 | Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | sell copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /ksoap2-android/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-android 11 | ksoap2-android 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | com.google.code.ksoap2-android 21 | ksoap2-j2se 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.apache.maven.plugins 29 | maven-jar-plugin 30 | 31 | 32 | 33 | test-jar 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/search/messages/Request.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon.search.messages; 2 | 3 | import java.util.*; 4 | 5 | import org.ksoap2.serialization.*; 6 | 7 | public class Request extends BaseObject { 8 | 9 | public String author; 10 | public String searchIndex; 11 | 12 | public Object getProperty(int index) { 13 | if(index == 0) { 14 | return author; 15 | } else { 16 | return searchIndex; 17 | } 18 | } 19 | 20 | public int getPropertyCount() { 21 | return 2; 22 | } 23 | 24 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 25 | info.type = PropertyInfo.STRING_CLASS; 26 | if(index == 0) { 27 | info.name = "Author"; 28 | } else { 29 | info.name = "SearchIndex"; 30 | } 31 | } 32 | 33 | public void setProperty(int index, Object value) { 34 | throw new RuntimeException("Request.setProperty is not implemented yet"); 35 | } 36 | 37 | public void register(SoapSerializationEnvelope envelope) { 38 | envelope.addMapping(NAMESPACE, "ItemSearchRequest", this.getClass()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/FwdRef.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.serialization; 22 | 23 | /** 24 | * @author Stefan Haustein 25 | */ 26 | class FwdRef { 27 | 28 | FwdRef next; 29 | Object obj; 30 | int index; 31 | } 32 | -------------------------------------------------------------------------------- /ksoap2-android-assembly/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-android-assembly 11 | ksoap2-android-assembly 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | com.google.code.ksoap2-android 21 | ksoap2-android 22 | 23 | 24 | 25 | 26 | 27 | 28 | maven-assembly-plugin 29 | 30 | 31 | jar-with-dependencies 32 | 33 | 34 | 35 | 36 | make-assembly 37 | package 38 | 39 | single 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ksoap2-base/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-base 11 | ksoap2-base 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | net.sourceforge.kxml 21 | kxml 22 | 23 | 24 | net.sourceforge.kobjects 25 | kobjects-j2me 26 | 27 | 28 | 29 | junit 30 | junit 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.apache.maven.plugins 38 | maven-jar-plugin 39 | 40 | 41 | 42 | test-jar 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/serialization/DMTest.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.serialization; 2 | 3 | import java.io.*; 4 | 5 | import org.ksoap2.transport.mock.*; 6 | import org.xmlpull.v1.*; 7 | 8 | import junit.framework.*; 9 | 10 | public class DMTest extends TestCase { 11 | 12 | private static final String STRING_XML_PROPERTY_VALUE = "someXmlPropertyValue"; 13 | private MockXmlPullParser pullParser; 14 | private DM dm; 15 | 16 | protected void setUp() throws Exception { 17 | super.setUp(); 18 | pullParser = new MockXmlPullParser(); 19 | pullParser.nextText = STRING_XML_PROPERTY_VALUE; 20 | dm = new DM(); 21 | } 22 | 23 | public void testValidTypes() throws IOException, XmlPullParserException { 24 | assertEquals(STRING_XML_PROPERTY_VALUE, dm.readInstance(pullParser, "", "string", null)); 25 | pullParser.nextText = "12"; 26 | assertEquals(new Long(12), dm.readInstance(pullParser, "", "long", null)); 27 | assertEquals(new Integer(12), dm.readInstance(pullParser, "", "int", null)); 28 | pullParser.nextText = "true"; 29 | assertEquals(Boolean.TRUE, dm.readInstance(pullParser, "", "boolean", null)); 30 | } 31 | 32 | public void testDefaultFailureCase() throws IOException, XmlPullParserException { 33 | try { 34 | dm.readInstance(pullParser, "", "unknownType", null); 35 | } catch (RuntimeException expected) { 36 | assertEquals(null, expected.getMessage()); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ksoap2-j2se/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-j2se 11 | ksoap2-j2se 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | com.google.code.ksoap2-android 21 | ksoap2-base 22 | 23 | 24 | com.google.code.ksoap2-android 25 | ksoap2-base 26 | test-jar 27 | test 28 | 29 | 30 | 31 | junit 32 | junit 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-jar-plugin 41 | 42 | 43 | 44 | test-jar 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/search/messages/ItemSearchResponse.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon.search.messages; 2 | 3 | import java.util.*; 4 | 5 | import org.ksoap2.serialization.*; 6 | 7 | public class ItemSearchResponse extends BaseObject { 8 | 9 | private BookItems bookItems; 10 | private String operationRequest; 11 | 12 | public Object getProperty(int index) { 13 | if (index == 0) { 14 | return bookItems; 15 | } else { 16 | return operationRequest; 17 | } 18 | } 19 | 20 | public int getPropertyCount() { 21 | return 2; 22 | } 23 | 24 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 25 | switch (index) { 26 | case 0: 27 | info.name = "Items"; 28 | info.type = new BookItems().getClass(); 29 | break; 30 | case 1: 31 | info.name = "OperationRequest"; 32 | info.type = new SoapObject(NAMESPACE, "OperationRequest").getClass(); 33 | default: 34 | break; 35 | } 36 | } 37 | 38 | public void setProperty(int index, Object value) { 39 | if (index == 0) { 40 | bookItems = (BookItems) value; 41 | } else { 42 | operationRequest = value.toString(); 43 | } 44 | } 45 | 46 | public void register(SoapSerializationEnvelope envelope) { 47 | envelope.addMapping(NAMESPACE, "ItemSearchResponse", this.getClass()); 48 | new BookItems().register(envelope); 49 | new BookAttributes().register(envelope); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /ksoap2-extras/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.google.code.ksoap2-android 6 | ksoap2-parent 7 | 2.5-SNAPSHOT 8 | 9 | 10 | ksoap2-extras 11 | ksoap2-extras 12 | jar 13 | 16 | 17 | 18 | 19 | 20 | com.google.code.ksoap2-android 21 | ksoap2-base 22 | 23 | 24 | com.google.code.ksoap2-android 25 | ksoap2-base 26 | test-jar 27 | test 28 | 29 | 30 | com.google.code.ksoap2-android 31 | ksoap2-midp 32 | 33 | 34 | 35 | junit 36 | junit 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-jar-plugin 45 | 46 | 47 | 48 | test-jar 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/AttributeInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2006, James Seigel, Calgary, AB., Canada Copyright (c) 2003,2004, Stefan Haustein, 3 | * Oberhausen, Rhld., Germany 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | * associated documentation files (the "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 9 | * following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial 12 | * portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 15 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 16 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 18 | * USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | package org.ksoap2.serialization; 22 | 23 | /** 24 | * This class is used to store information about each attribute of an implementation of 25 | * {@link KvmSerializable} exposes. 26 | */ 27 | public class AttributeInfo extends PropertyInfo 28 | { 29 | /** 30 | * Constructor. 31 | */ 32 | public AttributeInfo() 33 | { 34 | super(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/soccer/LiteralArrayVector.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.soccer; 2 | 3 | import java.util.*; 4 | 5 | import org.ksoap2.serialization.*; 6 | 7 | public abstract class LiteralArrayVector extends Vector implements KvmSerializable { 8 | 9 | public void register(SoapSerializationEnvelope envelope, String namespace, String name) { 10 | // using this.getClass() everywhere because .class doesn't 11 | // exist on j2me 12 | envelope.addMapping(namespace, name, this.getClass()); 13 | registerElementClass(envelope, namespace); 14 | } 15 | 16 | private void registerElementClass(SoapSerializationEnvelope envelope, String namespace) { 17 | final Class elementClass = getElementClass(); 18 | try { 19 | if (elementClass.newInstance() instanceof KvmSerializable) 20 | envelope.addMapping(namespace, "", elementClass); 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | } 25 | 26 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 27 | info.name = getItemDescriptor(); 28 | info.type = getElementClass(); 29 | } 30 | 31 | public Object getProperty(int index) { 32 | return this; 33 | } 34 | 35 | public int getPropertyCount() { 36 | return 1; 37 | } 38 | 39 | public void setProperty(int index, Object value) { 40 | addElement(value); 41 | } 42 | 43 | abstract protected Class getElementClass(); 44 | 45 | protected String getItemDescriptor() { 46 | return "item"; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/serialization/SoapPrimitiveTest.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.serialization; 2 | 3 | import junit.framework.*; 4 | 5 | public class SoapPrimitiveTest extends TestCase { 6 | 7 | public void testEquals() { 8 | SoapPrimitive primitive = new SoapPrimitive("namespace", "name", "value"); 9 | assertFalse(primitive.equals("something that shouldn't equal")); 10 | 11 | SoapPrimitive primitiveTwo = new SoapPrimitive("", "", ""); 12 | assertFalse(primitive.equals(primitiveTwo)); 13 | 14 | primitiveTwo.namespace = primitive.getNamespace(); 15 | assertFalse(primitive.equals(primitiveTwo)); 16 | 17 | primitiveTwo.name = primitive.getName(); 18 | assertFalse(primitive.equals(primitiveTwo)); 19 | 20 | primitiveTwo.value = primitive.toString(); 21 | assertTrue(primitive.equals(primitiveTwo)); 22 | 23 | primitiveTwo.value = null; 24 | assertFalse(primitive.equals(primitiveTwo)); 25 | 26 | primitive.value = null; 27 | assertTrue(primitive.equals(primitiveTwo)); 28 | } 29 | 30 | public void testHashCode_NullNamespace() { 31 | SoapPrimitive primitive = new SoapPrimitive(null, "name", "value"); 32 | assertTrue(primitive.hashCode() == primitive.hashCode()); 33 | assertFalse(primitive.hashCode() == new SoapPrimitive("weeee", "name", "value").hashCode()); 34 | } 35 | 36 | public void testEquals_NullNamespace() { 37 | SoapPrimitive primitive = new SoapPrimitive(null, "name", "value"); 38 | assertTrue(primitive.equals(primitive)); 39 | assertFalse(primitive.equals(new SoapPrimitive("weeee", "name", "value"))); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/search/messages/LiteralArrayVector.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon.search.messages; 2 | 3 | import java.util.*; 4 | 5 | import org.ksoap2.serialization.*; 6 | 7 | public abstract class LiteralArrayVector extends Vector implements KvmSerializable { 8 | 9 | public void register(SoapSerializationEnvelope envelope, String namespace, String name) { 10 | // using this.getClass() everywhere because .class doesn't 11 | // exist on j2me 12 | envelope.addMapping(namespace, name, this.getClass()); 13 | registerElementClass(envelope, namespace); 14 | } 15 | 16 | private void registerElementClass(SoapSerializationEnvelope envelope, String namespace) { 17 | final Class elementClass = getElementClass(); 18 | try { 19 | if (elementClass.newInstance() instanceof KvmSerializable) 20 | envelope.addMapping(namespace, "", elementClass); 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | } 25 | 26 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 27 | info.name = getItemDescriptor(); 28 | info.type = getElementClass(); 29 | } 30 | 31 | public Object getProperty(int index) { 32 | return this; 33 | } 34 | 35 | public int getPropertyCount() { 36 | return 1; 37 | } 38 | 39 | public void setProperty(int index, Object value) { 40 | addElement(value); 41 | } 42 | 43 | abstract protected Class getElementClass(); 44 | 45 | protected String getItemDescriptor() { 46 | return "item"; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/search/messages/Book.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon.search.messages; 2 | 3 | import java.util.*; 4 | 5 | import org.ksoap2.serialization.*; 6 | 7 | public class Book extends BaseObject { 8 | 9 | private String asin; 10 | private String detailPageUrl; 11 | private BookAttributes itemAttributes; 12 | 13 | public Object getProperty(int index) { 14 | throw new RuntimeException("Book.getProperty is not implemented yet"); 15 | } 16 | 17 | public int getPropertyCount() { 18 | return 3; 19 | } 20 | 21 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 22 | info.type = PropertyInfo.STRING_CLASS; 23 | switch (index) { 24 | case 0: 25 | info.name = "ASIN"; 26 | break; 27 | case 1: 28 | info.name = "DetailPageURL"; 29 | break; 30 | case 2: 31 | info.name = "ItemAttributes"; 32 | info.type = new BookAttributes().getClass(); 33 | default: 34 | break; 35 | } 36 | } 37 | 38 | public void setProperty(int index, Object value) { 39 | switch (index) { 40 | case 0: 41 | asin = value.toString(); 42 | break; 43 | case 1: 44 | detailPageUrl = value.toString(); 45 | break; 46 | case 2: 47 | itemAttributes = (BookAttributes) value; 48 | default: 49 | break; 50 | } 51 | } 52 | public String toString() { 53 | StringBuffer buffer = new StringBuffer(); 54 | buffer.append("ASIN: "); 55 | buffer.append(asin); 56 | buffer.append("\n"); 57 | buffer.append("Detail page URL: "); 58 | buffer.append(detailPageUrl); 59 | buffer.append("\n"); 60 | buffer.append(itemAttributes.toString()); 61 | return buffer.toString(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/serialization/MarshalDateTest.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.serialization; 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | 6 | import junit.framework.*; 7 | 8 | import org.kobjects.isodate.*; 9 | import org.ksoap2.*; 10 | import org.ksoap2.transport.mock.*; 11 | import org.xmlpull.v1.*; 12 | 13 | public class MarshalDateTest extends TestCase { 14 | private static final Date TEST_DATE = new Date(); 15 | private static final String ENCODED_DATE_STRING = IsoDate.dateToString(TEST_DATE, IsoDate.DATE_TIME); 16 | 17 | private MarshalDate marshalDate; 18 | 19 | protected void setUp() throws Exception { 20 | marshalDate = new MarshalDate(); 21 | } 22 | 23 | public void testMarshalDateInbound() throws IOException, XmlPullParserException { 24 | MockXmlPullParser mockXmlPullParser = new MockXmlPullParser(); 25 | mockXmlPullParser.nextText = ENCODED_DATE_STRING; 26 | Date date = (Date) marshalDate.readInstance(mockXmlPullParser, null, null, null); 27 | assertEquals(TEST_DATE, date); 28 | } 29 | 30 | public void testMarshalDateOutbound() throws IOException { 31 | MockXmlSerializer writer = new MockXmlSerializer(); 32 | marshalDate.writeInstance(writer , TEST_DATE); 33 | assertEquals(ENCODED_DATE_STRING, writer.getOutputText()); 34 | } 35 | 36 | public void testRegistration_moreIntegrationLike() throws IOException, XmlPullParserException { 37 | MockXmlPullParser pullParser = new MockXmlPullParser(); 38 | pullParser.nextText = ENCODED_DATE_STRING; 39 | 40 | SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 41 | marshalDate.register(envelope); 42 | assertTrue(envelope.classToQName.containsKey(MarshalDate.DATE_CLASS.getName())); 43 | 44 | Date date = (Date) envelope.readInstance(pullParser, envelope.xsd, "dateTime", null); 45 | assertEquals(TEST_DATE, date); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/axis/quotes/AxisStockQuoteExample.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.axis.quotes; 2 | 3 | import org.ksoap2.*; 4 | import org.ksoap2.serialization.*; 5 | import org.ksoap2.transport.*; 6 | /* 7 | * Example that uses one of the built in axis .jws examples 8 | * Install apache tomcat or use simple axis server 9 | * and the default version of axis then 10 | * start the server verify you have all of the needed .jars 11 | * installed correctly and you should be able to run this 12 | * Example. 13 | */ 14 | public class AxisStockQuoteExample { 15 | 16 | public AxisStockQuoteExample() { 17 | // Create the outgoing message 18 | SoapObject requestObject = new SoapObject("x", "getQuote"); 19 | // ask for the specially encoded symbol in the included service 20 | requestObject.addProperty("symbol", "XXX"); 21 | 22 | // use version 1.1 of soap 23 | SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 24 | // add the outgoing object as the request 25 | envelope.setOutputSoapObject(requestObject); 26 | new MarshalFloat().register(envelope); // not really needed for j2se version 27 | 28 | // Create a transport layer for the J2SE platform. You should change this for 29 | // another transport on midp or j2me devices. 30 | HttpTransportSE transportSE = new HttpTransportSE("http://localhost:8080/axis/StockQuoteService.jws"); 31 | // turn on debug mode if you want to see what is happening over the wire. 32 | transportSE.debug = true; 33 | try { 34 | // call and print out the result 35 | transportSE.call("getQuote", envelope); 36 | System.out.println(envelope.getResponse()); 37 | } catch (Exception e) { 38 | // if we get an error print the stacktrace and dump the response out. 39 | e.printStackTrace(); 40 | System.out.println(transportSE.responseDump); 41 | } 42 | } 43 | 44 | public static void main(String[] args) { 45 | new AxisStockQuoteExample(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/MarshalDate.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.serialization; 22 | 23 | import java.util.Date; 24 | import java.io.*; 25 | import org.xmlpull.v1.*; 26 | import org.kobjects.isodate.*; 27 | 28 | 29 | /** 30 | * Marshal class for Dates. 31 | */ 32 | public class MarshalDate implements Marshal { 33 | public static Class DATE_CLASS = new Date().getClass(); 34 | 35 | public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo expected) throws IOException, XmlPullParserException { 36 | return IsoDate.stringToDate(parser.nextText(), IsoDate.DATE_TIME); 37 | } 38 | 39 | public void writeInstance(XmlSerializer writer, Object obj) throws IOException { 40 | writer.text(IsoDate.dateToString((Date) obj, IsoDate.DATE_TIME)); 41 | } 42 | 43 | public void register(SoapSerializationEnvelope cm) { 44 | cm.addMapping(cm.xsd, "dateTime", MarshalDate.DATE_CLASS, this); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/search/AmazonSearchClient.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon.search; 2 | 3 | import org.ksoap2.*; 4 | import org.ksoap2.samples.amazon.search.messages.*; 5 | import org.ksoap2.serialization.*; 6 | import org.ksoap2.transport.*; 7 | 8 | public class AmazonSearchClient { 9 | private static final String NAMESPACE = "http://webservices.amazon.com/AWSECommerceService/2006-05-17"; 10 | private static final String AMAZON_WEBSERVICE_KEY = ""; 11 | 12 | public AmazonSearchClient() { 13 | if (AMAZON_WEBSERVICE_KEY.length() == 0) { 14 | System.out.println("Please substitute your own amazon webservice key before running this code."); 15 | } else { 16 | Request requestObject = new Request(); 17 | requestObject.author = "Whyte"; 18 | requestObject.searchIndex = "Books"; 19 | 20 | SoapObject request = new SoapObject(NAMESPACE, "ItemSearch"); 21 | request.addProperty("SubscriptionId", AMAZON_WEBSERVICE_KEY); 22 | request.addProperty("Request", requestObject); 23 | 24 | SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 25 | envelope.setOutputSoapObject(request); 26 | requestObject.register(envelope); 27 | 28 | registerObjects(envelope); 29 | 30 | HttpTransportSE httpTransportSE = new HttpTransportSE("http://soap.amazon.com/onca/soap?Service=AWSECommerceService"); 31 | httpTransportSE.setXmlVersionTag(""); 32 | try { 33 | httpTransportSE.call("http://soap.amazon.com", envelope); 34 | BookItems response = (BookItems) envelope.getResponse(); 35 | System.out.println(response); 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | } 41 | 42 | private void registerObjects(SoapSerializationEnvelope envelope) { 43 | new ItemSearchResponse().register(envelope); 44 | } 45 | 46 | public static void main(String[] args) { 47 | new AmazonSearchClient(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/quotes/StockQuoteDemo.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.quotes; 2 | 3 | import javax.microedition.midlet.*; 4 | import javax.microedition.lcdui.*; 5 | 6 | import org.ksoap2.*; 7 | import org.ksoap2.serialization.*; 8 | import org.ksoap2.transport.*; 9 | 10 | public class StockQuoteDemo extends MIDlet implements CommandListener, Runnable { 11 | 12 | Form mainForm = new Form("StockQuotes"); 13 | TextField symbolField = new TextField("Symbol", "IBM", 5, TextField.ANY); 14 | StringItem resultItem = new StringItem("", ""); 15 | Command getCommand = new Command("Get", Command.SCREEN, 1); 16 | 17 | public StockQuoteDemo() { 18 | mainForm.append(symbolField); 19 | mainForm.append(resultItem); 20 | mainForm.addCommand(getCommand); 21 | mainForm.setCommandListener(this); 22 | } 23 | 24 | public void startApp() { 25 | Display.getDisplay(this).setCurrent(mainForm); 26 | } 27 | 28 | public void pauseApp() { 29 | } 30 | 31 | public void destroyApp(boolean unconditional) { 32 | } 33 | 34 | 35 | public void run(){ 36 | try { 37 | // build request string 38 | String symbol = symbolField.getString(); 39 | 40 | SoapObject rpc = 41 | new SoapObject("urn:xmethods-delayed-quotes", "getQuote"); 42 | 43 | rpc.addProperty("symbol", symbol); 44 | 45 | SoapSerializationEnvelope envelope = 46 | new SoapSerializationEnvelope(SoapEnvelope.VER10); 47 | 48 | envelope.bodyOut = rpc; 49 | 50 | resultItem.setLabel(symbol); 51 | 52 | HttpTransport ht = new HttpTransport("http://services.xmethods.net/soap"); 53 | //ht.debug = true; 54 | 55 | ht.call("urn:xmethods-delayed-quotes#getQuote", envelope); 56 | resultItem.setText("" + envelope.getResponse()); 57 | } 58 | catch (Exception e) { 59 | e.printStackTrace(); 60 | resultItem.setLabel("Error:"); 61 | resultItem.setText(e.toString()); 62 | } 63 | 64 | } 65 | 66 | 67 | public void commandAction(Command c, Displayable d) { 68 | new Thread(this).start(); 69 | } 70 | 71 | /** for me4se */ 72 | 73 | public static void main(String[] argv) { 74 | new StockQuoteDemo().startApp(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/MarshalBase64.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.serialization; 22 | 23 | import java.io.*; 24 | import org.ksoap2.*; 25 | import org.kobjects.base64.*; 26 | import org.xmlpull.v1.*; 27 | 28 | /** 29 | * Base64 (de)serializer 30 | */ 31 | public class MarshalBase64 implements Marshal { 32 | public static Class BYTE_ARRAY_CLASS = new byte[0].getClass(); 33 | 34 | public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo expected) throws IOException, XmlPullParserException { 35 | return Base64.decode(parser.nextText()); 36 | } 37 | 38 | public void writeInstance(XmlSerializer writer, Object obj) throws IOException { 39 | writer.text(Base64.encode((byte[]) obj)); 40 | } 41 | 42 | public void register(SoapSerializationEnvelope cm) { 43 | cm.addMapping(cm.xsd, "base64Binary", MarshalBase64.BYTE_ARRAY_CLASS, this); 44 | cm.addMapping(SoapEnvelope.ENC, "base64", MarshalBase64.BYTE_ARRAY_CLASS, this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/search/messages/BookItems.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon.search.messages; 2 | 3 | import java.util.*; 4 | 5 | import org.ksoap2.serialization.*; 6 | 7 | public class BookItems extends LiteralArrayVector { 8 | private String request; 9 | 10 | protected String getItemDescriptor() { 11 | return "Item"; 12 | } 13 | 14 | public Object getProperty(int index) { 15 | throw new RuntimeException("BookItems.getProperty is not implemented yet"); 16 | } 17 | 18 | public int getPropertyCount() { 19 | return 4; 20 | } 21 | 22 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 23 | info.type = new SoapObject(BaseObject.NAMESPACE, "").getClass(); 24 | switch (index) { 25 | case 0: 26 | info.name = "Request"; 27 | break; 28 | case 1: 29 | info.name = "TotalResults"; 30 | break; 31 | case 2: 32 | info.name = "TotalPages"; 33 | break; 34 | case 3: 35 | super.getPropertyInfo(index, properties, info); 36 | default: 37 | break; 38 | } 39 | } 40 | 41 | public void setProperty(int index, Object value) { 42 | switch (index) { 43 | case 0: 44 | request = value.toString(); 45 | break; 46 | case 3: 47 | super.setProperty(index, value); 48 | default: 49 | break; 50 | } 51 | } 52 | 53 | protected Class getElementClass() { 54 | return new Book().getClass(); 55 | } 56 | 57 | public void register(SoapSerializationEnvelope envelope) { 58 | super.register(envelope, BaseObject.NAMESPACE, "Items"); 59 | } 60 | 61 | public synchronized String toString() { 62 | StringBuffer buffer = new StringBuffer(); 63 | buffer.append("Request: "); 64 | buffer.append(request); 65 | buffer.append("\n"); 66 | for (int i = 0; i < size(); i++) { 67 | buffer.append("\n=== BOOK ===\n"); 68 | buffer.append(elementAt(i).toString()); 69 | } 70 | return buffer.toString(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/serialization/MarshalHashtableTest.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.serialization; 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | 6 | import junit.framework.*; 7 | 8 | import org.ksoap2.*; 9 | import org.ksoap2.transport.mock.*; 10 | 11 | public class MarshalHashtableTest extends TestCase { 12 | 13 | private static final String VALUE1 = "value1"; 14 | private static final String KEY1_NAME = "key1"; 15 | 16 | // should work on a read instance. But too complicated. 17 | 18 | public void testWriteInstance() throws IOException { 19 | MarshalHashtable marshalHashtable = new MarshalHashtable(); 20 | SoapSerializationEnvelope serializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 21 | marshalHashtable.register(serializationEnvelope); 22 | MockXmlSerializer writer = new MockXmlSerializer(); 23 | Hashtable hashTable = prefilledHashTable(); 24 | marshalHashtable.writeInstance(writer, hashTable); 25 | 26 | // the mock just appends the bits together 27 | assertEquals(KEY1_NAME + ";" + VALUE1, writer.getOutputText()); 28 | assertEquals(MockXmlSerializer.PREFIX + ":string;" + MockXmlSerializer.PREFIX + ":string", writer.getPropertyType()); 29 | assertEquals("item;key;value", writer.getStartTag()); 30 | assertEquals("key;value;item", writer.getEndtag()); 31 | 32 | writer = new MockXmlSerializer(); 33 | hashTable = prefilledHashTable(); 34 | hashTable.put("key2", new Integer(12)); 35 | marshalHashtable.writeInstance(writer, hashTable); 36 | 37 | assertEquals("key2;12;"+KEY1_NAME + ";" + VALUE1, writer.getOutputText()); 38 | assertEquals(MockXmlSerializer.PREFIX + ":string;" + MockXmlSerializer.PREFIX + ":int;"+MockXmlSerializer.PREFIX + ":string;" + MockXmlSerializer.PREFIX + ":string", writer.getPropertyType()); 39 | assertEquals("item;key;value;item;key;value", writer.getStartTag()); 40 | assertEquals("key;value;item;key;value;item", writer.getEndtag()); 41 | } 42 | 43 | private Hashtable prefilledHashTable() { 44 | Hashtable hashtable = new Hashtable(); 45 | hashtable.put(KEY1_NAME, VALUE1); 46 | return hashtable; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/serialization/MarshalBase64Test.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.serialization; 2 | 3 | import java.io.*; 4 | 5 | import org.kobjects.base64.*; 6 | import org.ksoap2.*; 7 | import org.ksoap2.transport.mock.*; 8 | import org.xmlpull.v1.*; 9 | 10 | import junit.framework.*; 11 | 12 | public class MarshalBase64Test extends TestCase { 13 | 14 | private static final String TEST_STRING = "A very quick test string 13412341234"; 15 | private static final String ENCODED_TEST_STRING = Base64.encode(TEST_STRING.getBytes()); 16 | 17 | private MarshalBase64 marshalBase64; 18 | 19 | protected void setUp() throws Exception { 20 | marshalBase64 = new MarshalBase64(); 21 | } 22 | 23 | public void testConvertFromBase64() throws IOException, XmlPullParserException { 24 | MockXmlPullParser mockXmlPullParser = new MockXmlPullParser(); 25 | mockXmlPullParser.nextText = ENCODED_TEST_STRING; 26 | byte[] byteArray = (byte[]) marshalBase64.readInstance(mockXmlPullParser, null, null, null); 27 | assertEquals(TEST_STRING, new String(byteArray)); 28 | } 29 | 30 | public void testConvertToBase64() throws IOException { 31 | MockXmlSerializer writer = new MockXmlSerializer(); 32 | marshalBase64.writeInstance(writer , TEST_STRING.getBytes()); 33 | assertEquals(ENCODED_TEST_STRING, writer.getOutputText()); 34 | } 35 | 36 | public void testRegistration_moreIntegrationLike() throws IOException, XmlPullParserException { 37 | MockXmlPullParser pullParser = new MockXmlPullParser(); 38 | pullParser.nextText = ENCODED_TEST_STRING; 39 | 40 | SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 41 | marshalBase64.register(envelope); 42 | assertTrue(envelope.classToQName.containsKey(MarshalBase64.BYTE_ARRAY_CLASS.getName())); 43 | 44 | byte[] decodedArray = (byte[]) envelope.readInstance(pullParser, envelope.xsd, "base64Binary", null); 45 | assertEquals(TEST_STRING, new String(decodedArray)); 46 | 47 | decodedArray = (byte[]) envelope.readInstance(pullParser, SoapEnvelope.ENC, "base64", null); 48 | assertEquals(TEST_STRING, new String(decodedArray)); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /ksoap2-j2se/src/test/java/org/ksoap2/transport/HttpTransportSETest.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, James Seigel, Calgary, AB., Canada 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.transport; 22 | 23 | import java.io.*; 24 | 25 | public class HttpTransportSETest extends TransportTestCase { 26 | 27 | public void testOutbound() throws Throwable { 28 | MyTransport ht = new MyTransport("a url"); 29 | ht.call(soapAction, envelope); 30 | assertSerializationDeserialization(); 31 | assertTrue(serviceConnection.connected); 32 | } 33 | 34 | public void testOutbound_WithNoSoapAction() throws Throwable { 35 | MyTransport ht = new MyTransport("a url"); 36 | ht.call(null, envelope); 37 | soapAction = "\"\"";// expected answer for null 38 | assertSerializationDeserialization(); 39 | assertTrue(serviceConnection.connected); 40 | } 41 | 42 | class MyTransport extends HttpTransportSE { 43 | public MyTransport(String url) { 44 | super(url); 45 | } 46 | 47 | protected ServiceConnection getServiceConnection() throws IOException { 48 | return serviceConnection; 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/transport/TransportTestCase.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.transport; 2 | 3 | import org.ksoap2.*; 4 | import org.ksoap2.serialization.*; 5 | import org.ksoap2.transport.mock.*; 6 | 7 | import junit.framework.*; 8 | 9 | public abstract class TransportTestCase extends TestCase { 10 | 11 | protected static final String containerNameSpaceURI = ServiceConnectionFixture.NAMESPACE; 12 | protected String soapAction = "SoapActionString"; 13 | ServiceConnectionFixture serviceConnection; 14 | protected SoapSerializationEnvelope envelope; 15 | protected SoapObject soapObject; 16 | protected ComplexParameter complexParameter; 17 | 18 | protected void setUp() throws Exception { 19 | super.setUp(); 20 | serviceConnection = new ServiceConnectionFixture(); 21 | serviceConnection.setInputSring(ServiceConnectionFixture.WORKING_NOMULTIREF); 22 | envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 23 | soapObject = new SoapObject(containerNameSpaceURI, "performComplexFunctionService"); 24 | complexParameter = new ComplexParameter(); 25 | complexParameter.name = "Serenity"; 26 | complexParameter.count = 56; 27 | envelope.addMapping(containerNameSpaceURI, "ComplexParameter", complexParameter.getClass()); 28 | envelope.addMapping(containerNameSpaceURI, ServiceConnectionFixture.RESPONSE_CLASS_NAME, ServiceConnectionFixture.RESPONSE_CLASS); 29 | soapObject.addProperty("complexFunction", complexParameter); 30 | envelope.setOutputSoapObject(soapObject); 31 | } 32 | 33 | protected void assertHeaderCorrect(ServiceConnectionFixture aServiceConnection, String aSoapAction) { 34 | assertEquals(aSoapAction, aServiceConnection.requestPropertyMap.get("SOAPAction")); 35 | assertEquals("text/xml", aServiceConnection.requestPropertyMap.get("Content-Type")); 36 | assertNotNull(aServiceConnection.requestPropertyMap.get("Content-Length")); 37 | assertEquals("kSOAP/2.0", aServiceConnection.requestPropertyMap.get("User-Agent")); 38 | } 39 | 40 | protected void assertSerializationDeserialization() throws SoapFault { 41 | String outputString = new String(serviceConnection.outputStream.toByteArray()); 42 | assertTrue(outputString.indexOf(complexParameter.name) > 0); 43 | assertTrue(outputString.indexOf(""+complexParameter.count) > 0); 44 | assertTrue(envelope.getResponse() instanceof ComplexResponse); 45 | assertHeaderCorrect(serviceConnection,soapAction); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ksoap2-j2se/src/main/java/org/ksoap2/serialization/MarshalFloat.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004 Stefan Haustein, Oberhausen, Rhld., Germany 2 | * Copyright (c) 2006, James Seigel, Calgary, AB., Canada 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. */ 21 | 22 | package org.ksoap2.serialization; 23 | 24 | import java.io.*; 25 | 26 | import org.xmlpull.v1.*; 27 | 28 | public class MarshalFloat implements Marshal { 29 | 30 | public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo propertyInfo) throws IOException, XmlPullParserException { 31 | String stringValue = parser.nextText(); 32 | Object result; 33 | if (name.equals("float")) { 34 | result = new Float(stringValue); 35 | } else if (name.equals("double")) { 36 | result = new Double(stringValue); 37 | } else if (name.equals("decimal")) { 38 | result = new java.math.BigDecimal(stringValue); 39 | } else { 40 | throw new RuntimeException("float, double, or decimal expected"); 41 | } 42 | return result; 43 | } 44 | 45 | public void writeInstance(XmlSerializer writer, Object instance) throws IOException { 46 | writer.text(instance.toString()); 47 | } 48 | 49 | public void register(SoapSerializationEnvelope cm) { 50 | cm.addMapping(cm.xsd, "float", Float.class, this); 51 | cm.addMapping(cm.xsd, "double", Double.class, this); 52 | cm.addMapping(cm.xsd, "decimal", java.math.BigDecimal.class, this); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ksoap2-samples-axis/src/main/java/net/wessendorf/j2me/SoapDemo.java: -------------------------------------------------------------------------------- 1 | package net.wessendorf.j2me; 2 | 3 | 4 | import javax.microedition.lcdui.*; 5 | import javax.microedition.midlet.*; 6 | 7 | import org.ksoap2.*; 8 | import org.ksoap2.serialization.*; 9 | import org.ksoap2.transport.*; 10 | 11 | 12 | 13 | public class SoapDemo extends MIDlet implements CommandListener{ 14 | 15 | private Display display; 16 | 17 | Form mainForm = new Form ("Hello World WebService"); 18 | TextField nameField = new TextField ("Your name","",456,TextField.ANY); 19 | Command getCommand = new Command ("send", Command.SCREEN, 1); 20 | 21 | public SoapDemo () { 22 | mainForm.append (nameField); 23 | mainForm.addCommand (getCommand); 24 | mainForm.setCommandListener (this); 25 | } 26 | 27 | public void startApp() { 28 | display = Display.getDisplay (this); 29 | display.setCurrent (mainForm); 30 | } 31 | 32 | public void pauseApp() { 33 | } 34 | 35 | public void destroyApp(boolean unconditional) { 36 | } 37 | 38 | 39 | public void commandAction(Command c, Displayable s) { 40 | if (c == getCommand) { 41 | final TextBox t = new TextBox("", "", 256, 0); 42 | Thread thr = new Thread(){ 43 | public void run() { 44 | try { 45 | 46 | SoapObject client = new 47 | SoapObject("","getObject"); 48 | client.addProperty("name",nameField.getString()); 49 | SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 50 | envelope.bodyOut = client; 51 | HttpTransport ht = new 52 | HttpTransport("http://localhost:8080/axis/services/AxisService"); 53 | ht.call("", envelope); 54 | 55 | SoapObject ret = new SoapObject("http://ws.wessendorf.net","CustomObject"); 56 | ret = (SoapObject) envelope.getResponse(); 57 | t.setString(ret.getProperty(0).toString()); 58 | } 59 | catch ( SoapFault sf){ 60 | String faultString = "Code: " + sf.faultcode + "\nString: " + sf.faultstring; 61 | t.setString(faultString); 62 | } 63 | catch ( Exception e){ 64 | e.printStackTrace(); 65 | t.setString(e.getMessage()); 66 | } 67 | }}; 68 | thr.start(); 69 | display.setCurrent(t); 70 | } 71 | else{ 72 | destroyApp(false); 73 | notifyDestroyed(); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/serialization/SoapObjectTest.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.serialization; 2 | 3 | import junit.framework.*; 4 | 5 | public class SoapObjectTest extends TestCase { 6 | 7 | private static final String ANOTHER_PROPERTY_NAME = "anotherProperty"; 8 | private static final String A_PROPERTY_NAME = "aPropertyName"; 9 | private SoapObject soapObject; 10 | 11 | protected void setUp() throws Exception { 12 | super.setUp(); 13 | soapObject = new SoapObject("namespace", "name"); 14 | } 15 | 16 | public void testFormattingOfToString() { 17 | final String localValue = "propertyValue"; 18 | soapObject.addProperty(A_PROPERTY_NAME, "propertyValue"); 19 | assertEquals("name{" + A_PROPERTY_NAME + "=propertyValue; }", soapObject.toString()); 20 | soapObject.addProperty(ANOTHER_PROPERTY_NAME, new Integer(12)); 21 | assertEquals("name{" + A_PROPERTY_NAME + "=" + localValue + "; " + ANOTHER_PROPERTY_NAME + "=12; }", soapObject.toString()); 22 | } 23 | 24 | public void testEquals() { 25 | SoapObject soapObject2 = new SoapObject("namespace", "name"); 26 | assertTrue(soapObject.equals(soapObject2)); 27 | 28 | soapObject.addProperty(A_PROPERTY_NAME, new Integer(12)); 29 | assertFalse(soapObject.equals(soapObject2)); 30 | 31 | soapObject2.addProperty(A_PROPERTY_NAME, soapObject.getProperty(A_PROPERTY_NAME)); 32 | assertTrue(soapObject.equals(soapObject2)); 33 | 34 | soapObject.equals("bob"); 35 | 36 | assertTrue(soapObject.newInstance().equals(soapObject)); 37 | 38 | } 39 | 40 | public void testSameNumberProperties_DifferentNames() { 41 | SoapObject soapObject2 = soapObject.newInstance(); 42 | soapObject.addProperty(ANOTHER_PROPERTY_NAME, "value"); 43 | soapObject2.addProperty("differentProperty", "differentValue"); 44 | assertFalse(soapObject2.equals(soapObject)); 45 | } 46 | 47 | public void testSameProperties_DifferentValues() { 48 | SoapObject soapObject2 = soapObject.newInstance(); 49 | soapObject.addProperty(ANOTHER_PROPERTY_NAME, "value"); 50 | soapObject2.addProperty(ANOTHER_PROPERTY_NAME, "differentValue"); 51 | assertFalse(soapObject2.equals(soapObject)); 52 | } 53 | 54 | public void testGetPropertyWithIllegalPropertyName() { 55 | try { 56 | soapObject.getProperty("blah"); 57 | fail(); 58 | } catch (RuntimeException e) { 59 | assertEquals(RuntimeException.class.getName(), e.getClass().getName()); 60 | assertEquals("illegal property: blah", e.getMessage()); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /ksoap2-midp/src/main/java/org/ksoap2/transport/ServiceConnectionMidp.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * Copyright (c) 2006, James Seigel, Calgary, AB., Canada 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. */ 21 | 22 | package org.ksoap2.transport; 23 | 24 | import java.io.*; 25 | 26 | import javax.microedition.io.*; 27 | 28 | public class ServiceConnectionMidp implements ServiceConnection { 29 | private HttpConnection connection; 30 | 31 | public ServiceConnectionMidp(String url) throws IOException { 32 | connection = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true); 33 | } 34 | 35 | public void disconnect() throws IOException { 36 | connection.close(); 37 | } 38 | 39 | public void setRequestProperty(String string, String soapAction) throws IOException { 40 | connection.setRequestProperty(string, soapAction); 41 | } 42 | 43 | public void setRequestMethod(String post) throws IOException { 44 | connection.setRequestMethod(post); 45 | } 46 | 47 | public OutputStream openOutputStream() throws IOException { 48 | return connection.openOutputStream(); 49 | } 50 | 51 | public InputStream openInputStream() throws IOException { 52 | return connection.openInputStream(); 53 | } 54 | 55 | public void connect() throws IOException { 56 | throw new RuntimeException("ServiceConnectionMidp.connect is not available."); 57 | } 58 | 59 | public InputStream getErrorStream() { 60 | throw new RuntimeException("ServiceConnectionMidp.getErrorStream is not available."); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/DM.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.serialization; 22 | 23 | import java.io.*; 24 | import org.xmlpull.v1.*; 25 | import org.ksoap2.*; 26 | 27 | /** 28 | * This class is not public, so save a few bytes by using a short class name (DM 29 | * stands for DefaultMarshal)... 30 | */ 31 | class DM implements Marshal { 32 | 33 | public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo expected) throws IOException, XmlPullParserException { 34 | String text = parser.nextText(); 35 | switch (name.charAt(0)) { 36 | case 's': 37 | return text; 38 | case 'i': 39 | return new Integer(Integer.parseInt(text)); 40 | case 'l': 41 | return new Long(Long.parseLong(text)); 42 | case 'b': 43 | return new Boolean(SoapEnvelope.stringToBoolean(text)); 44 | default: 45 | throw new RuntimeException(); 46 | } 47 | } 48 | 49 | public void writeInstance(XmlSerializer writer, Object instance) throws IOException { 50 | writer.text(instance.toString()); 51 | } 52 | 53 | public void register(SoapSerializationEnvelope cm) { 54 | cm.addMapping(cm.xsd, "int", PropertyInfo.INTEGER_CLASS, this); 55 | cm.addMapping(cm.xsd, "long", PropertyInfo.LONG_CLASS, this); 56 | cm.addMapping(cm.xsd, "string", PropertyInfo.STRING_CLASS, this); 57 | cm.addMapping(cm.xsd, "boolean", PropertyInfo.BOOLEAN_CLASS, this); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/transport/mock/ComplexParameter.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, James Seigel, Calgary, AB., Canada 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.transport.mock; 22 | 23 | import java.util.*; 24 | 25 | import org.ksoap2.serialization.*; 26 | 27 | public class ComplexParameter implements KvmSerializable { 28 | 29 | public String name; 30 | public int count; 31 | 32 | public Object getProperty(int index) { 33 | if (index == 0) 34 | return name; 35 | else if (index == 1) 36 | return new Integer(count); 37 | else 38 | throw new RuntimeException("invalid parameter"); 39 | } 40 | 41 | public int getPropertyCount() { 42 | return 2; 43 | } 44 | 45 | public void setProperty(int index, Object value) { 46 | if (index == 0 && value instanceof String) 47 | name = (String) value; 48 | else if (index == 1 && value instanceof Integer) 49 | count = ((Integer) value).intValue(); 50 | else 51 | throw new RuntimeException("invalid parameter"); 52 | 53 | } 54 | 55 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 56 | if (index == 0) { 57 | info.name = "name"; 58 | info.type = PropertyInfo.STRING_CLASS; 59 | info.namespace = ""; 60 | } else if (index == 1) { 61 | info.name = "count"; 62 | info.type = PropertyInfo.INTEGER_CLASS; 63 | info.namespace = ""; 64 | } else { 65 | throw new RuntimeException("invalid parameter"); 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/transport/mock/MockTransport.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.transport.mock; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.lang.reflect.InvocationTargetException; 6 | import java.lang.reflect.Method; 7 | 8 | import org.ksoap2.SoapEnvelope; 9 | import org.ksoap2.serialization.PropertyInfo; 10 | import org.ksoap2.serialization.SoapObject; 11 | import org.ksoap2.transport.Transport; 12 | import org.xmlpull.v1.XmlPullParserException; 13 | 14 | // makes the parse more visible 15 | public class MockTransport extends Transport 16 | { 17 | public void parseResponse(SoapEnvelope envelope, InputStream is) throws XmlPullParserException, 18 | IOException 19 | { 20 | super.parseResponse(envelope, is); 21 | } 22 | 23 | /** 24 | * Overriding method to make it public. 25 | * 26 | * @see org.ksoap2.transport.Transport#createRequestData(org.ksoap2.SoapEnvelope) 27 | */ 28 | public byte[] createRequestData(SoapEnvelope envelope) throws IOException 29 | { 30 | return super.createRequestData(envelope); 31 | } 32 | 33 | public void call(String targetNamespace, SoapEnvelope envelope) throws IOException, 34 | XmlPullParserException 35 | { 36 | throw new RuntimeException("call not currently implemented"); 37 | } 38 | 39 | /** Invoke - from SoapServlet. */ 40 | public static SoapObject invoke(Object service, SoapObject soapReq) throws NoSuchMethodException, 41 | InvocationTargetException, IllegalAccessException 42 | { 43 | String name = soapReq.getName(); 44 | Class types[] = new Class[soapReq.getPropertyCount()]; 45 | Object[] args = new Object[soapReq.getPropertyCount()]; 46 | PropertyInfo arg = new PropertyInfo(); 47 | for (int i = 0; i < types.length; i++) 48 | { 49 | soapReq.getPropertyInfo(i, arg); 50 | types[i] = (Class) arg.type; 51 | args[i] = soapReq.getProperty(i); 52 | } 53 | // expensive invocation here.. optimize with method cache, 54 | // want to support method overloading so need to figure in 55 | // the arg types.. 56 | Object result = null; 57 | try 58 | { 59 | Method method = service.getClass().getMethod(name, types); 60 | result = method.invoke(service, args); 61 | } 62 | catch (NoSuchMethodException nsme) 63 | { 64 | // since the properties do not match the required method calls when 65 | // attributes are present 66 | // we will also search for a call that takes a single "SoapObject" 67 | // as the input. 68 | Method method = service.getClass().getMethod(name, new Class[] { SoapObject.class }); 69 | result = method.invoke(service, new Object[] { soapReq }); 70 | } 71 | SoapObject response = new SoapObject(soapReq.getNamespace(), name + "Response"); 72 | if (result != null) 73 | response.addProperty("return", result); 74 | return response; 75 | } 76 | } -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/search/messages/BookAttributes.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon.search.messages; 2 | 3 | import java.util.*; 4 | 5 | import org.ksoap2.serialization.*; 6 | 7 | public class BookAttributes extends BaseObject { 8 | 9 | private String author = ""; 10 | private String manufacturer; 11 | private String productGroup; 12 | private String title; 13 | private String creator; 14 | 15 | public Object getProperty(int index) { 16 | throw new RuntimeException("BookAttributes.getProperty is not implemented yet"); 17 | } 18 | 19 | public int getPropertyCount() { 20 | return 5; 21 | } 22 | 23 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 24 | info.type = PropertyInfo.STRING_CLASS; 25 | switch (index) { 26 | case 0: 27 | info.name = "Author"; 28 | break; 29 | case 1: 30 | info.name = "Manufacturer"; 31 | break; 32 | case 2: 33 | info.name = "ProductGroup"; 34 | break; 35 | case 3: 36 | info.name = "Title"; 37 | break; 38 | case 4: 39 | info.name = "Creator"; 40 | break; 41 | default: 42 | break; 43 | } 44 | } 45 | 46 | public void setProperty(int index, Object value) { 47 | switch (index) { 48 | case 0: 49 | author += value.toString() + ";"; 50 | break; 51 | case 1: 52 | manufacturer = value.toString(); 53 | break; 54 | case 2: 55 | productGroup = value.toString(); 56 | break; 57 | case 3: 58 | title = value.toString(); 59 | break; 60 | case 4: 61 | creator = value.toString(); 62 | default: 63 | break; 64 | } 65 | } 66 | 67 | public void register(SoapSerializationEnvelope envelope) { 68 | envelope.addMapping(NAMESPACE, "ItemAttributes", this.getClass()); 69 | } 70 | 71 | public String toString() { 72 | StringBuffer buffer = new StringBuffer("*** Attributes ***\n"); 73 | buffer.append("Author: "); 74 | buffer.append(author); 75 | buffer.append("\n"); 76 | buffer.append("Manufacturer: "); 77 | buffer.append(manufacturer); 78 | buffer.append("\n"); 79 | buffer.append("Product Group: "); 80 | buffer.append(productGroup); 81 | buffer.append("\n"); 82 | buffer.append("Title: "); 83 | buffer.append(title); 84 | buffer.append("\n"); 85 | if (creator != null) { 86 | buffer.append("Creator: "); 87 | buffer.append(creator); 88 | buffer.append("\n"); 89 | } 90 | return buffer.toString(); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/soccer/WorldCupSoccer2006Client.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.soccer; 2 | 3 | import org.ksoap2.*; 4 | import org.ksoap2.serialization.*; 5 | import org.ksoap2.transport.*; 6 | 7 | public class WorldCupSoccer2006Client { 8 | private static final String SOAP_ACTION = ""; 9 | private static final String METHOD_NAME = "StadiumNames"; 10 | private static final String NAMESPACE = "http://www.dataaccess.nl/wk2006"; 11 | private static final String URL = "http://www.dataaccess.nl/wk2006/footballpoolwebservice.wso"; 12 | 13 | WorldCupSoccer2006Client() { 14 | SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 15 | SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 16 | envelope.setOutputSoapObject(request); 17 | 18 | addClassMappings(envelope); 19 | // again this example is designed to run with j2se. Just change the transport 20 | // layer to make it work with j2me 21 | HttpTransportSE httpTransportSE = new HttpTransportSE(URL); 22 | try { 23 | httpTransportSE.call(SOAP_ACTION, envelope); 24 | 25 | // Show the elements of the resultant vector. 26 | StadiumNamesResult response = (StadiumNamesResult) envelope.getResponse(); 27 | for (int i = 0; i < response.size(); i++) { 28 | System.out.println(response.elementAt(i)); 29 | } 30 | } catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | private void addClassMappings(SoapSerializationEnvelope envelope) { 36 | createWrappingResultTemplate(envelope); 37 | new StadiumNamesResult().register(envelope, NAMESPACE, "StadiumNamesResult"); 38 | } 39 | 40 | private void createWrappingResultTemplate(SoapSerializationEnvelope envelope) { 41 | // tell ksoap what type of attribute the Resulting Object as. 42 | PropertyInfo info = new PropertyInfo(); 43 | info.name = "StadiumNamesResult"; 44 | info.type = new StadiumNamesResult().getClass(); 45 | 46 | // Demonstration of using a template to describe what the result will 47 | // look like. KSOAP will actually clone this object and fill it with 48 | // the resulting information. 49 | // You could use a real object here as well, your choice. 50 | // However, If you fail to tell ksoap what to 51 | // expect however it will not try to map any 52 | // contained objects to their classes. 53 | 54 | SoapObject template = new SoapObject(NAMESPACE, "StadiumNamesResponse"); 55 | template.addProperty(info, "not important what this is"); 56 | 57 | envelope.addTemplate(template); 58 | } 59 | 60 | public static void main(String[] args) { 61 | new WorldCupSoccer2006Client(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /ksoap2-j2se/src/main/java/org/ksoap2/transport/ServiceConnectionSE.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * Copyright (c) 2006, James Seigel, Calgary, AB., Canada 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. */ 21 | 22 | package org.ksoap2.transport; 23 | 24 | import java.io.*; 25 | import java.net.*; 26 | 27 | /** 28 | * Connection for J2SE environments. 29 | */ 30 | public class ServiceConnectionSE implements ServiceConnection { 31 | 32 | private HttpURLConnection connection; 33 | 34 | /** 35 | * Constructor taking the url to the endpoint for this soap communication 36 | * @param url the url to open the connection to. 37 | */ 38 | public ServiceConnectionSE(String url) throws IOException { 39 | connection = (HttpURLConnection) new URL(url).openConnection(); 40 | connection.setUseCaches(false); 41 | connection.setDoOutput(true); 42 | connection.setDoInput(true); 43 | } 44 | 45 | public void connect() throws IOException { 46 | connection.connect(); 47 | } 48 | 49 | public void disconnect() { 50 | connection.disconnect(); 51 | } 52 | 53 | public void setRequestProperty(String string, String soapAction) { 54 | connection.setRequestProperty(string, soapAction); 55 | } 56 | 57 | public void setRequestMethod(String requestMethod) throws IOException { 58 | connection.setRequestMethod(requestMethod); 59 | } 60 | 61 | public OutputStream openOutputStream() throws IOException { 62 | return connection.getOutputStream(); 63 | } 64 | 65 | public InputStream openInputStream() throws IOException { 66 | return connection.getInputStream(); 67 | } 68 | 69 | public InputStream getErrorStream() { 70 | return connection.getErrorStream(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/KvmSerializable.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | * 21 | * Contributor(s): John D. Beatty, F. Hunter, Renaud Tognelli 22 | * 23 | * */ 24 | 25 | package org.ksoap2.serialization; 26 | 27 | import java.util.Hashtable; 28 | 29 | /** 30 | * Provides get and set methods for properties. Can be used to replace 31 | * reflection (to some extend) for "serialization-aware" classes. Currently used 32 | * in kSOAP and the RMS based kobjects object repository 33 | */ 34 | 35 | public interface KvmSerializable { 36 | 37 | /** 38 | * Returns the property at a specified index (for serialization) 39 | * 40 | * @param index 41 | * the specified index 42 | * @return the serialized property 43 | */ 44 | Object getProperty(int index); 45 | 46 | /** 47 | * @return the number of serializable properties 48 | */ 49 | int getPropertyCount(); 50 | 51 | /** 52 | * Sets the property with the given index to the given value. 53 | * 54 | * @param index 55 | * the index to be set 56 | * @param value 57 | * the value of the property 58 | */ 59 | void setProperty(int index, Object value); 60 | 61 | /** 62 | * Fills the given property info record. 63 | * 64 | * @param index 65 | * the index to be queried 66 | * @param properties 67 | * information about the (de)serializer. Not frequently used. 68 | * @param info 69 | * The return parameter, to be filled with information about the 70 | * property with the given index. 71 | */ 72 | void getPropertyInfo(int index, Hashtable properties, PropertyInfo info); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/Marshal.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.serialization; 22 | 23 | import java.io.*; 24 | import org.xmlpull.v1.*; 25 | 26 | /** 27 | * Interface for custom (de)serialization. 28 | */ 29 | 30 | public interface Marshal { 31 | 32 | /** 33 | * This methods reads an instance from the given parser. For implementation, 34 | * please note that the start and and tag must be consumed. This is not 35 | * symmetric to writeInstance, but otherwise it would not be possible to 36 | * access the attributes of the start tag here. 37 | * 38 | * @param parser 39 | * the xml parser 40 | * @param namespace 41 | * the namespace. 42 | * @return the object read from the xml stream. 43 | */ 44 | public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo expected) throws IOException, XmlPullParserException; 45 | 46 | /** 47 | * Write the instance to the given XmlSerializer. In contrast to 48 | * readInstance, it is not neccessary to care about the surrounding start 49 | * and end tags. Additional attributes must be writen before anything else 50 | * is written. 51 | * 52 | * @param writer 53 | * the xml serializer. 54 | * @param instance 55 | * the instance to write to the writer. 56 | */ 57 | public void writeInstance(XmlSerializer writer, Object instance) throws IOException; 58 | 59 | /** 60 | * Register this Marshal with Envelope 61 | * 62 | * @param envelope 63 | * the soap serialization envelope. 64 | */ 65 | public void register(SoapSerializationEnvelope envelope); 66 | } 67 | -------------------------------------------------------------------------------- /ksoap2-extras/src/test/java/org/ksoap2/transport/HttpTransportBasicAuthTest.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, James Seigel, Calgary, AB., Canada 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.transport; 22 | 23 | import java.io.*; 24 | 25 | import org.kobjects.base64.*; 26 | 27 | public class HttpTransportBasicAuthTest extends TransportTestCase { 28 | 29 | public void testSimpleMessage_nullUsernamePassword() throws Throwable { 30 | String username = null; 31 | String password = null; 32 | MyTransport ht = new MyTransport("a url", username, password); 33 | ht.call(soapAction, envelope); 34 | 35 | assertSerializationDeserialization(); 36 | 37 | assertNull((String) serviceConnection.requestPropertyMap.get("Authorization")); 38 | 39 | } 40 | 41 | public void testSimpleMessage() throws Throwable { 42 | String username = "username"; 43 | String password = "password"; 44 | MyTransport ht = new MyTransport("a url", username, password); 45 | ht.call(soapAction, envelope); 46 | 47 | assertSerializationDeserialization(); 48 | 49 | String authorizationProperty = (String) serviceConnection.requestPropertyMap.get("Authorization"); 50 | assertEquals(basicAuthenticationStringFor(username, password), authorizationProperty); 51 | 52 | } 53 | 54 | private String basicAuthenticationStringFor(String username, String password) { 55 | return "Basic " + Base64.encode((username + ":" + password).getBytes()); 56 | } 57 | 58 | class MyTransport extends HttpTransportBasicAuth { 59 | public MyTransport(String url, String username, String password) { 60 | super(url, username, password); 61 | } 62 | 63 | protected ServiceConnection getServiceConnection() throws IOException { 64 | addBasicAuthentication(serviceConnection); 65 | return serviceConnection; 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/SoapPrimitive.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.serialization; 22 | 23 | /** 24 | * A class that is used to encapsulate primitive types (represented by a string 25 | * in XML serialization). 26 | * 27 | * Basically, the SoapPrimitive class encapsulates "unknown" primitive types 28 | * (similar to SoapObject encapsulating unknown complex types). For example, new 29 | * SoapPrimitive (classMap.xsd, "float", "12.3") allows you to send a float from 30 | * a MIDP device to a server although MIDP does not support floats. In the other 31 | * direction, kSOAP will deserialize any primitive type (=no subelements) that 32 | * are not recognized by the ClassMap to SoapPrimitive, preserving the 33 | * namespace, name and string value (this is how the stockquote example works). 34 | */ 35 | 36 | public class SoapPrimitive { 37 | String namespace; 38 | String name; 39 | String value; 40 | 41 | public SoapPrimitive(String namespace, String name, String value) { 42 | this.namespace = namespace; 43 | this.name = name; 44 | this.value = value; 45 | } 46 | 47 | public boolean equals(Object o) { 48 | if (!(o instanceof SoapPrimitive)) { 49 | return false; 50 | } 51 | SoapPrimitive p = (SoapPrimitive) o; 52 | return name.equals(p.name) && (namespace == null ? p.namespace == null:namespace.equals(p.namespace)) && (value == null ? (p.value == null) : value.equals(p.value)); 53 | } 54 | 55 | public int hashCode() { 56 | return name.hashCode() ^ (namespace == null ? 0 : namespace.hashCode()); 57 | } 58 | 59 | public String toString() { 60 | return value; 61 | } 62 | 63 | public String getNamespace() { 64 | return namespace; 65 | } 66 | 67 | public String getName() { 68 | return name; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /ksoap2-extras/src/main/java/org/ksoap2/transport/HttpTransportBasicAuth.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2006, James Seigel, Calgary, AB., Canada 3 | * Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | * Contributor(s): Paul Spencer, John D. Beatty, Dave Dash, F. Hunter, 23 | * Renaud Tognelli, Thomas Strang, Alexander Krebs, Sean McDaniel 24 | */ 25 | package org.ksoap2.transport; 26 | 27 | import java.io.*; 28 | 29 | /** 30 | * An Http transport layer class which provides a mechanism to login to 31 | * webservices using Basic Authentication on midp platforms. 32 | * 33 | * Thanks to Paul Spencer 34 | */ 35 | public class HttpTransportBasicAuth extends HttpTransport { 36 | private String username; 37 | private String password; 38 | /** 39 | * Constructor with username and password 40 | * 41 | * @param url 42 | * The url address of the webservice endpoint 43 | * @param username 44 | * Username for the Basic Authentication challenge RFC 2617 45 | * @param password 46 | * Password for the Basic Authentication challenge RFC 2617 47 | */ 48 | public HttpTransportBasicAuth(String url, String username, String password) { 49 | super(url); 50 | this.username = username; 51 | this.password = password; 52 | } 53 | 54 | protected ServiceConnection getServiceConnection() throws IOException { 55 | ServiceConnectionMidp midpConnection = new ServiceConnectionMidp(url); 56 | addBasicAuthentication(midpConnection); 57 | return midpConnection; 58 | } 59 | 60 | protected void addBasicAuthentication(ServiceConnection midpConnection) throws IOException { 61 | if (username != null && password != null) { 62 | StringBuffer buf = new StringBuffer(username); 63 | buf.append(':').append(password); 64 | byte[] raw = buf.toString().getBytes(); 65 | buf.setLength(0); 66 | buf.append("Basic "); 67 | org.kobjects.base64.Base64.encode(raw, 0, raw.length, buf); 68 | midpConnection.setRequestProperty("Authorization", buf.toString()); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/transport/ServiceConnection.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * Copyright (c) 2006, James Seigel, Calgary, AB., Canada 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. */ 21 | 22 | package org.ksoap2.transport; 23 | 24 | import java.io.*; 25 | 26 | /** 27 | * Interface to allow the abstraction of the raw transport information 28 | */ 29 | public interface ServiceConnection { 30 | 31 | /** 32 | * Make an outgoing connection. 33 | * 34 | * @exception IOException 35 | */ 36 | public void connect() throws IOException; 37 | 38 | /** 39 | * Disconnect from the outgoing connection 40 | * 41 | * @exception IOException 42 | */ 43 | public void disconnect() throws IOException; 44 | 45 | /** 46 | * Set properties on the outgoing connection. 47 | * 48 | * @param propertyName 49 | * the name of the property to set. For HTTP connections these 50 | * are the request properties in the HTTP Header. 51 | * @param value 52 | * the string to set the property header to. 53 | * @exception IOException 54 | */ 55 | public void setRequestProperty(String propertyName, String value) throws IOException; 56 | 57 | /** 58 | * Sets how to make the requests. For HTTP this is typically POST or GET. 59 | * 60 | * @param requestMethodType 61 | * the type of request method to make the soap call with. 62 | * @exception IOException 63 | */ 64 | public void setRequestMethod(String requestMethodType) throws IOException; 65 | 66 | /** 67 | * Open and return the outputStream to the endpoint. 68 | * 69 | * @exception IOException 70 | * @return the output stream to write the soap message to. 71 | */ 72 | public OutputStream openOutputStream() throws IOException; 73 | 74 | /** 75 | * Opens and returns the inputstream from which to parse the result of the 76 | * soap call. 77 | * 78 | * @exception IOException 79 | * @return the inputstream containing the xml to parse the result from the 80 | * call from. 81 | */ 82 | public InputStream openInputStream() throws IOException; 83 | 84 | /** 85 | * @return the error stream for the call. 86 | */ 87 | public InputStream getErrorStream(); 88 | 89 | } 90 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/SoapEnvelopeTest.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, James Seigel, Calgary, AB., Canada 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2; 22 | 23 | import junit.framework.*; 24 | 25 | public class SoapEnvelopeTest extends TestCase { 26 | 27 | public void testInitialConfigurationCorrect_Version10() { 28 | SoapEnvelope envelope = new SoapEnvelope(SoapEnvelope.VER10); 29 | assertEquals(SoapEnvelope.XSI1999, envelope.xsi); 30 | assertEquals(SoapEnvelope.XSD1999, envelope.xsd); 31 | assertEquals(SoapEnvelope.ENC, envelope.enc); 32 | assertEquals(SoapEnvelope.ENV, envelope.env); 33 | assertEquals(SoapEnvelope.VER10, envelope.version); 34 | } 35 | 36 | public void testInitialConfigurationCorrect_Version11() { 37 | SoapEnvelope envelope = new SoapEnvelope(SoapEnvelope.VER11); 38 | assertEquals(SoapEnvelope.XSI, envelope.xsi); 39 | assertEquals(SoapEnvelope.XSD, envelope.xsd); 40 | assertEquals(SoapEnvelope.ENC, envelope.enc); 41 | assertEquals(SoapEnvelope.ENV, envelope.env); 42 | assertEquals(SoapEnvelope.VER11, envelope.version); 43 | } 44 | 45 | public void testInitialConfigurationCorrect_Version12() { 46 | SoapEnvelope envelope = new SoapEnvelope(SoapEnvelope.VER12); 47 | assertEquals(SoapEnvelope.XSI, envelope.xsi); 48 | assertEquals(SoapEnvelope.XSD, envelope.xsd); 49 | assertEquals(SoapEnvelope.ENC2001, envelope.enc); 50 | assertEquals(SoapEnvelope.ENV2001, envelope.env); 51 | assertEquals(SoapEnvelope.VER12, envelope.version); 52 | } 53 | 54 | public void testStringToBoolean() { 55 | assertTrue(SoapEnvelope.stringToBoolean("true")); 56 | assertTrue(SoapEnvelope.stringToBoolean(" true ")); 57 | assertTrue(SoapEnvelope.stringToBoolean("TRUE")); 58 | assertTrue(SoapEnvelope.stringToBoolean("1")); 59 | assertTrue(SoapEnvelope.stringToBoolean(" 1")); 60 | assertFalse(SoapEnvelope.stringToBoolean("false")); 61 | assertFalse(SoapEnvelope.stringToBoolean("FALSE")); 62 | assertFalse(SoapEnvelope.stringToBoolean("0")); 63 | } 64 | 65 | public void testStringToBoolean_ExceptionalCases() { 66 | assertFalse(SoapEnvelope.stringToBoolean(null)); 67 | assertFalse(SoapEnvelope.stringToBoolean("bob")); 68 | assertFalse(SoapEnvelope.stringToBoolean("1.0")); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/SoapFaultTest.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, James Seigel, Calgary, AB., Canada 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2; 22 | 23 | import java.io.*; 24 | 25 | import junit.framework.*; 26 | 27 | import org.ksoap2.transport.*; 28 | import org.kxml2.io.*; 29 | import org.xmlpull.v1.*; 30 | 31 | public class SoapFaultTest extends TestCase { 32 | private static final String FAULT_STRING = "The ISBN value contains invalid characters"; 33 | 34 | public void testFaultDeserialize() throws Throwable { 35 | SoapFault fault = generateFaultFromFaultString(ServiceConnectionFixture.FAULT_STRING); 36 | assertEquals(ServiceConnectionFixture.FAULT_MESSAGE_STRING, fault.faultstring); 37 | } 38 | 39 | public void testFaultSerialize() throws Throwable { 40 | KXmlSerializer xmlWriter = new KXmlSerializer(); 41 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 42 | xmlWriter.setOutput(outputStream, "UTF-8"); 43 | SoapFault fault = generateFaultFromFaultString(ServiceConnectionFixture.FAULT_STRING); 44 | fault.write(xmlWriter); 45 | // TODO: looks like there might be a problem with the output. There are duplicate open open tags. 46 | String possibleOutputString = "soap:Client"+FAULT_STRING+" 19318224-D The first nine characters must be digits. The last character may be a digit or the letter 'X'. Case is not important. "; 47 | String faultString = new String(outputStream.toByteArray()); 48 | assertEquals(possibleOutputString, faultString); 49 | } 50 | 51 | private SoapFault generateFaultFromFaultString(String faultString) throws XmlPullParserException, IOException { 52 | SoapFault fault = new SoapFault(); 53 | XmlPullParser parser = new KXmlParser(); 54 | parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); 55 | parser.setInput(new StringReader(faultString)); 56 | parser.nextTag(); 57 | parser.nextTag(); 58 | parser.nextTag(); 59 | fault.parse(parser); 60 | return fault; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /ksoap2-j2se/src/test/java/org/ksoap2/serialization/MarshalFloatTest.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.serialization; 2 | 3 | import java.io.*; 4 | import java.math.*; 5 | 6 | import junit.framework.*; 7 | 8 | import org.ksoap2.*; 9 | import org.ksoap2.transport.mock.*; 10 | import org.xmlpull.v1.*; 11 | 12 | public class MarshalFloatTest extends TestCase { 13 | private static final String FLOAT_LABEL = "float"; 14 | 15 | private static final String FLOATING_POINT_VALUE = "12.0"; 16 | 17 | private MarshalFloat marshalFloat; 18 | 19 | protected void setUp() throws Exception { 20 | marshalFloat = new MarshalFloat(); 21 | } 22 | 23 | public void testMarshalDateInbound() throws IOException, XmlPullParserException { 24 | MockXmlPullParser mockXmlPullParser = new MockXmlPullParser(); 25 | mockXmlPullParser.nextText = FLOATING_POINT_VALUE; 26 | Number floatingPointValue = (Number) marshalFloat.readInstance(mockXmlPullParser, null, FLOAT_LABEL, null); 27 | assertTrue(floatingPointValue instanceof Float); 28 | assertEquals(new Float(FLOATING_POINT_VALUE).floatValue(), floatingPointValue.floatValue(), 0.01f); 29 | 30 | floatingPointValue = (Number) marshalFloat.readInstance(mockXmlPullParser, null, "double", null); 31 | assertTrue(floatingPointValue instanceof Double); 32 | assertEquals(new Double(FLOATING_POINT_VALUE).doubleValue(), floatingPointValue.doubleValue(), 0.01); 33 | 34 | floatingPointValue = (Number) marshalFloat.readInstance(mockXmlPullParser, null, "decimal", null); 35 | assertTrue(floatingPointValue instanceof BigDecimal); 36 | assertEquals(new BigDecimal(FLOATING_POINT_VALUE).doubleValue(), floatingPointValue.doubleValue(), 0.01); 37 | 38 | try { 39 | floatingPointValue = (Number) marshalFloat.readInstance(mockXmlPullParser, null, "unknown type", null); 40 | fail(); 41 | } catch (RuntimeException e) { 42 | assertNotNull(e.getMessage()); 43 | } 44 | 45 | } 46 | 47 | public void testMarshalDateOutbound_Float() throws IOException { 48 | MockXmlSerializer writer = new MockXmlSerializer(); 49 | marshalFloat.writeInstance(writer, new Float(12.0)); 50 | assertEquals(FLOATING_POINT_VALUE, writer.getOutputText()); 51 | } 52 | 53 | public void testmarshalDateOutbound_Double() throws IOException { 54 | MockXmlSerializer writer = new MockXmlSerializer(); 55 | marshalFloat.writeInstance(writer, new Double(12.0)); 56 | assertEquals(FLOATING_POINT_VALUE, writer.getOutputText()); 57 | } 58 | 59 | public void testmarshalDateOutbound_Decimal() throws IOException { 60 | MockXmlSerializer writer = new MockXmlSerializer(); 61 | marshalFloat.writeInstance(writer, new BigDecimal(12.0)); 62 | assertEquals("12", writer.getOutputText()); 63 | } 64 | 65 | public void testRegistration_moreIntegrationLike() throws IOException, XmlPullParserException { 66 | MockXmlPullParser pullParser = new MockXmlPullParser(); 67 | pullParser.nextText = FLOATING_POINT_VALUE; 68 | 69 | SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 70 | marshalFloat.register(envelope); 71 | assertTrue(envelope.classToQName.containsKey(Float.class.getName())); 72 | assertTrue(envelope.classToQName.containsKey(Double.class.getName())); 73 | assertTrue(envelope.classToQName.containsKey(BigDecimal.class.getName())); 74 | 75 | Float floatingPointValue = (Float) envelope.readInstance(pullParser, envelope.xsd, FLOAT_LABEL, null); 76 | assertEquals(new Float(FLOATING_POINT_VALUE).floatValue(), floatingPointValue.floatValue(), 0.01f); 77 | 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/transport/mock/ComplexResponse.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, James Seigel, Calgary, AB., Canada 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.transport.mock; 22 | 23 | import java.util.*; 24 | 25 | import org.ksoap2.serialization.*; 26 | 27 | public class ComplexResponse implements KvmSerializable { 28 | public static final String BOOLEAN_RESPONSE_NAME = "booleanResponse"; 29 | public static final String INTEGER_REPONSE_NAME = "integerReponse"; 30 | public String stringResponse; 31 | public long longResponse; 32 | public int integerResponse; 33 | public boolean booleanResponse; 34 | public String namespace = ""; 35 | public String responseOne_Name = "longResponse"; 36 | public int parameterCount = 4; 37 | 38 | public Object getProperty(int index) { 39 | if (index == 0) 40 | return stringResponse; 41 | else if (index == 1) 42 | return new Long(longResponse); 43 | else if (index == 2) { 44 | return new Integer(integerResponse); 45 | } else if (index == 3) { 46 | return new Boolean(booleanResponse); 47 | } else 48 | throw new RuntimeException("invalid parameter"); 49 | } 50 | 51 | public int getPropertyCount() { 52 | return parameterCount; 53 | } 54 | 55 | public void setProperty(int index, Object value) { 56 | if (index == 0 && value instanceof String) 57 | stringResponse = (String) value; 58 | else if (index == 1 && value instanceof Long) 59 | longResponse = ((Long) value).longValue(); 60 | else if (index == 2 ) { 61 | integerResponse = ((Integer) value).intValue(); 62 | } else if (index == 3) { 63 | booleanResponse = ((Boolean) value).booleanValue(); 64 | } else 65 | throw new RuntimeException("invalid parameter in set: "+index+":"+value.toString()+":"+value.getClass().getName()); 66 | } 67 | 68 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 69 | if (index == 0) { 70 | info.name = "stringResponse"; 71 | info.type = PropertyInfo.STRING_CLASS; 72 | } else if (index == 1) { 73 | info.name = responseOne_Name; 74 | info.type = PropertyInfo.LONG_CLASS; 75 | } else if (index == 2) { 76 | info.name = INTEGER_REPONSE_NAME; 77 | info.type = PropertyInfo.INTEGER_CLASS; 78 | } else if (index == 3) { 79 | info.name = BOOLEAN_RESPONSE_NAME; 80 | info.type = PropertyInfo.BOOLEAN_CLASS; 81 | } else { 82 | throw new RuntimeException("invalid parameter"); 83 | } 84 | info.namespace = namespace; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/SoapFault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | * associated documentation files (the "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 8 | * following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all copies or substantial 11 | * portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 14 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 15 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 16 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 17 | * USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | */ 19 | 20 | package org.ksoap2; 21 | 22 | import java.io.IOException; 23 | 24 | import org.kxml2.kdom.Node; 25 | import org.xmlpull.v1.XmlPullParser; 26 | import org.xmlpull.v1.XmlPullParserException; 27 | import org.xmlpull.v1.XmlSerializer; 28 | 29 | /** 30 | * Exception class encapsulating SOAP Faults 31 | */ 32 | 33 | public class SoapFault extends IOException 34 | { 35 | 36 | /** The SOAP fault code */ 37 | public String faultcode; 38 | /** The SOAP fault code */ 39 | public String faultstring; 40 | /** The SOAP fault code */ 41 | public String faultactor; 42 | /** A KDom Node holding the details of the fault */ 43 | public Node detail; 44 | 45 | /** Fills the fault details from the given XML stream */ 46 | public void parse(XmlPullParser parser) throws IOException, XmlPullParserException 47 | { 48 | parser.require(XmlPullParser.START_TAG, SoapEnvelope.ENV, "Fault"); 49 | while (parser.nextTag() == XmlPullParser.START_TAG) 50 | { 51 | String name = parser.getName(); 52 | if (name.equals("detail")) 53 | { 54 | detail = new Node(); 55 | detail.parse(parser); 56 | continue; 57 | } 58 | else if (name.equals("faultcode")) 59 | faultcode = parser.nextText(); 60 | else if (name.equals("faultstring")) 61 | faultstring = parser.nextText(); 62 | else if (name.equals("faultactor")) 63 | faultactor = parser.nextText(); 64 | else 65 | throw new RuntimeException("unexpected tag:" + name); 66 | parser.require(XmlPullParser.END_TAG, null, name); 67 | } 68 | parser.require(XmlPullParser.END_TAG, SoapEnvelope.ENV, "Fault"); 69 | parser.nextTag(); 70 | } 71 | 72 | /** Writes the fault to the given XML stream */ 73 | public void write(XmlSerializer xw) throws IOException 74 | { 75 | xw.startTag(SoapEnvelope.ENV, "Fault"); 76 | xw.startTag(null, "faultcode"); 77 | xw.text("" + faultcode); 78 | xw.endTag(null, "faultcode"); 79 | xw.startTag(null, "faultstring"); 80 | xw.text("" + faultstring); 81 | xw.endTag(null, "faultstring"); 82 | xw.startTag(null, "detail"); 83 | if (detail != null) 84 | detail.write(xw); 85 | xw.endTag(null, "detail"); 86 | xw.endTag(SoapEnvelope.ENV, "Fault"); 87 | } 88 | 89 | /** 90 | * @see java.lang.Throwable#getMessage() 91 | */ 92 | @Override 93 | public String getMessage() 94 | { 95 | return faultstring; 96 | } 97 | 98 | /** Returns a simple string representation of the fault */ 99 | public String toString() 100 | { 101 | return "SoapFault - faultcode: '" + faultcode + "' faultstring: '" + faultstring + "' faultactor: '" 102 | + faultactor + "' detail: " + detail; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /ksoap2-j2se/src/main/java/org/ksoap2/transport/HttpTransportSE.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | * 22 | * Contributor(s): John D. Beatty, Dave Dash, F. Hunter, Alexander Krebs, 23 | * Lars Mehrmann, Sean McDaniel, Thomas Strang, Renaud Tognelli 24 | * */ 25 | package org.ksoap2.transport; 26 | 27 | import java.io.*; 28 | 29 | import org.ksoap2.*; 30 | import org.xmlpull.v1.*; 31 | 32 | /** 33 | * A J2SE based HttpTransport layer. 34 | */ 35 | public class HttpTransportSE extends Transport { 36 | 37 | /** 38 | * Creates instance of HttpTransportSE with set url 39 | * 40 | * @param url 41 | * the destination to POST SOAP data 42 | */ 43 | public HttpTransportSE(String url) { 44 | super(url); 45 | } 46 | 47 | /** 48 | * set the desired soapAction header field 49 | * 50 | * @param soapAction 51 | * the desired soapAction 52 | * @param envelope 53 | * the envelope containing the information for the soap call. 54 | */ 55 | public void call(String soapAction, SoapEnvelope envelope) throws IOException, XmlPullParserException { 56 | if (soapAction == null) 57 | soapAction = "\"\""; 58 | byte[] requestData = createRequestData(envelope); 59 | requestDump = debug ? new String(requestData) : null; 60 | responseDump = null; 61 | ServiceConnection connection = getServiceConnection(); 62 | connection.setRequestProperty("User-Agent", "kSOAP/2.0"); 63 | connection.setRequestProperty("SOAPAction", soapAction); 64 | connection.setRequestProperty("Content-Type", "text/xml"); 65 | connection.setRequestProperty("Connection", "close"); 66 | connection.setRequestProperty("Content-Length", "" + requestData.length); 67 | connection.setRequestMethod("POST"); 68 | connection.connect(); 69 | OutputStream os = connection.openOutputStream(); 70 | os.write(requestData, 0, requestData.length); 71 | os.flush(); 72 | os.close(); 73 | requestData = null; 74 | InputStream is; 75 | try { 76 | connection.connect(); 77 | is = connection.openInputStream(); 78 | } catch (IOException e) { 79 | is = connection.getErrorStream(); 80 | if (is == null) { 81 | connection.disconnect(); 82 | throw (e); 83 | } 84 | } 85 | if (debug) { 86 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 87 | byte[] buf = new byte[256]; 88 | while (true) { 89 | int rd = is.read(buf, 0, 256); 90 | if (rd == -1) 91 | break; 92 | bos.write(buf, 0, rd); 93 | } 94 | bos.flush(); 95 | buf = bos.toByteArray(); 96 | responseDump = new String(buf); 97 | is.close(); 98 | is = new ByteArrayInputStream(buf); 99 | } 100 | parseResponse(envelope, is); 101 | } 102 | 103 | protected ServiceConnection getServiceConnection() throws IOException { 104 | return new ServiceConnectionSE(url); 105 | } 106 | } -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/transport/Transport.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2006, James Seigel, Calgary, AB., Canada 3 | * Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | package org.ksoap2.transport; 25 | 26 | import java.io.*; 27 | 28 | import org.ksoap2.*; 29 | import org.kxml2.io.*; 30 | import org.xmlpull.v1.*; 31 | 32 | /** 33 | * Abstract class which holds common methods and members that are used by the 34 | * transport layers. This class encapsulates the serialization and 35 | * deserialization of the soap messages, leaving the basic communication 36 | * routines to the subclasses. 37 | */ 38 | abstract public class Transport { 39 | 40 | protected String url; 41 | /** Set to true if debugging */ 42 | public boolean debug; 43 | /** String dump of request for debugging. */ 44 | public String requestDump; 45 | /** String dump of response for debugging */ 46 | public String responseDump; 47 | private String xmlVersionTag = ""; 48 | 49 | public Transport() { 50 | } 51 | 52 | public Transport(String url) { 53 | this.url = url; 54 | } 55 | 56 | /** 57 | * Sets up the parsing to hand over to the envelope to deserialize. 58 | */ 59 | protected void parseResponse(SoapEnvelope envelope, InputStream is) throws XmlPullParserException, IOException { 60 | XmlPullParser xp = new KXmlParser(); 61 | xp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); 62 | xp.setInput(is, null); 63 | envelope.parse(xp); 64 | } 65 | 66 | /** 67 | * Serializes the request. 68 | */ 69 | protected byte[] createRequestData(SoapEnvelope envelope) throws IOException { 70 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 71 | bos.write(xmlVersionTag.getBytes()); 72 | XmlSerializer xw = new KXmlSerializer(); 73 | xw.setOutput(bos, null); 74 | envelope.write(xw); 75 | xw.flush(); 76 | bos.write('\r'); 77 | bos.write('\n'); 78 | bos.flush(); 79 | return bos.toByteArray(); 80 | } 81 | 82 | /** 83 | * Set the target url. 84 | * 85 | * @param url 86 | * the target url. 87 | */ 88 | public void setUrl(String url) { 89 | this.url = url; 90 | } 91 | 92 | /** 93 | * Sets the version tag for the outgoing soap call. Example 95 | * 96 | * @param tag 97 | * the xml string to set at the top of the soap message. 98 | */ 99 | public void setXmlVersionTag(String tag) { 100 | xmlVersionTag = tag; 101 | } 102 | 103 | /** 104 | * Attempts to reset the connection. 105 | */ 106 | public void reset() { 107 | } 108 | 109 | /** 110 | * Perform a soap call with a given namespace and the given envelope. 111 | * 112 | * @param targetNamespace 113 | * the namespace with which to perform the call in. 114 | * @param envelope 115 | * the envelope the contains the information for the call. 116 | */ 117 | abstract public void call(String targetNamespace, SoapEnvelope envelope) throws IOException, XmlPullParserException; 118 | 119 | } 120 | -------------------------------------------------------------------------------- /eclipseTemplates.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/MarshalHashtable.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | * 21 | * Contributor(s): Sean McDaniel 22 | * 23 | * */ 24 | 25 | package org.ksoap2.serialization; 26 | 27 | import java.io.*; 28 | import java.util.*; 29 | 30 | import org.xmlpull.v1.*; 31 | 32 | /** 33 | * Serializes instances of hashtable to and from xml. This implementation is 34 | * based on the xml schema from apache-soap, namely the type 'map' in the 35 | * namespace 'http://xml.apache.org/xml-soap'. Other soap implementations 36 | * including apache (obviously) and glue are also interoperable with the 37 | * schema. 38 | */ 39 | public class MarshalHashtable implements Marshal { 40 | 41 | /** use then during registration */ 42 | public static final String NAMESPACE = "http://xml.apache.org/xml-soap"; 43 | /** use then during registration */ 44 | public static final String NAME = "Map"; 45 | /** CLDC does not support .class, so this helper is needed. */ 46 | public static final Class HASHTABLE_CLASS = new Hashtable().getClass(); 47 | SoapSerializationEnvelope envelope; 48 | 49 | public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo expected) throws IOException, XmlPullParserException { 50 | Hashtable instance = new Hashtable(); 51 | String elementName = parser.getName(); 52 | while (parser.nextTag() != XmlPullParser.END_TAG) { 53 | SoapObject item = new ItemSoapObject(instance); 54 | parser.require(XmlPullParser.START_TAG, null, "item"); 55 | parser.nextTag(); 56 | Object key = envelope.read(parser, item, 0, null, null, PropertyInfo.OBJECT_TYPE); 57 | parser.nextTag(); 58 | if (key != null) { 59 | item.setProperty(0, key); 60 | } 61 | Object value = envelope.read(parser, item, 1, null, null, PropertyInfo.OBJECT_TYPE); 62 | parser.nextTag(); 63 | if (value != null) { 64 | item.setProperty(1, value); 65 | } 66 | parser.require(XmlPullParser.END_TAG, null, "item"); 67 | } 68 | parser.require(XmlPullParser.END_TAG, null, elementName); 69 | return instance; 70 | } 71 | 72 | public void writeInstance(XmlSerializer writer, Object instance) throws IOException { 73 | Hashtable h = (Hashtable) instance; 74 | SoapObject item = new SoapObject(null, null); 75 | item.addProperty("key", null); 76 | item.addProperty("value", null); 77 | for (Enumeration keys = h.keys(); keys.hasMoreElements();) { 78 | writer.startTag("", "item"); 79 | Object key = keys.nextElement(); 80 | item.setProperty(0, key); 81 | item.setProperty(1, h.get(key)); 82 | envelope.writeObjectBody(writer, item); 83 | writer.endTag("", "item"); 84 | } 85 | } 86 | 87 | class ItemSoapObject extends SoapObject { 88 | Hashtable h; 89 | int resolvedIndex = -1; 90 | ItemSoapObject(Hashtable h) { 91 | super(null, null); 92 | this.h = h; 93 | addProperty("key", null); 94 | addProperty("value", null); 95 | } 96 | 97 | // 0 & 1 only valid 98 | public void setProperty(int index, Object value) { 99 | if (resolvedIndex == -1) { 100 | super.setProperty(index, value); 101 | resolvedIndex = index; 102 | } else { 103 | // already have a key or value 104 | Object resolved = resolvedIndex == 0 ? getProperty(0) : getProperty(1); 105 | if (index == 0) 106 | h.put(value, resolved); 107 | else 108 | h.put(resolved, value); 109 | } 110 | } 111 | } 112 | 113 | public void register(SoapSerializationEnvelope cm) { 114 | envelope = cm; 115 | cm.addMapping(MarshalHashtable.NAMESPACE, MarshalHashtable.NAME, HASHTABLE_CLASS, this); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /ksoap2-samples/src/main/java/org/ksoap2/samples/amazon/AmazonDemo.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.samples.amazon; 2 | 3 | import java.util.Vector; 4 | 5 | import javax.microedition.midlet.*; 6 | import javax.microedition.lcdui.*; 7 | 8 | import org.ksoap2.*; 9 | import org.ksoap2.serialization.*; 10 | import org.ksoap2.transport.*; 11 | 12 | /** 13 | * @author Stefan Haustein 14 | * 15 | * To try this demo, you need a developer tag from Amazon.com, see 16 | * http://www.amazon.com/gp/browse.html?node=3435361 17 | * 18 | */ 19 | 20 | public class AmazonDemo extends MIDlet implements CommandListener, Runnable { 21 | 22 | Display display; 23 | 24 | Form mainForm = new Form("Amazon Sample"); 25 | TextField tagField = new TextField("Developer-Tag", "", 64, TextField.ANY); 26 | TextField symbolField = new TextField("Keyword", "pattern", 64, TextField.ANY); 27 | 28 | StringItem statusItem = new StringItem("Status", "idle"); 29 | //TextField tagField = new TextField("") 30 | // StringItem resultItem = new StringItem("", ""); 31 | static Command getCommand = new Command("Get", Command.SCREEN, 1); 32 | static Command detailCommand = new Command("Details", Command.SCREEN, 1); 33 | static Command newCommand = new Command("New", Command.SCREEN, 1); 34 | static Command backCommand = new Command("Back", Command.BACK, 1); 35 | Vector resultVector; 36 | List resultList; 37 | 38 | public AmazonDemo() { 39 | mainForm.append(tagField); 40 | mainForm.append(symbolField); 41 | mainForm.append(statusItem); 42 | mainForm.addCommand(getCommand); 43 | mainForm.setCommandListener(this); 44 | } 45 | 46 | public void startApp() { 47 | display = Display.getDisplay(this); 48 | display.setCurrent(mainForm); 49 | } 50 | 51 | public void pauseApp() { 52 | } 53 | 54 | public void destroyApp(boolean unconditional) { 55 | } 56 | 57 | 58 | public void run(){ 59 | try { 60 | // build request string 61 | String symbol = symbolField.getString(); 62 | 63 | statusItem.setText("building request"); 64 | 65 | SoapObject rpc = 66 | new SoapObject("urn:PI/DevCentral/SoapService", "KeywordSearchRequest"); 67 | 68 | 69 | SoapObject ro = new SoapObject("urn:PI/DevCentral/SoapService", "KeywordRequest"); 70 | 71 | ro.addProperty("keyword", symbol.trim().toLowerCase()); 72 | ro.addProperty("tag", "webservices-20"); 73 | ro.addProperty("type", "lite"); 74 | ro.addProperty("mode", "book"); 75 | ro.addProperty("page", "1"); 76 | ro.addProperty("devtag", tagField.getString()); 77 | 78 | rpc.addProperty("KeywordSearchRequest", ro); 79 | 80 | /* 81 | dog 82 | 1 83 | book 84 | webservices-20 85 | lite 86 | your-dev-tag 87 | xml 88 | 1.0 89 | */ 90 | 91 | 92 | SoapSerializationEnvelope envelope = 93 | new SoapSerializationEnvelope(SoapEnvelope.VER11); 94 | 95 | envelope.bodyOut = rpc; 96 | 97 | //resultItem.setLabel(symbol); 98 | 99 | HttpTransport ht = new HttpTransport("http://soap.amazon.com/onca/soap3"); 100 | ht.debug = true; 101 | 102 | statusItem.setText("submitting request"); 103 | 104 | try{ 105 | 106 | ht.call(null, envelope); 107 | 108 | statusItem.setText("analyzing results..."); 109 | 110 | System.err.println (ht.responseDump); 111 | 112 | SoapObject result = (SoapObject) envelope.getResponse(); 113 | 114 | resultVector = (Vector) result.getProperty("Details"); //.getProperty("Details"); 115 | 116 | 117 | resultList = new List("Result", List.IMPLICIT); 118 | resultList.addCommand(newCommand); 119 | resultList.addCommand(detailCommand); 120 | resultList.setCommandListener(this); 121 | 122 | for(int i = 0; i < resultVector.size(); i++){ 123 | SoapObject detail = (SoapObject) resultVector.elementAt(i); 124 | resultList.append((String) detail.getProperty("ProductName"), null); 125 | } 126 | 127 | display.setCurrent(resultList); 128 | 129 | // for(int i = 0; i < result.getPropertyCount()) 130 | } 131 | catch (SoapFault f) { 132 | // e.printStackTrace(); 133 | // System.err.println (ht.requestDump); 134 | // System.err.println (ht.responseDump); 135 | 136 | statusItem.setText("Error (perhaps keyword not found): "+f.faultstring); 137 | } 138 | 139 | 140 | } 141 | catch (Exception e) { 142 | e.printStackTrace(); 143 | statusItem.setText("Error: "+ e.toString()); 144 | } 145 | 146 | } 147 | 148 | 149 | public void commandAction(Command c, Displayable d) { 150 | if(c == getCommand){ 151 | new Thread(this).start(); 152 | } 153 | else if(c == newCommand){ 154 | display.setCurrent(mainForm); 155 | statusItem.setText("idle"); 156 | } 157 | else if(c == backCommand){ 158 | display.setCurrent(resultList); 159 | } 160 | else { 161 | int sel = resultList.getSelectedIndex(); 162 | SoapObject details = (SoapObject) resultVector.elementAt(sel); 163 | 164 | Form detailForm = new Form("Details: "+resultList.getString(sel)); 165 | detailForm.setCommandListener(this); 166 | detailForm.addCommand(backCommand); 167 | PropertyInfo pi = new PropertyInfo(); 168 | for(int i = 0; i < details.getPropertyCount(); i++) { 169 | details.getPropertyInfo(i, null, pi); 170 | if(pi.name.toLowerCase().indexOf("url")==-1) 171 | detailForm.append(new StringItem(pi.name, ""+details.getProperty(i))); 172 | } 173 | display.setCurrent(detailForm); 174 | } 175 | } 176 | 177 | } 178 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/PropertyInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | * associated documentation files (the "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 8 | * following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all copies or substantial 11 | * portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 14 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 15 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 16 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 17 | * USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | * 19 | * Contributor(s): John D. Beatty, F. Hunter, Renaud Tognelli 20 | */ 21 | 22 | package org.ksoap2.serialization; 23 | 24 | /** 25 | * This class is used to store information about each property an implementation of KvmSerializable exposes. 26 | */ 27 | 28 | public class PropertyInfo 29 | { 30 | public static final Class OBJECT_CLASS = new Object().getClass(); 31 | public static final Class STRING_CLASS = "".getClass(); 32 | public static final Class INTEGER_CLASS = new Integer(0).getClass(); 33 | public static final Class LONG_CLASS = new Long(0).getClass(); 34 | public static final Class BOOLEAN_CLASS = new Boolean(true).getClass(); 35 | public static final Class VECTOR_CLASS = new java.util.Vector().getClass(); 36 | public static final PropertyInfo OBJECT_TYPE = new PropertyInfo(); 37 | public static final int TRANSIENT = 1; 38 | public static final int MULTI_REF = 2; 39 | public static final int REF_ONLY = 4; 40 | 41 | /** 42 | * Name of the property 43 | */ 44 | public String name; 45 | 46 | /** 47 | * Namespace of this property 48 | */ 49 | public String namespace; 50 | 51 | /** 52 | * Type of property, Transient, multi_ref, Ref_only *JHS* Note, not really used that effectively 53 | */ 54 | public int flags; 55 | 56 | /** 57 | * The current value of this property. 58 | */ 59 | protected Object value; 60 | 61 | /** 62 | * Type of the property/elements. Should usually be an instance of Class. 63 | */ 64 | public Object type = OBJECT_CLASS; 65 | 66 | /** 67 | * if a property is multi-referenced, set this flag to true. 68 | */ 69 | public boolean multiRef; 70 | 71 | /** 72 | * Element type for array properties, null if not array prop. 73 | */ 74 | public PropertyInfo elementType; 75 | 76 | public PropertyInfo() 77 | { 78 | } 79 | 80 | public void clear() 81 | { 82 | type = OBJECT_CLASS; 83 | flags = 0; 84 | name = null; 85 | namespace = null; 86 | } 87 | 88 | /** 89 | * @return Returns the elementType. 90 | */ 91 | public PropertyInfo getElementType() 92 | { 93 | return elementType; 94 | } 95 | 96 | /** 97 | * @param elementType 98 | * The elementType to set. 99 | */ 100 | public void setElementType(PropertyInfo elementType) 101 | { 102 | this.elementType = elementType; 103 | } 104 | 105 | /** 106 | * @return Returns the flags. 107 | */ 108 | public int getFlags() 109 | { 110 | return flags; 111 | } 112 | 113 | /** 114 | * @param flags 115 | * The flags to set. 116 | */ 117 | public void setFlags(int flags) 118 | { 119 | this.flags = flags; 120 | } 121 | 122 | /** 123 | * @return Returns the multiRef. 124 | */ 125 | public boolean isMultiRef() 126 | { 127 | return multiRef; 128 | } 129 | 130 | /** 131 | * @param multiRef 132 | * The multiRef to set. 133 | */ 134 | public void setMultiRef(boolean multiRef) 135 | { 136 | this.multiRef = multiRef; 137 | } 138 | 139 | /** 140 | * @return Returns the name. 141 | */ 142 | public String getName() 143 | { 144 | return name; 145 | } 146 | 147 | /** 148 | * @param name 149 | * The name to set. 150 | */ 151 | public void setName(String name) 152 | { 153 | this.name = name; 154 | } 155 | 156 | /** 157 | * @return Returns the namespace. 158 | */ 159 | public String getNamespace() 160 | { 161 | return namespace; 162 | } 163 | 164 | /** 165 | * @param namespace 166 | * The namespace to set. 167 | */ 168 | public void setNamespace(String namespace) 169 | { 170 | this.namespace = namespace; 171 | } 172 | 173 | /** 174 | * @return Returns the type. 175 | */ 176 | public Object getType() 177 | { 178 | return type; 179 | } 180 | 181 | /** 182 | * @param type 183 | * The type to set. 184 | */ 185 | public void setType(Object type) 186 | { 187 | this.type = type; 188 | } 189 | 190 | /** 191 | * @return Returns the value. 192 | */ 193 | public Object getValue() 194 | { 195 | return value; 196 | } 197 | 198 | /** 199 | * @param value 200 | * The value to set. 201 | */ 202 | public void setValue(Object value) 203 | { 204 | this.value = value; 205 | } 206 | 207 | /** 208 | * Show the name and value. 209 | * 210 | * @see java.lang.Object#toString() 211 | */ 212 | public String toString() 213 | { 214 | StringBuffer sb = new StringBuffer(); 215 | sb.append(name); 216 | sb.append(" : "); 217 | if (value != null) 218 | { 219 | sb.append(value); 220 | } 221 | else 222 | { 223 | sb.append("(not set)"); 224 | } 225 | return sb.toString(); 226 | } 227 | } -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/transport/mock/MockXmlSerializer.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.transport.mock; 2 | 3 | import java.io.*; 4 | 5 | import org.xmlpull.v1.*; 6 | 7 | public class MockXmlSerializer implements XmlSerializer { 8 | 9 | public static final String PREFIX = "PREFIX"; 10 | public String outputText = ""; 11 | public String propertyType = ""; 12 | public String endtag = ""; 13 | public String startTag = ""; 14 | 15 | public XmlSerializer attribute(String arg0, String label, String type) throws IOException, IllegalArgumentException, IllegalStateException { 16 | propertyType += (type + ";"); 17 | return this; 18 | } 19 | 20 | public void cdsect(String arg0) throws IOException, IllegalArgumentException, IllegalStateException { 21 | throw new UnsupportedOperationException("MockXmlSerializer.cdsect is not implemented yet"); 22 | } 23 | 24 | public void comment(String arg0) throws IOException, IllegalArgumentException, IllegalStateException { 25 | throw new UnsupportedOperationException("MockXmlSerializer.comment is not implemented yet"); 26 | } 27 | 28 | public void docdecl(String arg0) throws IOException, IllegalArgumentException, IllegalStateException { 29 | throw new UnsupportedOperationException("MockXmlSerializer.docdecl is not implemented yet"); 30 | } 31 | 32 | public void endDocument() throws IOException, IllegalArgumentException, IllegalStateException { 33 | throw new UnsupportedOperationException("MockXmlSerializer.endDocument is not implemented yet"); 34 | } 35 | 36 | public XmlSerializer endTag(String arg0, String tag) throws IOException, IllegalArgumentException, IllegalStateException { 37 | endtag += (tag + ";"); 38 | return this; 39 | } 40 | 41 | public void entityRef(String arg0) throws IOException, IllegalArgumentException, IllegalStateException { 42 | throw new UnsupportedOperationException("MockXmlSerializer.entityRef is not implemented yet"); 43 | } 44 | 45 | public void flush() throws IOException { 46 | throw new UnsupportedOperationException("MockXmlSerializer.flush is not implemented yet"); 47 | } 48 | 49 | public int getDepth() { 50 | throw new UnsupportedOperationException("MockXmlSerializer.getDepth is not implemented yet"); 51 | } 52 | 53 | public boolean getFeature(String arg0) { 54 | throw new UnsupportedOperationException("MockXmlSerializer.getFeature is not implemented yet"); 55 | } 56 | 57 | public String getName() { 58 | throw new UnsupportedOperationException("MockXmlSerializer.getName is not implemented yet"); 59 | } 60 | 61 | public String getNamespace() { 62 | throw new UnsupportedOperationException("MockXmlSerializer.getNamespace is not implemented yet"); 63 | } 64 | 65 | public String getPrefix(String arg0, boolean arg1) throws IllegalArgumentException { 66 | return PREFIX; 67 | } 68 | 69 | public Object getProperty(String arg0) { 70 | throw new UnsupportedOperationException("MockXmlSerializer.getProperty is not implemented yet"); 71 | } 72 | 73 | public void ignorableWhitespace(String arg0) throws IOException, IllegalArgumentException, IllegalStateException { 74 | throw new UnsupportedOperationException("MockXmlSerializer.ignorableWhitespace is not implemented yet"); 75 | } 76 | 77 | public void processingInstruction(String arg0) throws IOException, IllegalArgumentException, IllegalStateException { 78 | throw new UnsupportedOperationException("MockXmlSerializer.processingInstruction is not implemented yet"); 79 | } 80 | 81 | public void setFeature(String arg0, boolean arg1) throws IllegalArgumentException, IllegalStateException { 82 | throw new UnsupportedOperationException("MockXmlSerializer.setFeature is not implemented yet"); 83 | } 84 | 85 | public void setOutput(Writer arg0) throws IOException, IllegalArgumentException, IllegalStateException { 86 | throw new UnsupportedOperationException("MockXmlSerializer.setOutput is not implemented yet"); 87 | } 88 | 89 | public void setOutput(OutputStream arg0, String arg1) throws IOException, IllegalArgumentException, IllegalStateException { 90 | throw new UnsupportedOperationException("MockXmlSerializer.setOutput is not implemented yet"); 91 | } 92 | 93 | public void setPrefix(String arg0, String arg1) throws IOException, IllegalArgumentException, IllegalStateException { 94 | throw new UnsupportedOperationException("MockXmlSerializer.setPrefix is not implemented yet"); 95 | } 96 | 97 | public void setProperty(String arg0, Object arg1) throws IllegalArgumentException, IllegalStateException { 98 | throw new UnsupportedOperationException("MockXmlSerializer.setProperty is not implemented yet"); 99 | } 100 | 101 | public void startDocument(String arg0, Boolean arg1) throws IOException, IllegalArgumentException, IllegalStateException { 102 | throw new UnsupportedOperationException("MockXmlSerializer.startDocument is not implemented yet"); 103 | } 104 | 105 | public XmlSerializer startTag(String arg0, String key) throws IOException, IllegalArgumentException, IllegalStateException { 106 | startTag += (key + ";"); 107 | return this; 108 | } 109 | 110 | public XmlSerializer text(String text) throws IOException, IllegalArgumentException, IllegalStateException { 111 | outputText += (text + ";"); 112 | return this; 113 | } 114 | 115 | public XmlSerializer text(char[] arg0, int arg1, int arg2) throws IOException, IllegalArgumentException, IllegalStateException { 116 | throw new UnsupportedOperationException("MockXmlSerializer.text is not implemented yet"); 117 | } 118 | 119 | public String getOutputText() { 120 | return outputText.substring(0, outputText.length() - 1); 121 | } 122 | 123 | public String getEndtag() { 124 | return endtag.substring(0, endtag.length() - 1); 125 | } 126 | 127 | public String getPropertyType() { 128 | return propertyType.substring(0, propertyType.length() - 1); 129 | } 130 | 131 | public String getStartTag() { 132 | return startTag.substring(0, startTag.length() - 1); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /ksoap2-base/src/test/java/org/ksoap2/transport/mock/MockXmlPullParser.java: -------------------------------------------------------------------------------- 1 | package org.ksoap2.transport.mock; 2 | 3 | import java.io.*; 4 | 5 | import org.xmlpull.v1.*; 6 | 7 | public class MockXmlPullParser implements XmlPullParser { 8 | 9 | public String nextText; 10 | 11 | public void defineEntityReplacementText(String arg0, String arg1) throws XmlPullParserException { 12 | throw new UnsupportedOperationException("MockXmlPullParser.defineEntityReplacementText is not implemented yet"); 13 | } 14 | 15 | public int getAttributeCount() { 16 | throw new UnsupportedOperationException("MockXmlPullParser.getAttributeCount is not implemented yet"); 17 | } 18 | 19 | public String getAttributeName(int arg0) { 20 | throw new UnsupportedOperationException("MockXmlPullParser.getAttributeName is not implemented yet"); 21 | } 22 | 23 | public String getAttributeNamespace(int arg0) { 24 | throw new UnsupportedOperationException("MockXmlPullParser.getAttributeNamespace is not implemented yet"); 25 | } 26 | 27 | public String getAttributePrefix(int arg0) { 28 | throw new UnsupportedOperationException("MockXmlPullParser.getAttributePrefix is not implemented yet"); 29 | } 30 | 31 | public String getAttributeType(int arg0) { 32 | throw new UnsupportedOperationException("MockXmlPullParser.getAttributeType is not implemented yet"); 33 | } 34 | 35 | public String getAttributeValue(int arg0) { 36 | throw new UnsupportedOperationException("MockXmlPullParser.getAttributeValue is not implemented yet"); 37 | } 38 | 39 | public String getAttributeValue(String arg0, String arg1) { 40 | throw new UnsupportedOperationException("MockXmlPullParser.getAttributeValue is not implemented yet"); 41 | } 42 | 43 | public int getColumnNumber() { 44 | throw new UnsupportedOperationException("MockXmlPullParser.getColumnNumber is not implemented yet"); 45 | } 46 | 47 | public int getDepth() { 48 | throw new UnsupportedOperationException("MockXmlPullParser.getDepth is not implemented yet"); 49 | } 50 | 51 | public int getEventType() throws XmlPullParserException { 52 | throw new UnsupportedOperationException("MockXmlPullParser.getEventType is not implemented yet"); 53 | } 54 | 55 | public boolean getFeature(String arg0) { 56 | throw new UnsupportedOperationException("MockXmlPullParser.getFeature is not implemented yet"); 57 | } 58 | 59 | public String getInputEncoding() { 60 | throw new UnsupportedOperationException("MockXmlPullParser.getInputEncoding is not implemented yet"); 61 | } 62 | 63 | public int getLineNumber() { 64 | throw new UnsupportedOperationException("MockXmlPullParser.getLineNumber is not implemented yet"); 65 | } 66 | 67 | public String getName() { 68 | throw new UnsupportedOperationException("MockXmlPullParser.getName is not implemented yet"); 69 | } 70 | 71 | public String getNamespace() { 72 | throw new UnsupportedOperationException("MockXmlPullParser.getNamespace is not implemented yet"); 73 | } 74 | 75 | public String getNamespace(String arg0) { 76 | throw new UnsupportedOperationException("MockXmlPullParser.getNamespace is not implemented yet"); 77 | } 78 | 79 | public int getNamespaceCount(int arg0) throws XmlPullParserException { 80 | throw new UnsupportedOperationException("MockXmlPullParser.getNamespaceCount is not implemented yet"); 81 | } 82 | 83 | public String getNamespacePrefix(int arg0) throws XmlPullParserException { 84 | throw new UnsupportedOperationException("MockXmlPullParser.getNamespacePrefix is not implemented yet"); 85 | } 86 | 87 | public String getNamespaceUri(int arg0) throws XmlPullParserException { 88 | throw new UnsupportedOperationException("MockXmlPullParser.getNamespaceUri is not implemented yet"); 89 | } 90 | 91 | public String getPositionDescription() { 92 | throw new UnsupportedOperationException("MockXmlPullParser.getPositionDescription is not implemented yet"); 93 | } 94 | 95 | public String getPrefix() { 96 | throw new UnsupportedOperationException("MockXmlPullParser.getPrefix is not implemented yet"); 97 | } 98 | 99 | public Object getProperty(String arg0) { 100 | throw new UnsupportedOperationException("MockXmlPullParser.getProperty is not implemented yet"); 101 | } 102 | 103 | public String getText() { 104 | throw new UnsupportedOperationException("MockXmlPullParser.getText is not implemented yet"); 105 | } 106 | 107 | public char[] getTextCharacters(int[] arg0) { 108 | throw new UnsupportedOperationException("MockXmlPullParser.getTextCharacters is not implemented yet"); 109 | } 110 | 111 | public boolean isAttributeDefault(int arg0) { 112 | throw new UnsupportedOperationException("MockXmlPullParser.isAttributeDefault is not implemented yet"); 113 | } 114 | 115 | public boolean isEmptyElementTag() throws XmlPullParserException { 116 | throw new UnsupportedOperationException("MockXmlPullParser.isEmptyElementTag is not implemented yet"); 117 | } 118 | 119 | public boolean isWhitespace() throws XmlPullParserException { 120 | throw new UnsupportedOperationException("MockXmlPullParser.isWhitespace is not implemented yet"); 121 | } 122 | 123 | public int next() throws XmlPullParserException, IOException { 124 | throw new UnsupportedOperationException("MockXmlPullParser.next is not implemented yet"); 125 | } 126 | 127 | public int nextTag() throws XmlPullParserException, IOException { 128 | throw new UnsupportedOperationException("MockXmlPullParser.nextTag is not implemented yet"); 129 | } 130 | 131 | public String nextText() throws XmlPullParserException, IOException { 132 | return nextText; 133 | } 134 | 135 | public int nextToken() throws XmlPullParserException, IOException { 136 | throw new UnsupportedOperationException("MockXmlPullParser.nextToken is not implemented yet"); 137 | } 138 | 139 | public void require(int arg0, String arg1, String arg2) throws XmlPullParserException, IOException { 140 | throw new UnsupportedOperationException("MockXmlPullParser.require is not implemented yet"); 141 | } 142 | 143 | public void setFeature(String arg0, boolean arg1) throws XmlPullParserException { 144 | throw new UnsupportedOperationException("MockXmlPullParser.setFeature is not implemented yet"); 145 | } 146 | 147 | public void setInput(Reader arg0) throws XmlPullParserException { 148 | throw new UnsupportedOperationException("MockXmlPullParser.setInput is not implemented yet"); 149 | } 150 | 151 | public void setInput(InputStream arg0, String arg1) throws XmlPullParserException { 152 | throw new UnsupportedOperationException("MockXmlPullParser.setInput is not implemented yet"); 153 | } 154 | 155 | public void setProperty(String arg0, Object arg1) throws XmlPullParserException { 156 | throw new UnsupportedOperationException("MockXmlPullParser.setProperty is not implemented yet"); 157 | } 158 | 159 | } -------------------------------------------------------------------------------- /ksoap2-midp/src/main/java/org/ksoap2/transport/HttpTransport.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | * 21 | * Contributor(s): John D. Beatty, Dave Dash, F. Hunter, Renaud Tognelli, 22 | * Thomas Strang, Alexander Krebs, Sean McDaniel 23 | * */ 24 | 25 | package org.ksoap2.transport; 26 | 27 | import java.io.*; 28 | 29 | import javax.microedition.io.*; 30 | 31 | import org.ksoap2.*; 32 | import org.xmlpull.v1.*; 33 | 34 | /** 35 | * Methods to facilitate SOAP calls over HTTP using the J2ME generic connection 36 | * framework. 37 | *

38 | * Instances of HttpTransport can be in one of two states: connected and not 39 | * connected. When an invocation on call is made the instance is in a connected 40 | * state until call returns or throws an IOException. in any case once control 41 | * is returned to the caller the instance is again in the not connected state. 42 | * HttpTransport is not thread safe and applications should ensure that only one 43 | * thread is inside the call method at any given time. It is designed in such a 44 | * way that applications can reuse a single instance for all soap calls to one, 45 | * or multiple, target endpoints. 46 | *

47 | * 48 | * The underlying HttpConnection is opened with the timeout flag set. In the 49 | * MIDP API this flag is only a hint to the underlying protocol handler to throw 50 | * an InterrruptIOException, however, there are no guarantees that it will be 51 | * handled. So rather than support a timeout mechanism internally the design is 52 | * such that applications can manage timeouts in an environment dependent way. 53 | *

54 | * 55 | * For example some environments may allow for a timeout parameter that can be 56 | * externally specified in perhaps a system property (which? I don't know. it's 57 | * in the api). Others like the emulator (ok, who cares) and the Motorola i85s 58 | * can use a simple and effective timeout mechanism that closes the connection 59 | * and associated streams in an asynchronous fashion. Calling the close( ) 60 | * method inside of a separate thread can provide for this timeout handling by 61 | * releasing threads that maybe stuck inside of call( ) performing network io. 62 | *

63 | * 64 | * Here is some sample code to demonstrate how such a timeout mechanism may 65 | * look:
66 | * 67 | *

 68 |  *    private HttpTransport soap;
 69 |  *    ...
 70 |  *    TimerTask task =
 71 |  *    new TimerTask( ) { public void run( ) { soap.close( ); } };
 72 |  *   
 73 |  *    try {
 74 |  *    new Timer( ).schedule( task, TIMEOUT );
 75 |  *    soap.call( soapobject );  // invoke method
 76 |  *    task.cancel( );           // cancel the timeout
 77 |  *   
 78 |  *    } catch ( InterruptedIOException e ) {
 79 |  *    // handle timeout here...
 80 |  *   
 81 |  *    } catch ( IOException e ) {
 82 |  *    // some other io problem...
 83 |  *    }
 84 |  * 
85 | * 86 | *
87 | * The call( ) method will throw and InterruptedIOException if the instance is 88 | * no longer in the connected state before control is returned to the caller. 89 | * The call to soap.close( ) inside the TimerTask transitions the HttpConnection 90 | * into a not connected state. 91 | *

92 | * Note: The InterruptedIOException will be caught by a thread waiting 93 | * on network io, however, it may not be immediate. It is assumed that the 94 | * protocol handler will gracefully handle the lifecycle of the outputstream and 95 | * therefore it is not closed inside the close method. IOW the waiting thread 96 | * will be interrupted after the outputstream has been flushed. If the waiting 97 | * thread is hung up waiting for input a call to close from a separate thread 98 | * the exception is observed right away and will return before the thread 99 | * calling close. At least this is what has been observation on the i85s 100 | * handset. On this device, if a call to outputstream.close( ) is made 101 | * while the outputstream is being flushed it seems to cause a deadlock, ie 102 | * outputstream will never return. 103 | */ 104 | 105 | public class HttpTransport extends Transport { 106 | ServiceConnection connection; 107 | OutputStream os; 108 | InputStream is; 109 | /** state info */ 110 | private boolean connected = false; 111 | 112 | /** 113 | * Creates instance of HttpTransport with set url 114 | * 115 | * @param url 116 | * the destination to POST SOAP data 117 | */ 118 | public HttpTransport(String url) { 119 | super(url); 120 | } 121 | 122 | /** 123 | * set the desired soapAction header field 124 | * 125 | * @param soapAction 126 | * the desired soapAction 127 | */ 128 | public void call(String soapAction, SoapEnvelope envelope) throws IOException, XmlPullParserException { 129 | if (soapAction == null) 130 | soapAction = "\"\""; 131 | byte[] requestData = createRequestData(envelope); 132 | requestDump = debug ? new String(requestData) : null; 133 | responseDump = null; 134 | try { 135 | connected = true; 136 | connection = getServiceConnection(); 137 | connection.setRequestProperty("SOAPAction", soapAction); 138 | connection.setRequestProperty("Content-Type", "text/xml"); 139 | connection.setRequestProperty("Content-Length", "" + requestData.length); 140 | connection.setRequestProperty("User-Agent", "kSOAP/2.0"); 141 | connection.setRequestMethod(HttpConnection.POST); 142 | os = connection.openOutputStream(); 143 | os.write(requestData, 0, requestData.length); 144 | os.close(); 145 | requestData = null; 146 | is = connection.openInputStream(); 147 | if (debug) { 148 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 149 | byte[] buf = new byte[256]; 150 | while (true) { 151 | int rd = is.read(buf, 0, 256); 152 | if (rd == -1) 153 | break; 154 | bos.write(buf, 0, rd); 155 | } 156 | bos.flush(); 157 | buf = bos.toByteArray(); 158 | responseDump = new String(buf); 159 | is.close(); 160 | is = new ByteArrayInputStream(buf); 161 | } 162 | parseResponse(envelope, is); 163 | } finally { 164 | if (!connected) 165 | throw new InterruptedIOException(); 166 | reset(); 167 | } 168 | if (envelope.bodyIn instanceof SoapFault) 169 | throw ((SoapFault) envelope.bodyIn); 170 | } 171 | 172 | /** 173 | * Closes the connection and associated streams. This method does not need 174 | * to be explictly called since the uderlying connections and streams are 175 | * only opened and valid inside of the call method. Close can be called 176 | * ansynchronously, from another thread to potentially release another 177 | * thread that is hung up doing network io inside of call. Caution should be 178 | * taken, however when using this as a psedu timeout mechanism. it is a 179 | * valid and suggested approach for the motorola handsets. oh, and it works 180 | * in the emulator... 181 | */ 182 | public void reset() { 183 | connected = false; 184 | if (is != null) { 185 | try { 186 | is.close(); 187 | } catch (Throwable e) { 188 | } 189 | is = null; 190 | } 191 | if (connection != null) { 192 | try { 193 | connection.disconnect(); 194 | } catch (Throwable e) { 195 | } 196 | connection = null; 197 | } 198 | } 199 | 200 | protected ServiceConnection getServiceConnection() throws IOException { 201 | return new ServiceConnectionMidp(url); 202 | } 203 | 204 | } 205 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/SoapEnvelope.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2; 22 | 23 | import java.io.*; 24 | import org.kxml2.kdom.*; 25 | import org.xmlpull.v1.*; 26 | 27 | /** 28 | * A SOAP envelope, holding head and body objects. While this basic envelope 29 | * supports literal encoding as content format via KDom, The 30 | * SoapSerializationEnvelope provides support for the SOAP Serialization format 31 | * specification and simple object serialization. 32 | */ 33 | 34 | public class SoapEnvelope { 35 | 36 | /** SOAP Version 1.0 constant */ 37 | public static final int VER10 = 100; 38 | /** SOAP Version 1.1 constant */ 39 | public static final int VER11 = 110; 40 | /** SOAP Version 1.2 constant */ 41 | public static final int VER12 = 120; 42 | public static final String ENV2001 = "http://www.w3.org/2001/12/soap-envelope"; 43 | public static final String ENC2001 = "http://www.w3.org/2001/12/soap-encoding"; 44 | /** Namespace constant: http://schemas.xmlsoap.org/soap/envelope/ */ 45 | public static final String ENV = "http://schemas.xmlsoap.org/soap/envelope/"; 46 | /** Namespace constant: http://schemas.xmlsoap.org/soap/encoding/ */ 47 | public static final String ENC = "http://schemas.xmlsoap.org/soap/encoding/"; 48 | /** Namespace constant: http://www.w3.org/2001/XMLSchema */ 49 | public static final String XSD = "http://www.w3.org/2001/XMLSchema"; 50 | /** Namespace constant: http://www.w3.org/2001/XMLSchema */ 51 | public static final String XSI = "http://www.w3.org/2001/XMLSchema-instance"; 52 | /** Namespace constant: http://www.w3.org/1999/XMLSchema */ 53 | public static final String XSD1999 = "http://www.w3.org/1999/XMLSchema"; 54 | /** Namespace constant: http://www.w3.org/1999/XMLSchema */ 55 | public static final String XSI1999 = "http://www.w3.org/1999/XMLSchema-instance"; 56 | 57 | /** 58 | * Returns true for the string values "1" and "true", ignoring upper/lower 59 | * case and whitespace, false otherwise. 60 | */ 61 | public static boolean stringToBoolean(String booleanAsString) { 62 | if (booleanAsString == null) 63 | return false; 64 | booleanAsString = booleanAsString.trim().toLowerCase(); 65 | return (booleanAsString.equals("1") || booleanAsString.equals("true")); 66 | } 67 | 68 | /** 69 | * The body object received with this envelope. Will be an KDom Node for 70 | * literal encoding. For SOAP Serialization, please refer to 71 | * SoapSerializationEnvelope. 72 | */ 73 | public Object bodyIn; 74 | /** 75 | * The body object to be sent with this envelope. Must be a KDom Node 76 | * modelling the remote call including all parameters for literal encoding. 77 | * For SOAP Serialization, please refer to SoapSerializationEnvelope 78 | */ 79 | public Object bodyOut; 80 | /** 81 | * Incoming header elements 82 | */ 83 | public Element[] headerIn; 84 | /** 85 | * Outgoing header elements 86 | */ 87 | public Element[] headerOut; 88 | public String encodingStyle; 89 | /** 90 | * The SOAP version, set by the constructor 91 | */ 92 | public int version; 93 | /** Envelope namespace, set by the constructor */ 94 | public String env; 95 | /** Encoding namespace, set by the constructor */ 96 | public String enc; 97 | /** Xml Schema instance namespace, set by the constructor */ 98 | public String xsi; 99 | /** Xml Schema data namespace, set by the constructor */ 100 | public String xsd; 101 | 102 | /** 103 | * Initializes a SOAP Envelope. The version parameter must be set to one of 104 | * VER10, VER11 or VER12 105 | */ 106 | public SoapEnvelope(int version) { 107 | this.version = version; 108 | if (version == SoapEnvelope.VER10) { 109 | xsi = SoapEnvelope.XSI1999; 110 | xsd = SoapEnvelope.XSD1999; 111 | } else { 112 | xsi = SoapEnvelope.XSI; 113 | xsd = SoapEnvelope.XSD; 114 | } 115 | if (version < SoapEnvelope.VER12) { 116 | enc = SoapEnvelope.ENC; 117 | env = SoapEnvelope.ENV; 118 | } else { 119 | enc = SoapEnvelope.ENC2001; 120 | env = SoapEnvelope.ENV2001; 121 | } 122 | } 123 | 124 | /** Parses the SOAP envelope from the given parser */ 125 | public void parse(XmlPullParser parser) throws IOException, XmlPullParserException { 126 | parser.nextTag(); 127 | parser.require(XmlPullParser.START_TAG, env, "Envelope"); 128 | encodingStyle = parser.getAttributeValue(env, "encodingStyle"); 129 | parser.nextTag(); 130 | if (parser.getEventType() == XmlPullParser.START_TAG && parser.getNamespace().equals(env) && parser.getName().equals("Header")) { 131 | parseHeader(parser); 132 | parser.require(XmlPullParser.END_TAG, env, "Header"); 133 | parser.nextTag(); 134 | } 135 | parser.require(XmlPullParser.START_TAG, env, "Body"); 136 | encodingStyle = parser.getAttributeValue(env, "encodingStyle"); 137 | parseBody(parser); 138 | parser.require(XmlPullParser.END_TAG, env, "Body"); 139 | parser.nextTag(); 140 | parser.require(XmlPullParser.END_TAG, env, "Envelope"); 141 | } 142 | 143 | public void parseHeader(XmlPullParser parser) throws IOException, XmlPullParserException { 144 | // consume start header 145 | parser.nextTag(); 146 | // look at all header entries 147 | Node headers = new Node(); 148 | headers.parse(parser); 149 | int count = 0; 150 | for (int i = 0; i < headers.getChildCount(); i++) { 151 | Element child = headers.getElement(i); 152 | if (child != null) 153 | count++; 154 | } 155 | headerIn = new Element[count]; 156 | count = 0; 157 | for (int i = 0; i < headers.getChildCount(); i++) { 158 | Element child = headers.getElement(i); 159 | if (child != null) 160 | headerIn[count++] = child; 161 | } 162 | } 163 | 164 | public void parseBody(XmlPullParser parser) throws IOException, XmlPullParserException { 165 | parser.nextTag(); 166 | // insert fault generation code here 167 | if (parser.getEventType() == XmlPullParser.START_TAG && parser.getNamespace().equals(env) && parser.getName().equals("Fault")) { 168 | SoapFault fault = new SoapFault(); 169 | fault.parse(parser); 170 | bodyIn = fault; 171 | } else { 172 | Node node = (bodyIn instanceof Node) ? (Node) bodyIn : new Node(); 173 | node.parse(parser); 174 | bodyIn = node; 175 | } 176 | } 177 | 178 | /** 179 | * Writes the complete envelope including header and body elements to the 180 | * given XML writer. 181 | */ 182 | public void write(XmlSerializer writer) throws IOException { 183 | writer.setPrefix("i", xsi); 184 | writer.setPrefix("d", xsd); 185 | writer.setPrefix("c", enc); 186 | writer.setPrefix("v", env); 187 | writer.startTag(env, "Envelope"); 188 | writer.startTag(env, "Header"); 189 | writeHeader(writer); 190 | writer.endTag(env, "Header"); 191 | writer.startTag(env, "Body"); 192 | writeBody(writer); 193 | writer.endTag(env, "Body"); 194 | writer.endTag(env, "Envelope"); 195 | } 196 | 197 | /** 198 | * Writes the header elements contained in headerOut 199 | */ 200 | public void writeHeader(XmlSerializer writer) throws IOException { 201 | if (headerOut != null) { 202 | for (int i = 0; i < headerOut.length; i++) { 203 | headerOut[i].write(writer); 204 | } 205 | } 206 | } 207 | 208 | /** 209 | * Writes the SOAP body stored in the object variable bodyIn, Overwrite this 210 | * method for customized writing of the soap message body. 211 | */ 212 | public void writeBody(XmlSerializer writer) throws IOException { 213 | if (encodingStyle != null) 214 | writer.attribute(env, "encodingStyle", encodingStyle); 215 | ((Node) bodyOut).write(writer); 216 | } 217 | 218 | /** 219 | * Assigns the object to the envelope as the outbound message for the soap call. 220 | * @param soapObject the object to send in the soap call. 221 | */ 222 | public void setOutputSoapObject(Object soapObject) { 223 | bodyOut = soapObject; 224 | } 225 | 226 | } 227 | -------------------------------------------------------------------------------- /ksoap2-servlet/src/main/java/org/ksoap2/servlet/SoapServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. */ 20 | 21 | package org.ksoap2.servlet; 22 | 23 | import java.io.ByteArrayInputStream; 24 | import java.io.IOException; 25 | import java.io.StringWriter; 26 | import java.io.Writer; 27 | import java.lang.reflect.InvocationTargetException; 28 | import java.lang.reflect.Method; 29 | import java.lang.reflect.Modifier; 30 | import java.util.Hashtable; 31 | 32 | import javax.servlet.ServletException; 33 | import javax.servlet.http.HttpServlet; 34 | import javax.servlet.http.HttpServletRequest; 35 | import javax.servlet.http.HttpServletResponse; 36 | 37 | import org.ksoap2.SoapFault; 38 | import org.ksoap2.serialization.PropertyInfo; 39 | import org.ksoap2.serialization.SoapObject; 40 | import org.ksoap2.serialization.SoapSerializationEnvelope; 41 | import org.kxml2.io.KXmlParser; 42 | import org.kxml2.io.KXmlSerializer; 43 | import org.xmlpull.v1.XmlPullParser; 44 | import org.xmlpull.v1.XmlSerializer; 45 | 46 | /** 47 | * copy-paste seans interop server orb here as needed.... 48 | * 49 | * some design issues: - path and soapaction are not considered. soapaction is 50 | * deprecated; for multiple paths, please use multiple servlets. 51 | */ 52 | 53 | public class SoapServlet extends HttpServlet { 54 | 55 | SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER12); 56 | /** static mapping paths -> objects */ 57 | Hashtable instanceMap = new Hashtable(); 58 | 59 | /** 60 | * the default operation is to map request.getPathInfo to an instance using 61 | * the information given by buildInstance. The returned instance is used as 62 | * target object for the method invocation. Please overwrite this method in 63 | * order to define your own (generic) mapping. If no mapping is found, the 64 | * servlet itself is returned. 65 | */ 66 | protected Object getInstance(HttpServletRequest request) { 67 | if (request.getPathInfo() == null) 68 | return this; 69 | Object result = instanceMap.get(request.getPathInfo()); 70 | return (result != null) ? result : this; 71 | } 72 | 73 | /** Publish all public methods of the given class */ 74 | public void publishClass(Class service, String namespace) { 75 | Method[] methods = service.getMethods(); 76 | for (int i = 0; i < methods.length; i++) { 77 | if (Modifier.isPublic(methods[i].getModifiers())) { 78 | Class[] types = methods[i].getParameterTypes(); 79 | PropertyInfo[] info = new PropertyInfo[types.length]; 80 | for (int j = 0; j < types.length; j++) { 81 | info[j] = new PropertyInfo(); 82 | info[j].type = types[j]; 83 | } 84 | publishMethod(service, namespace, methods[i].getName(), info); 85 | } 86 | } 87 | } 88 | 89 | /** 90 | * publish an instance by associating the instance with the given local 91 | * path. Please note that (currently) also the methods need to be published 92 | * separateley. Alternatively to this call, it is also possible to overwrite 93 | * the getObject (HttpRequest request) method 94 | */ 95 | public void publishInstance(String path, Object instance) { 96 | instanceMap.put(path, instance); 97 | } 98 | 99 | /** 100 | * publish a method. Please note that also a corresponding instance needs to 101 | * be published, either calling publishInstance or by overwriting 102 | * getInstance (), except when the method is a method of the servlet itself. 103 | */ 104 | 105 | public void publishMethod(Class service, String namespace, String name, PropertyInfo[] parameters) { 106 | SoapObject template = new SoapObject(namespace, name); 107 | for (int i = 0; i < parameters.length; i++) 108 | template.addProperty(parameters[i], null); 109 | envelope.addTemplate(template); 110 | } 111 | 112 | /** 113 | * convenience method; use this method if the paremeter types can be 114 | * obtained via reflection 115 | */ 116 | public void publishMethod(Class service, String namespace, String name, String[] parameterNames) { 117 | // find a fitting method 118 | Method[] methods = service.getMethods(); 119 | for (int i = 0; i < methods.length; i++) { 120 | if (methods[i].getName().equals(name) && methods[i].getParameterTypes().length == parameterNames.length) { 121 | Class[] types = methods[i].getParameterTypes(); 122 | PropertyInfo[] info = new PropertyInfo[types.length]; 123 | for (int j = 0; j < types.length; j++) { 124 | info[j] = new PropertyInfo(); 125 | info[j].name = parameterNames[j]; 126 | info[j].type = types[j]; 127 | } 128 | publishMethod(service, namespace, name, info); 129 | return; 130 | } 131 | } 132 | throw new RuntimeException("Method not found!"); 133 | } 134 | 135 | public SoapSerializationEnvelope getEnvelope() { 136 | return envelope; 137 | } 138 | 139 | /** 140 | * Please note: The classMap should not be set after publishing methods, 141 | * because parameter type information may get lost! 142 | */ 143 | public void setEnvelope(SoapSerializationEnvelope envelope) { 144 | this.envelope = envelope; 145 | } 146 | 147 | /** 148 | * In order to filter requests, please overwrite doPost and call super for 149 | * soap requests only 150 | */ 151 | public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 152 | try { 153 | Object service = getInstance(req); 154 | XmlPullParser parser = new KXmlParser(); 155 | if ( false ) { 156 | //parser.setInput(req.getInputStream(), req.getCharacterEncoding()); 157 | } 158 | else { 159 | byte[] inputRequest = new byte[req.getInputStream().available()]; 160 | req.getInputStream().read(inputRequest); 161 | System.out.println ("Request: " + new String(inputRequest)); 162 | ByteArrayInputStream bas = new ByteArrayInputStream(inputRequest); 163 | parser.setInput(bas, null); 164 | } 165 | parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); 166 | envelope.parse(parser); 167 | SoapObject soapReq = (SoapObject) envelope.bodyIn; 168 | SoapObject result = invoke(service, soapReq); 169 | System.out.println("result: " + result); 170 | envelope.bodyOut = result; 171 | } catch (SoapFault f) { 172 | f.printStackTrace(); 173 | envelope.bodyOut = f; 174 | res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 175 | } catch (Throwable t) { 176 | t.printStackTrace(); 177 | SoapFault fault = new SoapFault(); 178 | fault.faultcode = "Server"; 179 | fault.faultstring = t.getMessage(); 180 | envelope.bodyOut = fault; 181 | res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 182 | } finally { 183 | res.setContentType("text/xml; charset=utf-8"); 184 | res.setHeader("Connection", "close"); 185 | StringWriter sw = new StringWriter(); 186 | XmlSerializer writer = new KXmlSerializer(); 187 | writer.setOutput(sw); 188 | try { 189 | envelope.write(writer); 190 | } catch (Exception e) { 191 | e.printStackTrace(); 192 | } 193 | writer.flush(); 194 | System.out.println("result xml: " + sw); 195 | Writer w = res.getWriter(); 196 | w.write(sw.toString()); 197 | w.close(); 198 | } 199 | res.flushBuffer(); 200 | } 201 | 202 | protected SoapObject invoke(Object service, SoapObject soapReq) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { 203 | String name = soapReq.getName(); 204 | Class types[] = new Class[soapReq.getPropertyCount()]; 205 | Object[] args = new Object[soapReq.getPropertyCount()]; 206 | PropertyInfo arg = new PropertyInfo(); 207 | Hashtable properties = new Hashtable(); 208 | for (int i = 0; i < types.length; i++) { 209 | soapReq.getPropertyInfo(i, properties, arg); 210 | types[i] = (Class) arg.type; 211 | args[i] = soapReq.getProperty(i); 212 | } 213 | // expensive invocation here.. optimize with method cache, 214 | // want to support method overloading so need to figure in 215 | // the arg types.. 216 | Method method = service.getClass().getMethod(name, types); 217 | Object result = method.invoke(service, args); 218 | System.out.println("result:" + result); 219 | SoapObject response = new SoapObject(soapReq.getNamespace(), name + "Response"); 220 | if (result != null) 221 | response.addProperty("return", result); 222 | return response; 223 | } 224 | 225 | } 226 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.google.code.ksoap2-android 5 | ksoap2-parent 6 | 2.5-SNAPSHOT 7 | pom 8 | 9 | ksoap2-parent 10 | 13 | 14 | 15 | http://code.google.com/p/ksoap2-android/ 16 | 2002 17 | 18 | 19 | scm:git:git://github.com/karlmdavis/ksoap2-android.git 20 | 21 | scm:git:git@github.com:karlmdavis/ksoap2-android.git 22 | 23 | http://github.com/karlmdavis/ksoap2-android/tree/master 24 | 25 | 26 | 27 | Google Code 28 | http://code.google.com/p/ksoap2-android/issues/list 29 | 30 | 31 | 32 | ksoap2-base 33 | ksoap2-android 34 | ksoap2-android-assembly 35 | ksoap2-extras 36 | ksoap2-j2se 37 | ksoap2-midp 38 | ksoap2-samples 39 | ksoap2-samples-axis 40 | ksoap2-servlet 41 | 42 | 43 | 44 | 45 | false 46 | googlecode 47 | svn:https://ksoap2-android.googlecode.com/svn/m2-repo 48 | 49 | 50 | 51 | 52 | googlecode-ksoap2-android 53 | googlecode-ksoap2-android 54 | http://ksoap2-android.googlecode.com/svn/m2-repo 55 | 56 | 57 | 58 | 59 | googlecode-ksoap2-android 60 | googlecode-ksoap2-android 61 | http://ksoap2-android.googlecode.com/svn/m2-repo 62 | 63 | 64 | 65 | 66 | 67 | 71 | release 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-source-plugin 77 | 78 | 79 | attach-sources 80 | 81 | jar 82 | test-jar 83 | 84 | 85 | 86 | 87 | 88 | org.apache.maven.plugins 89 | maven-javadoc-plugin 90 | 91 | 92 | attach-javadocs 93 | 94 | jar 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | com.google.code.ksoap2-android 108 | ksoap2-base 109 | ${project.version} 110 | jar 111 | compile 112 | 113 | 114 | com.google.code.ksoap2-android 115 | ksoap2-base 116 | ${project.version} 117 | test-jar 118 | test 119 | 120 | 121 | 122 | com.google.code.ksoap2-android 123 | ksoap2-android 124 | ${project.version} 125 | jar 126 | compile 127 | 128 | 129 | com.google.code.ksoap2-android 130 | ksoap2-android 131 | ${project.version} 132 | test-jar 133 | test 134 | 135 | 136 | 137 | com.google.code.ksoap2-android 138 | ksoap2-extras 139 | ${project.version} 140 | jar 141 | compile 142 | 143 | 144 | com.google.code.ksoap2-android 145 | ksoap2-extras 146 | ${project.version} 147 | test-jar 148 | test 149 | 150 | 151 | 152 | com.google.code.ksoap2-android 153 | ksoap2-j2se 154 | ${project.version} 155 | jar 156 | compile 157 | 158 | 159 | com.google.code.ksoap2-android 160 | ksoap2-j2se 161 | ${project.version} 162 | test-jar 163 | test 164 | 165 | 166 | 167 | com.google.code.ksoap2-android 168 | ksoap2-midp 169 | ${project.version} 170 | jar 171 | compile 172 | 173 | 174 | com.google.code.ksoap2-android 175 | ksoap2-midp 176 | ${project.version} 177 | test-jar 178 | test 179 | 180 | 181 | 182 | com.google.code.ksoap2-android 183 | ksoap2-samples 184 | ${project.version} 185 | jar 186 | compile 187 | 188 | 189 | com.google.code.ksoap2-android 190 | ksoap2-samples 191 | ${project.version} 192 | test-jar 193 | test 194 | 195 | 196 | 197 | 198 | com.google.code.ksoap2-android 199 | ksoap2-samples-axis 200 | ${project.version} 201 | jar 202 | compile 203 | 204 | 205 | com.google.code.ksoap2-android 206 | ksoap2-samples-axis 207 | ${project.version} 208 | test-jar 209 | test 210 | 211 | 212 | 213 | 214 | com.google.code.ksoap2-android 215 | ksoap2-servlet 216 | ${project.version} 217 | jar 218 | compile 219 | 220 | 221 | com.google.code.ksoap2-android 222 | ksoap2-servlet 223 | ${project.version} 224 | test-jar 225 | test 226 | 227 | 228 | 229 | net.sourceforge.kxml 230 | kxml 231 | 2.2.4 232 | jar 233 | compile 234 | 235 | 236 | 237 | net.sourceforge.kobjects 238 | kobjects-j2me 239 | 0.0-SNAPSHOT-20040926-2 240 | jar 241 | compile 242 | 243 | 244 | 245 | net.sourceforge.me4se 246 | me4se 247 | 2.1.4-SNAPSHOT-20040926 248 | jar 249 | compile 250 | 251 | 252 | 253 | junit 254 | junit 255 | 3.8.1 256 | jar 257 | test 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | src/main/java 266 | src/test/java 267 | 268 | 269 | false 270 | src/main/java 271 | 272 | 276 | ** 277 | 278 | 279 | **/*.java 280 | 281 | 282 | 283 | src/main/resources 284 | 285 | 286 | 287 | 288 | src/test/resources 289 | 290 | 291 | 292 | 293 | org.jvnet.wagon-svn 294 | wagon-svn 295 | 1.9 296 | 297 | 298 | 299 | 300 | 301 | org.apache.maven.plugins 302 | maven-compiler-plugin 303 | 304 | 1.6 305 | 1.6 306 | 307 | 308 | 309 | org.apache.maven.plugins 310 | maven-release-plugin 311 | 2.0 312 | 313 | 314 | org.apache.maven.scm 315 | maven-scm-provider-gitexe 316 | 1.2 317 | 318 | 319 | 320 | true 321 | 326 | clean install 327 | false 328 | -Prelease 329 | 330 | 331 | 332 | org.apache.maven.plugins 333 | maven-scm-plugin 334 | 335 | 336 | org.apache.maven.scm 337 | maven-scm-provider-gitexe 338 | 1.2 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | -------------------------------------------------------------------------------- /ksoap2-base/src/main/java/org/ksoap2/serialization/SoapObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | * associated documentation files (the "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 8 | * following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all copies or substantial 11 | * portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 14 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 15 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 16 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 17 | * USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | * 19 | * Contributor(s): John D. Beatty, Dave Dash, Andre Gerard, F. Hunter, Renaud Tognelli 20 | */ 21 | 22 | package org.ksoap2.serialization; 23 | 24 | import java.util.*; 25 | 26 | /** 27 | * A simple dynamic object that can be used to build soap calls without implementing KvmSerializable 28 | * 29 | * Essentially, this is what goes inside the body of a soap envelope - it is the direct subelement of the body 30 | * and all further subelements 31 | * 32 | * Instead of this this class, custom classes can be used if they implement the KvmSerializable interface. 33 | */ 34 | 35 | public class SoapObject implements KvmSerializable 36 | { 37 | /** The namespace of this soap object. */ 38 | protected String namespace; 39 | /** The name of this soap object. */ 40 | protected String name; 41 | /** The Vector of properties. */ 42 | protected Vector properties = new Vector(); 43 | /** The Vector of attributes. */ 44 | protected Vector attributes = new Vector(); 45 | 46 | /** 47 | * Creates a new SoapObject instance. 48 | * 49 | * @param namespace 50 | * the namespace for the soap object 51 | * @param name 52 | * the name of the soap object 53 | */ 54 | 55 | public SoapObject(String namespace, String name) 56 | { 57 | this.namespace = namespace; 58 | this.name = name; 59 | } 60 | 61 | public boolean equals(Object obj) 62 | { 63 | if (!(obj instanceof SoapObject)) 64 | return false; 65 | 66 | SoapObject otherSoapObject = (SoapObject) obj; 67 | 68 | int numProperties = properties.size(); 69 | if (numProperties != otherSoapObject.properties.size()) 70 | return false; 71 | int numAttributes = attributes.size(); 72 | if (numAttributes != otherSoapObject.attributes.size()) 73 | return false; 74 | 75 | try 76 | { 77 | for (int propIndex = 0; propIndex < numProperties; propIndex++) 78 | { 79 | PropertyInfo thisProp = (PropertyInfo) this.properties.elementAt(propIndex); 80 | Object thisPropValue = thisProp.getValue(); 81 | Object otherPropValue = otherSoapObject.getProperty(thisProp.getName()); 82 | if (!thisPropValue.equals(otherPropValue)) 83 | { 84 | return false; 85 | } 86 | } 87 | for (int attribIndex = 0; attribIndex < numAttributes; attribIndex++) 88 | { 89 | AttributeInfo thisAttrib = (AttributeInfo) this.properties.elementAt(attribIndex); 90 | Object thisAttribValue = thisAttrib.getValue(); 91 | Object otherAttribValue = otherSoapObject.getProperty(thisAttrib.getName()); 92 | if (!thisAttribValue.equals(otherAttribValue)) 93 | { 94 | return false; 95 | } 96 | } 97 | } 98 | catch (Exception e) 99 | { 100 | return false; 101 | } 102 | return true; 103 | } 104 | 105 | public String getName() 106 | { 107 | return name; 108 | } 109 | 110 | public String getNamespace() 111 | { 112 | return namespace; 113 | } 114 | 115 | /** 116 | * Returns a specific property at a certain index. 117 | * 118 | * @param index 119 | * the index of the desired property 120 | * @return the desired property 121 | */ 122 | public Object getProperty(int index) 123 | { 124 | return ((PropertyInfo) properties.elementAt(index)).getValue(); 125 | } 126 | 127 | public Object getProperty(String name) 128 | { 129 | for (int i = 0; i < properties.size(); i++) 130 | { 131 | if (name.equals(((PropertyInfo) properties.elementAt(i)).getName())) 132 | return getProperty(i); 133 | } 134 | throw new RuntimeException("illegal property: " + name); 135 | } 136 | 137 | /** 138 | * Returns the number of properties 139 | * 140 | * @return the number of properties 141 | */ 142 | public int getPropertyCount() 143 | { 144 | return properties.size(); 145 | } 146 | 147 | /** 148 | * Places AttributeInfo of desired attribute into a designated AttributeInfo object 149 | * 150 | * @param index 151 | * index of desired attribute 152 | * @param propertyInfo 153 | * designated retainer of desired attribute 154 | */ 155 | public void getAttributeInfo(int index, AttributeInfo attributeInfo) 156 | { 157 | AttributeInfo p = (AttributeInfo) attributes.elementAt(index); 158 | attributeInfo.name = p.name; 159 | attributeInfo.namespace = p.namespace; 160 | attributeInfo.flags = p.flags; 161 | attributeInfo.type = p.type; 162 | attributeInfo.elementType = p.elementType; 163 | attributeInfo.value = p.getValue(); 164 | } 165 | 166 | /** 167 | * Returns a specific attribute at a certain index. 168 | * 169 | * @param index 170 | * the index of the desired attribute 171 | * @return the value of the desired attribute 172 | * 173 | */ 174 | public Object getAttribute(int index) 175 | { 176 | return ((AttributeInfo) attributes.elementAt(index)).getValue(); 177 | } 178 | 179 | /** Returns a property with the given name. */ 180 | public Object getAttribute(String name) 181 | { 182 | for (int i = 0; i < attributes.size(); i++) 183 | { 184 | if (name.equals(((AttributeInfo) attributes.elementAt(i)).getName())) 185 | return getAttribute(i); 186 | } 187 | throw new RuntimeException("illegal property: " + name); 188 | } 189 | 190 | /** 191 | * Returns the number of attributes 192 | * 193 | * @return the number of attributes 194 | */ 195 | public int getAttributeCount() 196 | { 197 | return attributes.size(); 198 | } 199 | 200 | /** 201 | * Places PropertyInfo of desired property into a designated PropertyInfo object 202 | * 203 | * @param index 204 | * index of desired property 205 | * @param propertyInfo 206 | * designated retainer of desired property 207 | * @deprecated 208 | */ 209 | public void getPropertyInfo(int index, Hashtable properties, PropertyInfo propertyInfo) 210 | { 211 | getPropertyInfo(index, propertyInfo); 212 | } 213 | 214 | /** 215 | * Places PropertyInfo of desired property into a designated PropertyInfo object 216 | * 217 | * @param index 218 | * index of desired property 219 | * @param propertyInfo 220 | * designated retainer of desired property 221 | */ 222 | public void getPropertyInfo(int index, PropertyInfo propertyInfo) 223 | { 224 | PropertyInfo p = (PropertyInfo) properties.elementAt(index); 225 | propertyInfo.name = p.name; 226 | propertyInfo.namespace = p.namespace; 227 | propertyInfo.flags = p.flags; 228 | propertyInfo.type = p.type; 229 | propertyInfo.elementType = p.elementType; 230 | } 231 | 232 | /** 233 | * Creates a new SoapObject based on this, allows usage of SoapObjects as templates. One application is to 234 | * set the expected return type of a soap call if the server does not send explicit type information. 235 | * 236 | * @return a copy of this. 237 | */ 238 | public SoapObject newInstance() 239 | { 240 | SoapObject o = new SoapObject(namespace, name); 241 | for (int propIndex = 0; propIndex < properties.size(); propIndex++) 242 | { 243 | PropertyInfo propertyInfo = (PropertyInfo) properties.elementAt(propIndex); 244 | o.addProperty(propertyInfo); 245 | } 246 | for (int attribIndex = 0; attribIndex < attributes.size(); attribIndex++) 247 | { 248 | AttributeInfo attributeInfo = (AttributeInfo) attributes.elementAt(attribIndex); 249 | o.addAttribute(attributeInfo); 250 | } 251 | return o; 252 | } 253 | 254 | /** 255 | * Sets a specified property to a certain value. 256 | * 257 | * @param index 258 | * the index of the specified property 259 | * @param value 260 | * the new value of the property 261 | */ 262 | public void setProperty(int index, Object value) 263 | { 264 | ((PropertyInfo) properties.elementAt(index)).setValue(value); 265 | } 266 | 267 | /** 268 | * Adds a property (parameter) to the object. This is essentially a sub element. 269 | * 270 | * @param name 271 | * The name of the property 272 | * @param value 273 | * the value of the property 274 | */ 275 | public SoapObject addProperty(String name, Object value) 276 | { 277 | PropertyInfo propertyInfo = new PropertyInfo(); 278 | propertyInfo.name = name; 279 | propertyInfo.type = value == null ? PropertyInfo.OBJECT_CLASS : value.getClass(); 280 | propertyInfo.value = value; 281 | return addProperty(propertyInfo); 282 | } 283 | 284 | /** 285 | * Adds a property (parameter) to the object. This is essentially a sub element. 286 | * 287 | * @param propertyInfo 288 | * designated retainer of desired property 289 | * @param value 290 | * the value of the property 291 | * @deprecated property info now contains the value 292 | */ 293 | public SoapObject addProperty(PropertyInfo propertyInfo, Object value) 294 | { 295 | propertyInfo.setValue(value); 296 | addProperty(propertyInfo); 297 | return this; 298 | } 299 | 300 | /** 301 | * Adds a property (parameter) to the object. This is essentially a sub element. 302 | * 303 | * @param propertyInfo 304 | * designated retainer of desired property 305 | */ 306 | public SoapObject addProperty(PropertyInfo propertyInfo) 307 | { 308 | properties.addElement(propertyInfo); 309 | return this; 310 | } 311 | 312 | /** 313 | * Adds a attribute (parameter) to the object. This is essentially a sub element. 314 | * 315 | * @param name 316 | * The name of the attribute 317 | * @param value 318 | * the value of the attribute 319 | */ 320 | public SoapObject addAttribute(String name, Object value) 321 | { 322 | AttributeInfo attributeInfo = new AttributeInfo(); 323 | attributeInfo.name = name; 324 | attributeInfo.type = value == null ? PropertyInfo.OBJECT_CLASS : value.getClass(); 325 | attributeInfo.value = value; 326 | return addAttribute(attributeInfo); 327 | } 328 | 329 | /** 330 | * Adds a attribute (parameter) to the object. This is essentially a sub element. 331 | * 332 | * @param propertyInfo 333 | * designated retainer of desired attribute 334 | */ 335 | public SoapObject addAttribute(AttributeInfo attributeInfo) 336 | { 337 | attributes.addElement(attributeInfo); 338 | return this; 339 | } 340 | 341 | public String toString() 342 | { 343 | StringBuffer buf = new StringBuffer("" + name + "{"); 344 | for (int i = 0; i < getPropertyCount(); i++) 345 | { 346 | buf.append("" + ((PropertyInfo) properties.elementAt(i)).getName() + "=" + getProperty(i) + "; "); 347 | } 348 | buf.append("}"); 349 | return buf.toString(); 350 | } 351 | 352 | } 353 | --------------------------------------------------------------------------------