下面列出了怎么用javax.xml.rpc.handler.Handler的API类实例代码及写法,或者点击链接到github查看源代码。
private void initHandlerChain(QName portName, HandlerRegistry handlerRegistry,
HandlerInfo handlerInfo, List<String> soaprolesToAdd) {
HandlerChain handlerChain = (HandlerChain) handlerRegistry.getHandlerChain(portName);
@SuppressWarnings("unchecked") // Can't change the API
Iterator<Handler> iter = handlerChain.iterator();
while (iter.hasNext()) {
Handler handler = iter.next();
handler.init(handlerInfo);
}
String[] soaprolesRegistered = handlerChain.getRoles();
String [] soaproles = new String[soaprolesRegistered.length + soaprolesToAdd.size()];
int i;
for (i = 0;i < soaprolesRegistered.length; i++) {
soaproles[i] = soaprolesRegistered[i];
}
for (int j = 0; j < soaprolesToAdd.size(); j++) {
soaproles[i+j] = soaprolesToAdd.get(j);
}
handlerChain.setRoles(soaproles);
handlerRegistry.setHandlerChain(portName, handlerChain);
}
private void initHandlerChain(QName portName, HandlerRegistry handlerRegistry,
HandlerInfo handlerInfo, ArrayList<String> soaprolesToAdd) {
HandlerChain handlerChain = (HandlerChain) handlerRegistry.getHandlerChain(portName);
@SuppressWarnings("unchecked") // Can't change the API
Iterator<Handler> iter = handlerChain.iterator();
while (iter.hasNext()) {
Handler handler = iter.next();
handler.init(handlerInfo);
}
String[] soaprolesRegistered = handlerChain.getRoles();
String [] soaproles = new String[soaprolesRegistered.length + soaprolesToAdd.size()];
int i;
for (i = 0;i < soaprolesRegistered.length; i++)
soaproles[i] = soaprolesRegistered[i];
for (int j = 0; j < soaprolesToAdd.size(); j++)
soaproles[i+j] = soaprolesToAdd.get(j);
handlerChain.setRoles(soaproles);
handlerRegistry.setHandlerChain(portName, handlerChain);
}
private void initHandlerChain(QName portName, HandlerRegistry handlerRegistry,
HandlerInfo handlerInfo, ArrayList<String> soaprolesToAdd) {
HandlerChain handlerChain = (HandlerChain) handlerRegistry.getHandlerChain(portName);
@SuppressWarnings("unchecked") // Can't change the API
Iterator<Handler> iter = handlerChain.iterator();
while (iter.hasNext()) {
Handler handler = iter.next();
handler.init(handlerInfo);
}
String[] soaprolesRegistered = handlerChain.getRoles();
String [] soaproles = new String[soaprolesRegistered.length + soaprolesToAdd.size()];
int i;
for (i = 0;i < soaprolesRegistered.length; i++)
soaproles[i] = soaprolesRegistered[i];
for (int j = 0; j < soaprolesToAdd.size(); j++)
soaproles[i+j] = soaprolesToAdd.get(j);
handlerChain.setRoles(soaproles);
handlerRegistry.setHandlerChain(portName, handlerChain);
}
protected JPlagTyp_Stub getJPlagStub() {
if (stub == null) {
stub = (JPlagTyp_Stub) (new JPlagService_Impl()
.getJPlagServicePort());
HandlerChain handlerchain = stub._getHandlerChain();
@SuppressWarnings("unchecked")
Iterator<Handler> handlers = handlerchain.iterator();
while (handlers.hasNext()) {
Handler handler = handlers.next();
if (handler instanceof JPlagClientAccessHandler) {
accessHandler = ((JPlagClientAccessHandler) handler);
break;
}
}
}
if (accessHandler != null) {
accessHandler.setUserPassObjects(atujplag.getUsername(),
atujplag.getPassword());
}
return stub;
}
private JPlagTyp_Stub generateStub() {
if (this.stub == null) {
stub = (JPlagTyp_Stub) (new JPlagService_Impl()
.getJPlagServicePort());
HandlerChain handlerchain = stub._getHandlerChain();
@SuppressWarnings("unchecked")
Iterator<Handler> handlers = handlerchain.iterator();
while (handlers.hasNext()) {
Handler handler = handlers.next();
if (handler instanceof JPlagClientAccessHandler) {
this.accessHandler = ((JPlagClientAccessHandler) handler);
break;
}
}
}
if (accessHandler != null) {
accessHandler.setUserPassObjects(atujplag.getUsername(),
atujplag.getPassword());
}
return this.stub;
}
/**
* Returns a singleton JPlag stub
*
* @return The JPlag stub object
*/
public JPlagTyp_Stub getJPlagStub() {
if (stub == null) {
stub = (JPlagTyp_Stub) (new JPlagService_Impl().getJPlagServicePort());
HandlerChain handlerchain = stub._getHandlerChain();
@SuppressWarnings("unchecked")
Iterator<Handler> handlers = handlerchain.iterator();
while (handlers.hasNext()) {
Handler handler = handlers.next();
if (handler instanceof JPlagClientAccessHandler) {
accessHandler = ((JPlagClientAccessHandler) handler);
break;
}
}
}
return stub;
}
public JPlagBean() {
// Setup SSL stuff to allow message encryption
// System.setProperty("javax.net.ssl.trustStorePassword", "gulpie!");
// System.setProperty("javax.net.ssl.trustStore", System.getProperty("catalina.home") + File.separator + "server.trust");
// System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
// java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
stub = (JPlagTyp_Stub) (new JPlagService_Impl().getJPlagServicePort());
// Set the server page login data
HandlerChain handlerchain = stub._getHandlerChain();
@SuppressWarnings("unchecked")
Iterator<Handler> handlers = handlerchain.iterator();
while (handlers.hasNext()) {
Handler handler = handlers.next();
if (handler instanceof JPlagClientAccessHandler) {
((JPlagClientAccessHandler) handler).setUserPassObjects("JPlagJSP", "#Ca+#h8n4un!");
return;
}
}
throw new RuntimeException("JPlagBean(): Unable to find client access" + " handler!");
}
public JPlagTyp_Stub getJplagStub() {
if (stub == null) {
stub = (JPlagTyp_Stub) (new JPlagService_Impl().getJPlagServicePort());
HandlerChain handlerchain = stub._getHandlerChain();
@SuppressWarnings("unchecked")
Iterator<Handler> handlers = handlerchain.iterator();
while (handlers.hasNext()) {
Handler handler = handlers.next();
if (handler instanceof JPlagClientAccessHandler) {
accessHandler = ((JPlagClientAccessHandler) handler);
break;
}
}
}
if (accessHandler != null) {
accessHandler.setUserPassObjects(getJUsernameField().getText(), String.valueOf(getJPasswordField().getPassword()));
}
return stub;
}
public boolean handleRequest(MessageContext context) {
MessageSnapshot snapshot = new MessageSnapshot(context);
try {
for (int i = 0; i < size(); i++) {
Handler currentHandler = (Handler) get(i);
invokedHandlers.addFirst(currentHandler);
try {
if (!currentHandler.handleRequest(context)) {
return false;
}
} catch (SOAPFaultException e) {
throw e;
}
}
} finally {
saveChanges(context);
}
if (!snapshot.equals(context)) {
throw new IllegalStateException("The soap message operation or arguments were illegally modified by the HandlerChain");
}
return true;
}
public boolean handleResponse(MessageContext context) {
MessageSnapshot snapshot = new MessageSnapshot(context);
try {
for (Iterator iterator = invokedHandlers.iterator(); iterator.hasNext(); ) {
Handler handler = (Handler) iterator.next();
if (!handler.handleResponse(context)) {
return false;
}
}
} finally {
saveChanges(context);
}
if (!snapshot.equals(context)) {
throw new IllegalStateException("The soap message operation or arguments were illegally modified by the HandlerChain");
}
return true;
}
public boolean handleFault(MessageContext context) {
MessageSnapshot snapshot = new MessageSnapshot(context);
try {
for (Iterator iterator = invokedHandlers.iterator(); iterator.hasNext(); ) {
Handler handler = (Handler) iterator.next();
if (!handler.handleFault(context)) {
return false;
}
}
} finally {
saveChanges(context);
}
if (!snapshot.equals(context)) {
throw new IllegalStateException("The soap message operation or arguments were illegally modified by the HandlerChain");
}
return true;
}
@SuppressWarnings({"unchecked"})
public HandlerChainImpl(List<HandlerInfo> handlerInfos, String[] roles) {
this.roles = roles;
for (int i = 0; i < handlerInfos.size(); i++) {
HandlerInfo handlerInfo = handlerInfos.get(i);
try {
Handler handler = (Handler) handlerInfo.getHandlerClass().newInstance();
handler.init(handlerInfo);
add(handler);
} catch (Exception e) {
throw new JAXRPCException("Unable to initialize handler class: " + handlerInfo.getHandlerClass().getName(), e);
}
}
}
public void destroy() {
for (Iterator iterator = invokedHandlers.iterator(); iterator.hasNext(); ) {
Handler handler = (Handler) iterator.next();
handler.destroy();
}
invokedHandlers.clear();
clear();
}
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("jplan CLI needs two parameters: username and password!");
System.exit(1);
}
try {
JplagClient jpClient = new JplagClient();
jpClient.stub = (JPlagTyp_Stub) (new JPlagService_Impl().getJPlagServicePort());
HandlerChain handlerchain = jpClient.stub._getHandlerChain();
@SuppressWarnings("rawtypes")
Iterator handlers = handlerchain.iterator();
while (handlers.hasNext()) {
Handler handler = (Handler) handlers.next();
if (handler instanceof JPlagClientAccessHandler) {
jpClient.accessHandler = ((JPlagClientAccessHandler) handler);
break;
}
}
if (jpClient.accessHandler == null) {
System.out.println("Unable to find access handler!");
} else {
jpClient.accessHandler.setUserPassObjects(args[0], args[1]);
}
ServerInfo serverInfo = jpClient.invoke_getServerInfo();
String lstr = "";
LanguageInfo[] langs = serverInfo.getLanguageInfos();
for (int i = 0; i < langs.length; i++) {
lstr += "\nLanguage: " + langs[i].getName() + "\nSuffixes: ";
String[] suf = langs[i].getSuffixes();
for (int j = 0; j < suf.length; j++)
lstr += suf[j] + ((j < suf.length - 1) ? "," : "");
lstr += "\nDefault minimum token length: " + langs[i].getDefMinMatchLen() + "\n";
}
String str = "";
Submission[] subs = serverInfo.getSubmissions();
for (int i = 0; i < subs.length; i++) {
str += "Submission ID: " + subs[i].getSubmissionID() + " Title: " + subs[i].getTitle() + " Date: " + subs[i].getDate()
+ "\n";
}
System.out.println("Left submission slots: " + serverInfo.getUserInfo().getLeftSubmissionSlots());
System.out.println("Account end date: " + serverInfo.getUserInfo().getExpires());
System.out.println("List of languages:\n" + lstr + "\nList of submissions on server:\n" + str);
if (args.length == 2) {
String containerid = jpClient.invoke_compareSource(args);
Status status;
System.out.println("Waiting for server to be done...");
do {
Thread.sleep(4000);
status = jpClient.stub.getStatus(containerid);
System.out.println("State=" + status.getState() + " Progress=" + status.getProgress());
// System.out.flush();
} while (status.getState() >= WAITING_IN_QUEUE && status.getState() < COMPARE_SOURCE_DONE);
if (status.getState() == BAD_USER_ID) {
System.out.println("ARGH! Where did my container go?!? " + status.getReport());
} else if (status.getState() == UNKOWN_ERROR_OCCURED || status.getState() == BAD_LANGUAGE_ERROR
|| status.getState() == NO_ENOUGH_SUBMISSIONS_ERROR) {
System.out.println("Error occurred: " + status.getReport());
} else {
jpClient.extractPart(jpClient.stub.getResult(containerid), args[1]);
}
}
} catch (Exception ex) {
if (ex instanceof JPlagException) {
JPlagException jex = (JPlagException) ex;
System.out.println(jex.getExceptionType());
System.out.println(jex.getDescription());
System.out.println(jex.getRepair());
}
ex.printStackTrace();
}
}