To fixe the decoding bug (I already submit a bug+testcase), I use 
MyMixedParamUrlCodingStrategy :

public class MyMixedParamUrlCodingStrategy extends MixedParamUrlCodingStrategy {

    public MyMixedParamUrlCodingStrategy(String mountPath, Class 
bookmarkablePageClass, String[] parameterNames) {
        super(mountPath, bookmarkablePageClass, parameterNames);
    }

    @Override
    public void appendParameters(AppendingStringBuffer url, Map parameters) {
        super.appendParameters(url, parameters);
    }

    @Override
    public ValueMap decodeParameters(String urlFragment, Map urlParameters) {
        ValueMap back = super.decodeParameters(urlFragment, urlParameters);
        for (Object key : back.keySet()) {
            back.put(key, urlDecode(back.getString((String)key)));
        }
        return back;
    }
}

May be, you could do the same for SharedResourceRequestTargetUrlCodingStrategy.

Regards.

Leszek Gawron wrote:
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).


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

Reply via email to