| 1 |
package test.wsdd; |
| 2 |
|
| 3 |
import junit.framework.Test; |
| 4 |
import junit.framework.TestCase; |
| 5 |
import junit.framework.TestSuite; |
| 6 |
import org.apache.axis.Handler; |
| 7 |
import org.apache.axis.client.AdminClient; |
| 8 |
import org.apache.axis.configuration.XMLStringProvider; |
| 9 |
import org.apache.axis.deployment.wsdd.WSDDConstants; |
| 10 |
import org.apache.axis.server.AxisServer; |
| 11 |
import org.apache.axis.transport.local.LocalTransport; |
| 12 |
|
| 13 |
import java.io.ByteArrayInputStream; |
| 14 |
|
| 15 |
/** |
| 16 |
* Try various bad deployments, and make sure that we get back reasonable |
| 17 |
* errors and don't screw up the engine's configuration. |
| 18 |
* |
| 19 |
* @author Glen Daniels ([email protected]) |
| 20 |
*/ |
| 21 |
public class TestBadWSDD extends TestCase |
| 22 |
{ |
| 23 |
static final String HANDLER_NAME = "logger"; |
| 24 |
static final String PARAM_NAME = "testParam"; |
| 25 |
static final String PARAM_VAL = "testValue"; |
| 26 |
|
| 27 |
static final String goodWSDD = |
| 28 |
"<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " + |
| 29 |
"xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n" + |
| 30 |
" <handler type=\"java:org.apache.axis.handlers.LogHandler\" " + |
| 31 |
"name=\"" + HANDLER_NAME + "\">\n" + |
| 32 |
" <parameter name=\"" + PARAM_NAME + |
| 33 |
"\" value=\"" + PARAM_VAL + "\"/>\n" + |
| 34 |
" </handler>\n" + |
| 35 |
" <handler type=\"logger\" name=\"other\"/>\n" + |
| 36 |
" <service name=\"AdminService\" provider=\"java:MSG\">\n" + |
| 37 |
" <parameter name=\"allowedMethods\" value=\"AdminService\"/>" + |
| 38 |
" <parameter name=\"enableRemoteAdmin\" value=\"false\"/>" + |
| 39 |
" <parameter name=\"className\"" + |
| 40 |
" value=\"org.apache.axis.utils.Admin\"/>" + |
| 41 |
" </service>" + |
| 42 |
"</deployment>"; |
| 43 |
|
| 44 |
static final String header = |
| 45 |
"<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " + |
| 46 |
"xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n"; |
| 47 |
static final String footer = |
| 48 |
"</deployment>"; |
| 49 |
|
| 50 |
static final String badHandler = |
| 51 |
" <handler name=\"nameButNoType\"/>\n"; |
| 52 |
|
| 53 |
public TestBadWSDD (String name) { |
| 54 |
super(name); |
| 55 |
} |
| 56 |
|
| 57 |
public static Test suite() { |
| 58 |
return new TestSuite(TestBadWSDD.class); |
| 59 |
} |
| 60 |
|
| 61 |
protected void setup() { |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Initialize an engine with a single handler with a parameter set, and |
| 66 |
* another reference to that same handler with a different name. |
| 67 |
* |
| 68 |
* Make sure the param is set for both the original and the reference |
| 69 |
* handler. |
| 70 |
* |
| 71 |
*/ |
| 72 |
public void testOptions() throws Exception |
| 73 |
{ |
| 74 |
XMLStringProvider provider = new XMLStringProvider(goodWSDD); |
| 75 |
AxisServer server = new AxisServer(provider); |
| 76 |
|
| 77 |
Handler h1 = server.getHandler(HANDLER_NAME); |
| 78 |
assertNotNull("Couldn't get logger handler from engine!", h1); |
| 79 |
|
| 80 |
AdminClient client = new AdminClient(true); |
| 81 |
String doc = header + badHandler + footer; |
| 82 |
ByteArrayInputStream stream = new ByteArrayInputStream(doc.getBytes()); |
| 83 |
|
| 84 |
LocalTransport transport = new LocalTransport(server); |
| 85 |
transport.setUrl("local:///AdminService"); |
| 86 |
client.getCall().setTransport(transport); |
| 87 |
try { |
| 88 |
client.process(stream); |
| 89 |
} catch (Exception e) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
fail("Successfully processed bad WSDD!"); |
| 94 |
} |
| 95 |
|
| 96 |
public static void main(String[] args) throws Exception { |
| 97 |
TestBadWSDD tester = new TestBadWSDD("foo"); |
| 98 |
tester.testOptions(); |
| 99 |
} |
| 100 |
} |