You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by logancillo <al...@gmail.com> on 2008/08/11 12:59:48 UTC

i'm not able to display in a jsp client jpg file

hi everyone, i hope someone could help me!

im developing a webservice using EasyEclipse Server Java Version: 1.2.2.2,
all i need to do this ws is read a jpg from server and convert it in a byte
[], then i like to show it in a jsp client.

this is the implementation webservice class:

public class MapServicePortBindingImpl implements
		org.example.www.MAP.MapServicePortType {
	public org.example.www.MAP.MapResponseType getMap(
			org.example.www.MAP.MapRequestType parameters)
			throws java.rmi.RemoteException {

		MapResponseType mpt = new MapResponseType();
		boolean enc=false;
		String rutaACargar;
		byte[] byteValAlt = null;
		System.out.println("parametros recibidos:" + parameters.getAddress()
				+ parameters.getCountry() + parameters.getNumber()
				+ parameters.getPostalCode() + parameters.getProvince());

		try {
			java.util.Random r = new Random();
			int i = r.nextInt();
			// si es par
			if (i % 2 == 0) {
				System.out.println("badajoz..." + i);
				rutaACargar = "/home/alonso/badajoz.jpg";
				enc=true;
				mpt.setMapStatusCode(0);
				mpt.setMapStatusDescription("OK.badajoz");
			} else {
				System.out.println("caceres..." + i);
				rutaACargar = "/home/alonso/caceres.jpg";
				enc=true;
				mpt.setMapStatusCode(0);
				mpt.setMapStatusDescription("OK.caceres");
			}
			// si es multiple de 3, mostraremos un error controlado
			if (!enc) {
				System.out.println("el mapa no se ha encontrado.");
				rutaACargar = "/home/alonso/404.jpg";
				mpt.setMapStatusCode(1);
				mpt
						.setMapStatusDescription("ERROR. Mapa no encontrado en el sistema.");
			}
			Imagen obj = new Imagen();
			byteValAlt = obj.leerImagen(rutaACargar);
			mpt.setMapFile(byteValAlt);

		} catch (IOException e) {
			System.out.println("IOException: " + e.getMessage());
			e.printStackTrace();
			mpt.setMapFile(byteValAlt);
			mpt.setMapStatusDescription("ERROR IOException: " + e.getMessage());
			mpt.setMapStatusCode(1);
		}

		return mpt;

	}

this is Imagen.java

public class Imagen implements Serializable {

	private static final long serialVersionUID = -3456755345210057232L;

	public Imagen()  {
	}

	public byte[] getArrayBytes() throws IOException {
		ByteArrayOutputStream bStream = new ByteArrayOutputStream();
		ObjectOutputStream oStream = new ObjectOutputStream( bStream );
		oStream.writeObject(this);
		oStream.flush();
		bStream.close();
		oStream.close();
		return bStream.toByteArray();
	}

	/*
	   * Metodo encardado ingresar la imagen en un java.io.InputStream
	   */
	  public byte[] leerImagen(String imagen) throws IOException {

		  try {
			  long t1=System.currentTimeMillis();
			  System.out.println("leyendo bytes del mapa...");
			  FileInputStream miFichero = new FileInputStream(imagen);
			  BufferedInputStream bufferedInput = new BufferedInputStream(miFichero);
			  byte[] data=obtenerBytes(bufferedInput,bufferedInput.available());
			  long t2=System.currentTimeMillis();
			  System.out.println("bytes del mapa leidos...");
			  System.out.println (t2-t1 + " ms");
			  bufferedInput.close();
			  miFichero.close();

			  /*
			   * img es BufferedImage
			  ByteArrayOutputStream os = new ByteArrayOutputStream();
			  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
			  encoder.encode(img);
			  */
			  return data;

		} catch(Exception e){
		      e.printStackTrace();
		}

	    return null;
	  }

	  /*
	   * Devuelve el array de bytes
	   */
	  private static byte[] obtenerBytes(java.io.InputStream is,int capacidad){
	    java.io.DataInputStream dis=new java.io.DataInputStream(is);
	    byte[] bytes=new byte[capacidad];//para la capacidad del array
	    try{
	      dis.readFully(bytes);//los bytes de la imagen son introducidos en el
array "bytes"
	      if(dis!=null)
	        dis.close();//cierro el archivo
	    }catch(java.io.IOException ioe){
	      ioe.printStackTrace();
	    }
	    return bytes;
	  }
}

now in result.jsp i have something like this:

<jsp:useBean id="sampleMapServicePortTypeProxyid" scope="session"
class="org.example.www.MAP.MapServicePortTypeProxy" />

String province_2id=  request.getParameter("province24");
        java.lang.String province_2idTemp  = province_2id;
        String address_3id=  request.getParameter("address26");
        java.lang.String address_3idTemp  = address_3id;
        String number_4id=  request.getParameter("number28");
        java.lang.String number_4idTemp  = number_4id;
        String postalCode_5id=  request.getParameter("postalCode30");
        java.lang.String postalCode_5idTemp  = postalCode_5id;
        String country_6id=  request.getParameter("country32");
        java.lang.String country_6idTemp  = country_6id;
        %>
        <jsp:useBean id="org1example1www1MAP1MapRequestType_1id"
scope="session" class="org.example.www.MAP.MapRequestType" />
        <%
       
org1example1www1MAP1MapRequestType_1id.setProvince(province_2idTemp);
        org1example1www1MAP1MapRequestType_1id.setAddress(address_3idTemp);
        org1example1www1MAP1MapRequestType_1id.setNumber(number_4idTemp);
       
org1example1www1MAP1MapRequestType_1id.setPostalCode(postalCode_5idTemp);
        org1example1www1MAP1MapRequestType_1id.setCountry(country_6idTemp);
        org.example.www.MAP.MapResponseType getMap13mtemp =
sampleMapServicePortTypeProxyid.getMap(org1example1www1MAP1MapRequestType_1id);

<TABLE>
<TR>
<TD COLSPAN="3" ALIGN="LEFT">returnp:</TD>
<TD WIDTH="5%"></TD>
<TD COLSPAN="2" ALIGN="LEFT">mapFile:</TD>
<TD>
<%
if(getMap13mtemp != null){
byte[] typemapFile18 = getMap13mtemp.getMapFile();
how can i convert this byte[] into a img src.... ???? can i show this jpg
file????
}%>
</TD>
</TR>
</TABLE>


i have read this

http://72.5.124.111/thread.jspa?threadID=5204277&messageID=9844439

who says that is not possible! is it?

thx in advanced people!
-- 
View this message in context: http://www.nabble.com/i%27m-not-able-to-display-in-a-jsp-client-jpg-file-tp18923486p18923486.html
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org