private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
boolean error = false;
String signedXml = "error!";
JSObject window = JSObject.getWindow(this);
try {
if (keyStore == null || keyStore.size() == 0) {
error = true;
signedXml = "Unforunately, it looks as if you don't have any certificates to choose from.";
jTextArea1.setText(signedXml);
jTabbedPane1.setSelectedIndex(2);
return;
}
} catch (Exception ex) {
error = true;
signedXml = "Unforunately, it looks as if you don't have any certificates to choose from.";
jTextArea1.setText(signedXml);
jTabbedPane1.setSelectedIndex(2);
}
if (jList1.getSelectedValue() == null) {
error = true;
signedXml = "You must pick a certificate first";
jTextArea1.setText(signedXml);
jTabbedPane1.setSelectedIndex(2);
}
//Object object2 = window.call("getBrowserName", null);
//Object object1 = window.call("getOsName", null);
Object object3 = window.call("getObjectType", null);
//String browserName = (String) object2;
//tring osName = (String) object2;
String objecttype = (String) object3;
//get the xml
String xml = (String) window.call("getXml", new Object[]{});
Object j = null;
if (objecttype.equalsIgnoreCase("business")) {
try {
StringReader sr = new StringReader(xml.trim());
j = (BusinessEntity) JAXB.unmarshal(sr, BusinessEntity.class);
} catch (Exception ex) {
}
}
if (objecttype.equalsIgnoreCase("service")) {
try {
StringReader sr = new StringReader(xml.trim());
j = (BusinessService) JAXB.unmarshal(sr, BusinessService.class);
} catch (Exception ex) {
}
}
if (objecttype.equalsIgnoreCase("binding")) {
try {
StringReader sr = new StringReader(xml.trim());
j = (BindingTemplate) JAXB.unmarshal(sr, BindingTemplate.class);
} catch (Exception ex) {
}
}
if (objecttype.equalsIgnoreCase("tmodel")) {
try {
StringReader sr = new StringReader(xml.trim());
j = (TModel) JAXB.unmarshal(sr, TModel.class);
} catch (Exception ex) {
}
}
if (j != null) {
try {
//sign it
org.apache.juddi.v3.client.cryptor.DigSigUtil ds = new DigSigUtil();
if (isIncludePublicKey.isSelected()) {
ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_BASE64, "true");
}
if (isIncludeSubjectName.isSelected()) {
ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SUBJECTDN, "true");
}
if (isIncludeIssuer.isSelected()) {
ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SERIAL, "true");
}
ds.put(DigSigUtil.SIGNATURE_METHOD, jTextFieldSigMethod.getText());
ds.put(DigSigUtil.SIGNATURE_OPTION_DIGEST_METHOD, jTextFieldDigestMethod.getText());
ds.put(DigSigUtil.CANONICALIZATIONMETHOD, jTextFieldc14n.getText());
char[] cp = jPasswordField1.getPassword();
if (cp != null && cp.length <= 0) {
cp = null;
}
if (cp != null) {
String s = new String(cp);
s = s.trim();
if ("".equalsIgnoreCase(s)) {
cp = null;
}
}
PrivateKey key = (PrivateKey) keyStore.getKey((String) jList1.getSelectedValue(), cp);
Certificate publickey = keyStore.getCertificate((String) jList1.getSelectedValue());
j = ds.signUddiEntity(j, publickey, key);
ds.clear();
StringWriter sw = new StringWriter();
JAXB.marshal(j, sw);
signedXml = sw.toString();
} catch (Exception ex) {
error = true;
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
signedXml = "Sorry I couldn't sign the data. " + ex.getMessage();
}
} else {
signedXml = "Unable to determine which type of object that we're signing";
}
/*
try {
signedXml = this.sign(xml);
} catch (Exception ex) {
signedXml = ex.getMessage();
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
}*/
if (error) {
jTextArea1.setText(signedXml);
jTabbedPane1.setSelectedIndex(2);
} else {
//write it back to the web page
window.call("writeXml", new Object[]{signedXml});
}
}//GEN-LAST:event_jButton1ActionPerformed