Folks,
My CryptoService adheres to my own unique interface. So I have no need to
associate or latch onto anything HLS created.
But I did try to bootstrap it into hivemind as an ASO
<contribution configuration-id="tapestry.state.ApplicationObjects">
<state-object name="cryptoService" scope="application">
<create-instance class="common.crypto.CryptoService"/>
</state-object>
</contribution>
but upon operating my annotation in java
@InjectState("cryptoService")
public abstract CryptoService getCryptoService();
The thing quits with an exception stating that the object was not
formatted
[ +/- ] Exception: Error: An error occured processing annotation
@org.apache.tapestry.annotations.InjectObject(value=cryptoService) of
public
abstract common.crypto.CryptoService proto.Login.getCryptoService():
Error:
Object provider selector 'cryptoService' is not properly formatted.
But then I found other hivemind threads that talk about HiveUtils saying
that there is no way to treat any pojo like above and we should be doing
this...
<contribution configuration-id="hiveutils.ObjectBuilderObjects">
<object name="CryptoService" cached="true"
class="common.crypto.CryptoService">
<inject name="entityService" object="service:EntityService"
/>
</object>
</contribution>
<contribution configuration-id="tapestry.state.ApplicationObjects">
<state-object name="cryptoService" scope="application">
<invoke-factory object="object:CryptoService" />
</state-object>
</contribution>
But that failed due to non-existent config id of some sort...
Can anyone tell me how to get my basic pojo+unique interface into
hivemind?
Using tap-4.1.1
Thanks in advance
Best regards
Ken
---> Here is the interface
package common.crypto;
public interface ICrypto {
public SecretKey generateKey();
public Cipher createCipher();
public String enCipher(String value);
public String deCipher(String value);
}
---> Here is the implementation
package common.crypto;
public class CryptoService implements Serializable, ICrypto,
StateObjectFactory {
private Cipher cipher;
private SecretKey key;
public CryptoService() {
generateKey();
createCipher();
}
public Object createStateObject() {
return new CryptoService();
}
public SecretKey generateKey() {
try {
KeyGenerator keygen = KeyGenerator.getInstance
("DES");
key = keygen.generateKey();
} catch (NoSuchAlgorithmException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
}
return key;
}
public Cipher createCipher() {
try {
cipher = Cipher.getInstance
("DES/ECB/PKCS5Padding");
} catch (NoSuchAlgorithmException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
} catch (NoSuchPaddingException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
}
return cipher;
}
public String enCipher(String value) {
String result = "";
try {
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] text = cipher.doFinal(value.getBytes());
result = new String(text.toString());
} catch (InvalidKeyException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
} catch (BadPaddingException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
} catch (IllegalBlockSizeException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
}
return result;
}
public String deCipher(String value) {
String result = "";
try {
cipher.init(Cipher.DECRYPT_MODE, key);
// Decrypt the ciphertext
byte[] text = cipher.doFinal(value.getBytes());
result = new String(text.toString());
} catch (InvalidKeyException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
} catch (BadPaddingException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
} catch (IllegalBlockSizeException ex) {
System.out.println(ExceptionFormatter.logException
(ex));
}
return result;
}
public Cipher getCipher() {
return cipher;
}
public void setCipher(Cipher cipher) {
this.cipher = cipher;
}
public SecretKey getKey() {
return key;
}
public void setKey(SecretKey key) {
this.key = key;
}
}
_________________________________________________________________
Stay in touch with old friends and meet new ones with Windows Live Spaces
http://clk.atdmt.com/MSN/go/msnnkwsp0070000001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us