[PF3.2] Image Cropper don't support on fly session images

UI Components for JSF
Post Reply
ryuchile
Posts: 7
Joined: 04 Mar 2012, 17:50

14 Apr 2012, 16:10

i generated a temp image saved on the session with fileUpload.

then i passed the url to the image cropper image property but i need to especify the jsessionid concatenated in the url for don't get a NullPointException on ImageCropperRendered.java:141 (this is because internally create a new client to the server, diferent from the browser, to get the image. this is why a i need to concatenate jsessionid)

but the function "String getFormat(String path)" in ImageCropperRendered fail to detect the format when it has jsessionid concatenated.

i attach a screen shot of this

Image

this is on PrimeFaces 3.2

User avatar
T.dot
Expert Member
Posts: 620
Joined: 01 Feb 2012, 15:39
Location: Vienna/Austria

14 Apr 2012, 16:43

ImageCropper doesn't support dynamic images. I think your problem is related to this.

There are issues about imageCropper here:
http://code.google.com/p/primefaces/iss ... il?id=3751
http://code.google.com/p/primefaces/iss ... il?id=1603

ryuchile
Posts: 7
Joined: 04 Mar 2012, 17:50

14 Apr 2012, 16:45

from your first issue you only need to append jsessionid to the url in the component, like this:

image="http://#{request.serverName}:#{request.serverPort}#{request.contextPath}/uploadimagencrop/subida.jpeg;jsessionid=#{session.id}"

then you will get error of the format.


the problem is the behaviour of

protected String getFormat(String path) {
String[] pathTokens = path.split("\\.");

return pathTokens[pathTokens.length - 1];
}

in ImageCropperRendered.java

this is getting the format direct from url, instead of getting the format from the header http of the response(contentType? image/JPEG PNG, etc)

by the way, why ImageCropperRendered class , in "BufferedImage getSourceImage(FacesContext context, String imagePath)" has a distinction of is External or not? I think it should always be treated as external (http), Then get the format from http headers, content type.

something like this

String type = null;
URL u = new URL(fileUrl);
URLConnection uc = null;
uc = u.openConnection();
type = uc.getContentType();
return type;

ryuchile
Posts: 7
Joined: 04 Mar 2012, 17:50

14 Apr 2012, 22:54

i created a solution for this:

extending the render kit and the render class.


on faces-config:

<render-kit>
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.ImageCropperRenderer</renderer-type>
<renderer-class>org.primefaces.component.imagecropper.TrollFacesImageCropperRenderer</renderer-class>
</renderer>
</render-kit>


on the class:

package org.primefaces.component.imagecropper;

import java.net.URL;
import java.net.URLConnection;

/**
*
* @author RyuChile
*/
public class TrollFacesImageCropperRenderer extends ImageCropperRenderer {

@Override
protected String getFormat(String path) {
String contentType = null;
try {
URL url = new URL(path);
URLConnection connection = url.openConnection();
connection.connect();
contentType = connection.getContentType();
}catch (Exception ex) {
throw new RuntimeException("Connection to the url failed",ex);
}

if(contentType == null) {
throw new RuntimeException("Problem getting url contentType is null!");
}

String format = contentType.toLowerCase().trim().replace("image/","");

if(format == null || format.length() == 0){
throw new RuntimeException("Unknow image mime type");
}

if(format.contains(";")) //contains a semicolon
{
format = format.split(";")[0];
}

if(format == null || format.length() == 0){
throw new RuntimeException("Unknow image mime type");
}

System.out.println("the format is: " + format);
return format;
}
}


now works well with session, but i think i break the behaviour when is internal (file)

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

15 Apr 2012, 01:13

Create an issue please - jsessionid must be supported.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko


Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: jossey and 22 guests