1 16 17 package test.wsdd; 18 19 import java.util.Map ; 20 21 import javax.xml.namespace.QName ; 22 import javax.xml.rpc.handler.Handler ; 23 import javax.xml.rpc.handler.HandlerInfo ; 24 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 25 import javax.xml.rpc.holders.StringHolder ; 26 27 import junit.framework.TestCase; 28 29 import org.apache.axis.MessageContext; 30 import org.apache.axis.client.Call; 31 import org.apache.axis.client.Service; 32 import org.apache.axis.configuration.XMLStringProvider; 33 import org.apache.axis.deployment.wsdd.WSDDConstants; 34 import org.apache.axis.message.SOAPHeaderElement; 35 import org.apache.axis.server.AxisServer; 36 import org.apache.axis.transport.local.LocalTransport; 37 import org.w3c.dom.NodeList ; 38 39 48 public class TestJAXRPCHandlerInfoChain extends TestCase implements Handler { 49 50 static final String SERVICE_NAME = "JAXRPCHandlerService"; 51 static final String tns = "http://axis.apache.org/test"; 52 static final String ROLE_ONE = "http://test.role.one"; 53 static final String ROLE_TWO = "http://test.role.two"; 54 55 AxisServer server; 56 LocalTransport transport; 57 58 static boolean roleOneFound = false; 59 static boolean roleTwoFound = false; 60 static boolean initCalled = false; 61 static boolean handleRequestCalled = false; 62 static boolean handleResponseCalled = false; 63 static boolean methodCalled = false; 64 65 static final String wsdd = 66 "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " 67 + "xmlns:java=\"" 68 + WSDDConstants.URI_WSDD_JAVA 69 + "\">\n" 70 + " <service name=\"" 71 + SERVICE_NAME 72 + "\" " 73 + "provider=\"java:RPC\">\n" 74 + " <parameter name=\"className\" value=\"test.wsdd.TestJAXRPCHandlerInfoChain\"/>" 75 + " <handlerInfoChain>" 76 + " <handlerInfo classname=\"test.wsdd.TestJAXRPCHandlerInfoChain\">" 77 + " <parameter name=\"param1\" value=\"hossa\"/>" 78 + " </handlerInfo>" 79 + " <role soapActorName=\"" + ROLE_ONE + "\"/>" 80 + " <role soapActorName=\"" + ROLE_TWO + "\"/>" 81 + " </handlerInfoChain>" 82 + " </service>\n" 83 + "</deployment>"; 84 85 public TestJAXRPCHandlerInfoChain() { 86 super("test"); 87 } 88 89 public TestJAXRPCHandlerInfoChain(String s) { 90 super(s); 91 } 92 93 protected void setUp() throws Exception { 94 transport = new LocalTransport(new AxisServer(new XMLStringProvider(wsdd))); 95 transport.setRemoteService(SERVICE_NAME); 96 } 97 98 public void init(HandlerInfo handlerInfo) { 99 assertEquals("hossa", (String ) handlerInfo.getHandlerConfig().get("param1")); 100 initCalled = true; 101 } 102 103 public void destroy() { 104 } 105 106 public boolean handleRequest(javax.xml.rpc.handler.MessageContext mc) { 107 108 String [] roles = ((SOAPMessageContext ) mc).getRoles(); 109 for (int i = 0; i < roles.length; i++) { 110 if (ROLE_ONE.equals(roles[i])) 111 roleOneFound = true; 112 if (ROLE_TWO.equals(roles[i])) 113 roleTwoFound = true; 114 } 115 116 handleRequestCalled = true; 117 return true; 118 } 119 120 public QName [] getHeaders() { 121 return null; 122 } 123 124 public boolean handleResponse(javax.xml.rpc.handler.MessageContext mc) { 125 handleResponseCalled = true; 126 return true; 127 } 128 129 public boolean handleFault(javax.xml.rpc.handler.MessageContext mc) { 130 return true; 131 } 132 133 public void doSomething() { 134 methodCalled = true; 135 } 136 137 public void testJAXRPCHandlerRoles() throws Exception { 138 139 Call call = new Call(new Service()); 140 call.setTransport(transport); 141 142 call.invoke("doSomething", null); 143 144 assertTrue( roleOneFound); 145 assertTrue( roleTwoFound); 146 assertTrue( initCalled); 147 assertTrue( handleRequestCalled); 148 assertTrue( handleResponseCalled); 149 assertTrue( methodCalled); 150 } 151 152 } 153 | Popular Tags |