To configure the access path for the class:
@Path (Globalconstants.dbproxy_server_context + "/" + version._1 + "/attachment")
Access path to the configuration method:
GET Request:
The JSON type is returned to the client
@Path ("/get/{id}")
@GET
@Produces ("Application/json")
Public Serverresponse getattachment (@PathParam (value = "id") String ID)
Get POST Request
@POST
Public Serverresponse getattachment (@FormParam (value = "id") String ID)
Get file for put transfer:
@Context
Use @context to get httpservletrequest,httpservletresponse.
@Path ("/newattach/{id}") @PUT @Produces ("Application/json") public serverresponse Newattach (@PathParam ("ID") String
ID, @Context httpservletrequest request) throws ioexception{Long RequestTime = System.currenttimemillis ();
Logger.info ("@GET" + RequestTime + "Attachmentresource.newattach ID:" + ID);
Serverresponse sr = null;
InputStream in = null;
try {in = Request.getinputstream ();
byte[] data = Ioutil.read (in);
Attachmenthelper.newattach (Id,data);
sr = new Serverresponse ("{\" issuccess\ ": \" True\ "}");
catch (Eopexception e) {e.printstacktrace (); Logger.error ("EXCEPTION:" + e.getexceptioncode () + "CODE:" + E.getexceptioncode (). GetCode () + "message:" + e.getmessage (
), E);
sr = new Serverresponse (E.getmessage (), E.getexceptioncode ());
}catch (Exception e) {e.printstacktrace ();
Logger.error (E.getmessage (), E);
sr = new Serverresponse (E.getmessage (), exceptioncode.dbproxy_other); } logger.info ("@GET" + requesttime + "ServerreSponse.newattach sr: "+ sr.tostring () +" use: "+ (Requesttime-system.currenttimemillis ()));
return SR; }
Resteasy returns the response file, which can be written in produces ("*/*") to represent arbitrary files, using @context annotations to obtain response.
@Path ("/getattach/{id}") @GET @Produces ("*/*") public serverresponse Getattach (@PathParam ("id") String ID, @Context Htt
Pservletresponse response) {Long requesttime = System.currenttimemillis ();
Logger.info ("@GET" + RequestTime + "Attachmentresource.getattach ID:" + ID);
OutputStream outputstream = null;
Serverresponse sr = null;
byte[] data = null;
try {outputstream = Response.getoutputstream ();
data = Attachmenthelper.getattach (ID);
Outputstream.write (data);
Outputstream.flush ();
Outputstream.close ();
catch (Eopexception e) {e.printstacktrace (); Logger.error ("EXCEPTION:" + e.getexceptioncode () + "CODE:" + E.getexceptioncode (). GetCode () + "message:" + e.getmessage (
), E);
sr = new Serverresponse (E.getmessage (), E.getexceptioncode ());
}catch (Exception e) {e.printstacktrace ();
Logger.error (E.getmessage (), E);
sr = new Serverresponse (E.getmessage (), exceptioncode.dbproxy_other); } logger.info ("@GET" + requesttime + "ServeRresponse.getattach sr: "+ sr.tostring () +" use: "+ (Requesttime-system.currenttimemillis ()));
return SR; }