| 1 |
package samples.encoding; |
| 2 |
|
| 3 |
import org.apache.axis.client.Call; |
| 4 |
import org.apache.axis.client.Service; |
| 5 |
import org.apache.axis.utils.Options; |
| 6 |
import org.apache.axis.utils.XMLUtils; |
| 7 |
import org.w3c.dom.Element; |
| 8 |
|
| 9 |
import javax.xml.namespace.QName; |
| 10 |
import java.io.ByteArrayInputStream; |
| 11 |
import java.net.URL; |
| 12 |
|
| 13 |
public class TestElem { |
| 14 |
static String xml = "<x:hello xmlns:x=\"urn:foo\">a string</x:hello>" ; |
| 15 |
|
| 16 |
public static String doit(String[] args,String xml) throws Exception { |
| 17 |
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); |
| 18 |
|
| 19 |
String sURL = "http://" + args[0] + ":" + args[1] + "/axis/services/ElementService" ; |
| 20 |
QName sqn = new QName(sURL, "ElementService" ); |
| 21 |
QName pqn = new QName(sURL, "ElementService" ); |
| 22 |
|
| 23 |
//Service service=new Service(new URL("file:ElementService.wsdl"),sqn); |
| 24 |
Service service = new Service(new URL(sURL+"?wsdl"),sqn); |
| 25 |
Call call = (Call) service.createCall( pqn, "echoElement" ); |
| 26 |
|
| 27 |
Options opts = new Options(args); |
| 28 |
opts.setDefaultURL( call.getTargetEndpointAddress() ); |
| 29 |
call.setTargetEndpointAddress( new URL(opts.getURL()) ); |
| 30 |
|
| 31 |
Element elem = XMLUtils.newDocument(bais).getDocumentElement(); |
| 32 |
|
| 33 |
elem = (Element) call.invoke( new Object[] { "a string", elem } ); |
| 34 |
return( XMLUtils.ElementToString( elem ) ); |
| 35 |
} |
| 36 |
|
| 37 |
public static void main(String[] args) throws Exception { |
| 38 |
System.out.println("Sent: " + xml ); |
| 39 |
String res = doit(args, xml); |
| 40 |
System.out.println("Returned: " + res ); |
| 41 |
} |
| 42 |
} |