In order for Tapestry to autowire your service into your property, it must be of the same type.  Try this:

public abstract ICrypto getCryptoService();

On 10/23/06, Ken nashua <[EMAIL PROTECTED]> wrote:
Guys,

I removed the annotation to enable auto-wire with the following:
        public abstract CryptoService getCryptoService();

I tried the following:

        public IPage onFormSubmit(IRequestCycle cycle) {
                try {
                        CookieSource cookieSrc = getCookieSource();
                        CryptoService cryptoService = getCryptoService();

Using the following hive-module.xml :
    <service-point id="CryptoService" interface="common.crypto.ICrypto"/>
    <implementation service-id="CryptoService">
        <create-instance class="common.crypto.CryptoService "/>
    </implementation>

RESULT...

getCryptoService() returns null

I even changed the service-id and id of service-point to have lower case
"cryptoService" since HLS suggested a case issue with caps.
    <service-point id="cryptoService" interface="common.crypto.ICrypto"/>
    <implementation service-id="cryptoService">
        <create-instance class="common.crypto.CryptoService "/>
    </implementation>

No luck,
Any suggestions?

Thanks in advance


---> Here is the service again with interface (Notice I added both support
for factory and service to no avail)

package common.crypto;

import java.io.IOException;
import java.io.Serializable;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException ;
import javax.crypto.SecretKey;

import org.apache.hivemind.util.Defense;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService ;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.engine.state.StateObjectFactory;
import org.apache.tapestry.error.RequestExceptionReporter;
import org.apache.tapestry.services.LinkFactory ;
import org.apache.tapestry.services.ServiceConstants;
import org.apache.tapestry.web.WebResponse;

import common.ExceptionFormatter;

public class CryptoService implements Serializable, ICrypto, IEngineService,
                StateObjectFactory {
        public static final String SERVICE_NAME = "CryptoService";

        private RequestExceptionReporter exceptionReporter;

        private LinkFactory linkFactory;

        private WebResponse response;

        private Cipher cipher;

        private SecretKey key;

        public CryptoService() {
                generateKey();
                createCipher();
        }

        public ILink getLink(boolean post, Object parameter) {
                Defense.isAssignable(parameter, IComponent.class, "parameter");

                IComponent component = (IComponent) parameter;

                Map parameters = new HashMap();

                parameters.put(ServiceConstants.SERVICE, getName());
                parameters
                                .put(ServiceConstants.PAGE , component.getPage().getPageName());
                parameters.put(ServiceConstants.COMPONENT, component.getIdPath());

                return linkFactory.constructLink(this, false, parameters, true);
        }

        public void service(IRequestCycle cycle) throws IOException {
                String pageName = cycle.getParameter(ServiceConstants.PAGE);
                String componentId = cycle.getParameter(ServiceConstants.COMPONENT );

                IPage page = cycle.getPage(pageName);
                IComponent component = page.getNestedComponent(componentId);

                try {

                } catch (ClassCastException ex) {
                        exceptionReporter.reportRequestException("Component "
                                        + component.getExtendedId()
                                        + " does not implement IChartProvider.", ex);

                        return;
                } catch (Throwable ex) {
                        exceptionReporter.reportRequestException(
                                        "Error creating JPEG stream.", ex);

                        return;
                }

                return;
        }

        public String getName() {
                return SERVICE_NAME;
        }

        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;
        }

        public RequestExceptionReporter getExceptionReporter() {
                return exceptionReporter;
        }

        public void setExceptionReporter(RequestExceptionReporter
exceptionReporter) {
                this.exceptionReporter = exceptionReporter;
        }

        public LinkFactory getLinkFactory() {
                return linkFactory;
        }

        public void setLinkFactory(LinkFactory linkFactory) {
                this.linkFactory = linkFactory;
        }

        public WebResponse getResponse() {
                return response;
        }

        public void setResponse(WebResponse response) {
                this.response = response;
        }
}

package common.crypto;

import javax.crypto.*;


public interface ICrypto {

        public SecretKey generateKey();

        public Cipher createCipher();

        public String enCipher(String value);

        public String deCipher(String value);
}











Is this object supposed to be a "state" object or a "service" object?  It's
called a service, but you're trying to use it as an ASO (application state
object).  This is somewhat of a Tapestry question and should go to the
tapestry user list, but I'm familiar enough with Tapestry to help you I
think.  Since you're using tap 4.1.x, you can just create a service point
(the website docs cover this) for your CryptoService interface and Tapestry
will automatically inject (or "autowire") it into your components/pages by
just declaring this:

public abstract CryptoService getCryptoService();




On 10/19/06, Ken nashua <[EMAIL PROTECTED] > wrote:
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="">

_________________________________________________________________
Try the next generation of search with Windows Live Search today!
http://imagine-windowslive.com/minisites/searchlaunch/?locale=en-us&source=hmtagline


Reply via email to