David Bernard wrote:
Hi,

You can mount with a coding strategy in Application.init, something like .. (I do it for attachment) mount(new MyMixedParamUrlCodingStrategy("/images", Page.class, new String[] { "id", "move" }) {
                @Override
public IRequestTarget decode(RequestParameters requestParameters) {
                    try {
ValueMap params = decodeParameters(requestParameters.getPath().substring(getMountPath().length()), requestParameters.getParameters());
                        String id = params.getString("id");
                        String move = params.getString("move");
                        if (StringUtils.isNotBlank(id)) {
                            ...
                            return new ResourceStreamRequestTarget(...);
                        }
return new WebErrorCodeResponseTarget(HttpServletResponse.SC_NOT_FOUND);

nice to know how to return errors :)

                        //return super.decode(requestParameters);
                    } catch (RuntimeException exc) {
                        throw exc;
                    } catch (Exception exc) {
throw new RuntimeException("wrap: " + exc.getMessage(), exc);
                    }
                }
            });

Thanks, I managed to do something like this:

getSharedResources().add(       "snapshot", new CameraSnapshotResource() );
mount( new SharedResourceRequestTargetUrlCodingStrategy( "/snapshot", new 
ResourceReference( "snapshot" ).getSharedResourceKey() ) );

public class CameraSnapshotResource extends DynamicWebResource {
        @SpringBean
        private CameraSnapshotService   cameraSnapshotService;

        public CameraSnapshotResource() {
                InjectorHolder.getInjector().inject( this );
        }

        @Override
        protected ResourceState getResourceState() {
                ValueMap parameters = getParameters();
                Long id = parameters.getLong( "id" );
                final CameraSnapshot snapshot = cameraSnapshotService.findById( 
id );

                return new ResourceState() {
                        @Override
                        public String getContentType() {
                                return "image/jpeg";
                        }

                        @Override
                        public byte[] getData() {
                                try {
                                        return snapshot.getData().getBytes( 1,
                                                                                
                                snapshot.getSize() );
                                } catch ( SQLException e ) {
                                        throw new RuntimeException( "unable to fetch 
image data", e );
                                }
                        }
                };
        }
}

Now I have a problem:

http://host/wicketapp/snapshot?id=1 works
http://host/wicketapp/snapshot/id/1 does not (although when debugging I see parameters get decoded).

--
Leszek Gawron

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to