UsernameToken userToken = new UsernameToken(WSSConfig.getDefaultWSConfig(),doc);
userToken.setName("bob");
userToken.setPassword("bobspass");
RequestSecurityTokenResponse tokenResponse = new RequestSecurityTokenResponse(doc, new SecurityTokenOrReference(userToken));
tokenResponse.setContext(new URI("http://context.context"));
tokenResponse.setTokenType(TokenTypes.USERNAME);
/*
Data data = new Data();
Data data2 = new Data();
data.stringMember = "String member";
data.floatMember = new Float("1.23");
data.dataMember = data2;
data2.stringMember = "another str member";
data2.floatMember = new Float("4.56");
data2.dataMember = null; // "data;" for loop-test of multi-refs
*/
RPCParam arg2 = new RPCParam("", "struct", tokenResponse);
RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{arg1, arg2});
msg.addBodyElement(body);
try {
Reader reader = null;
if (args.length == 0) {
Writer stringWriter = new StringWriter();
SerializationContext context = new SerializationContext(stringWriter, msgContext);
TypeMappingRegistry reg = context.getTypeMappingRegistry();
TypeMapping tm = (TypeMapping) reg.getTypeMapping(Constants.URI_SOAP11_ENC);
if (tm == null) {
tm = (TypeMapping) reg.createTypeMapping();
reg.register(Constants.URI_DEFAULT_SOAP_ENC, tm);
}
tm.register(RequestSecurityTokenResponse.class, TrustConstants.RESPONSE_NAME, new RSTResponseSerializerFactory(), new RSTResponseDeserializerFactory());
msg.output(context);
String msgString = stringWriter.toString();
System.out.println("Serialized msg:");
System.out.println(msgString);
System.out.println("-------");
System.out.println("Testing deserialization...");
reader = new StringReader(msgString);
} else {
reader = new FileReader(args[0]);
}
DeserializationContext dser = new DeserializationContext(new InputSource(reader), msgContext, org.apache.axis.Message.REQUEST);
dser.parse();
SOAPEnvelope env = dser.getEnvelope();
//System.out.println("********\n" + DOM2Writer.nodeToString(env, true) + "\n********");
RPCElement rpcElem = (RPCElement) env.getFirstBody();
RPCParam struct = rpcElem.getParam("struct");
if (struct == null)
throw new Exception("No <struct> param");
if (!(struct.getObjectValue() instanceof RequestSecurityTokenResponse)) {
System.out.println("Not a RST object! ");
System.out.println(struct.getValue());
System.exit(1);
}
RequestSecurityTokenResponse val = (RequestSecurityTokenResponse) struct.getObjectValue();
if (val == null)
throw new Exception("No value for struct param");
System.out.println(val.toString());
} catch (Exception e) {
e.printStackTrace();
}
}