|
Axis 2 example source code file (MultirefTest.java)
The Axis 2 MultirefTest.java source code/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.axis2.rpc; import java.io.ByteArrayInputStream; import java.util.ArrayList; import javax.xml.namespace.QName; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; import org.apache.axiom.om.impl.builder.StAXOMBuilder; import org.apache.axiom.om.util.StAXUtils; import org.apache.axiom.soap.SOAPEnvelope; import org.apache.axiom.soap.SOAPFactory; import org.apache.axis2.AxisFault; import org.apache.axis2.Constants; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.OperationClient; import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.axis2.context.MessageContext; import org.apache.axis2.context.ServiceContext; import org.apache.axis2.databinding.utils.BeanUtil; import org.apache.axis2.description.AxisService; import org.apache.axis2.engine.AxisConfiguration; import org.apache.axis2.engine.DefaultObjectSupplier; import org.apache.axis2.integration.RPCLocalTestCase; import org.apache.axis2.integration.UtilServer; import org.apache.axis2.rpc.client.RPCServiceClient; import org.apache.axis2.wsdl.WSDLConstants; public class MultirefTest extends RPCLocalTestCase { protected boolean finish = false; public static final String NAMESPACE = "http://rpc.axis2.apache.org"; protected void setUp() throws Exception { super.setUp(); deployClassAsService("EchoXMLService", RPCServiceClass.class); } public void testMulitref1() throws AxisFault { RPCServiceClient sender = getRPCClient("EchoXMLService", "echoString"); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace(NAMESPACE, "my"); OMElement method = fac.createOMElement("echoString", omNs); OMElement value = fac.createOMElement("arg0", null); value.addAttribute(fac.createOMAttribute("href", null, "#1")); method.addChild(value); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = factory.getDefaultEnvelope(); envelope.getBody().addChild(method); OMElement ref = fac.createOMElement("reference", null); ref.addAttribute(fac.createOMAttribute("id", null, "1")); ref.setText("hello Axis2"); envelope.getBody().addChild(ref); MessageContext reqMessageContext = new MessageContext(); OperationClient opClinet = sender.createClient(ServiceClient.ANON_OUT_IN_OP); reqMessageContext.setEnvelope(envelope); opClinet.addMessageContext(reqMessageContext); opClinet.execute(true); MessageContext responseMessageContx = opClinet.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); SOAPEnvelope env = responseMessageContx.getEnvelope(); assertEquals(env.getBody().getFirstElement().getFirstElement().getText(), "hello Axis2"); } public void testadd() throws AxisFault { RPCServiceClient sender = getRPCClient("EchoXMLService", "add"); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace(NAMESPACE, "my"); OMElement method = fac.createOMElement("add", omNs); OMElement value = fac.createOMElement("arg0", null); value.addAttribute(fac.createOMAttribute("href", null, "#1")); method.addChild(value); OMElement value2 = fac.createOMElement("arg1", null); value2.addAttribute(fac.createOMAttribute("href", null, "#2")); method.addChild(value2); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = factory.getDefaultEnvelope(); envelope.getBody().addChild(method); OMElement ref = fac.createOMElement("reference", null); ref.addAttribute(fac.createOMAttribute("id", null, "1")); ref.setText("10"); envelope.getBody().addChild(ref); OMElement ref2 = fac.createOMElement("reference", null); ref2.addAttribute(fac.createOMAttribute("id", null, "2")); ref2.setText("10"); envelope.getBody().addChild(ref2); MessageContext reqMessageContext = new MessageContext(); OperationClient opClinet = sender.createClient(ServiceClient.ANON_OUT_IN_OP); reqMessageContext.setEnvelope(envelope); opClinet.addMessageContext(reqMessageContext); opClinet.execute(true); MessageContext responseMessageContx = opClinet.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); SOAPEnvelope env = responseMessageContx.getEnvelope(); assertEquals(env.getBody().getFirstElement().getFirstElement().getText(), "20"); } public void testaddSameRef() throws AxisFault { RPCServiceClient sender = getRPCClient("EchoXMLService", "add"); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace(NAMESPACE, "my"); OMElement method = fac.createOMElement("add", omNs); OMElement value = fac.createOMElement("arg0", null); value.addAttribute(fac.createOMAttribute("href", null, "#1")); method.addChild(value); OMElement value2 = fac.createOMElement("arg1", null); value2.addAttribute(fac.createOMAttribute("href", null, "#1")); method.addChild(value2); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = factory.getDefaultEnvelope(); envelope.getBody().addChild(method); OMElement ref = fac.createOMElement("reference", null); ref.addAttribute(fac.createOMAttribute("id", null, "1")); ref.setText("10"); envelope.getBody().addChild(ref); MessageContext reqMessageContext = new MessageContext(); OperationClient opClinet = sender.createClient(ServiceClient.ANON_OUT_IN_OP); reqMessageContext.setEnvelope(envelope); opClinet.addMessageContext(reqMessageContext); opClinet.execute(true); MessageContext responseMessageContx = opClinet.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); SOAPEnvelope env = responseMessageContx.getEnvelope(); assertEquals(env.getBody().getFirstElement().getFirstElement().getText(), "20"); } public void testaddError() { try { RPCServiceClient sender = getRPCClient("EchoXMLService", "add"); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace(NAMESPACE, "my"); OMElement method = fac.createOMElement("add", omNs); OMElement value = fac.createOMElement("arg0", null); value.addAttribute(fac.createOMAttribute("href", null, "#1")); method.addChild(value); OMElement value2 = fac.createOMElement("arg1", null); value2.addAttribute(fac.createOMAttribute("href", null, "#2")); method.addChild(value2); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = factory.getDefaultEnvelope(); envelope.getBody().addChild(method); OMElement ref = fac.createOMElement("reference", null); ref.addAttribute(fac.createOMAttribute("id", null, "1")); ref.setText("10"); envelope.getBody().addChild(ref); OMElement ref2 = fac.createOMElement("reference", null); ref2.addAttribute(fac.createOMAttribute("id", null, "3")); ref2.setText("10"); envelope.getBody().addChild(ref2); MessageContext reqMessageContext = new MessageContext();; OperationClient opClinet = sender.createClient(ServiceClient.ANON_OUT_IN_OP); reqMessageContext.setEnvelope(envelope); opClinet.addMessageContext(reqMessageContext); opClinet.execute(true); fail("This should fail with : " + "org.apache.axis2.AxisFault: Invalid reference :2"); } catch (AxisFault axisFault) { String val = axisFault.getFaultDetailElement().toString(); System.out.println("val = " + val); int index = val.indexOf("org.apache.axis2.AxisFault: Invalid reference :2"); if (index < 0) { fail("This should fail with : " + "org.apache.axis2.AxisFault: Invalid reference :2"); } } } public void testMulitrefBean() throws Exception { RPCServiceClient sender = getRPCClient("EchoXMLService", "editBean"); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace(NAMESPACE, "my"); OMElement method = fac.createOMElement("editBean", omNs); OMElement value = fac.createOMElement("arg0", null); value.addAttribute(fac.createOMAttribute("href", null, "#1")); method.addChild(value); OMElement value2 = fac.createOMElement("arg1", null); value2.setText("159"); method.addChild(value2); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = factory.getDefaultEnvelope(); envelope.getBody().addChild(method); String ref1 = "<reference id=\"1\"> Other Axis 2 examples (source code examples)Here is a short list of links related to this Axis 2 MultirefTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.