Esempio n. 1
0
func View(this *ViewController, loadImgRequest *request.LoadImgRequest) {
	var result = util.Error{}
	Cat := cat.Instance()
	title := "/fdupload/target"
	if loadImgRequest.IsSource {
		title = "/fdupload/source"
	}
	tran := Cat.NewTransaction("URL", title)
	defer func() {
		if p := recover(); p != nil {
			Cat.LogPanic(p)
		}
		if result.Err != nil {
			tran.SetStatus(result.Err)
		} else {
			tran.SetStatus("0")
		}
		tran.Complete()
	}()
	util.LogEvent(Cat, "URL", "URL.Client", map[string]string{
		"clientip": util.GetClientIP(this.Ctx.Request),
		"serverip": util.GetIP(),
		"proto":    this.Ctx.Request.Proto,
		"referer":  this.Ctx.Request.Referer(),
		//"agent":    request.UserAgent(),
	})
	util.LogEvent(Cat, "URL", "URL.Method", map[string]string{
		"Http": this.Ctx.Request.Method + " " + loadImgRequest.FilePath,
	})

	imgRequest := business.ImageRequest{}
	imgRequest.Cat = Cat
	resp, e := imgRequest.Download(loadImgRequest)

	if e.Err != nil {
		this.Ctx.WriteString(e.Err.(error).Error())
	} else {
		//this.Ctx.Output.ContentType("image/Jpeg")

		//this.Ctx.Output.Body(resp.FileBytes)
		bts, err := soapparse.B64.DecodeString(string(resp.FileBytes))
		if err != nil {
			this.Ctx.WriteString(err.Error())
		} else {
			this.Ctx.Output.Header("Content-Type", "image/jpeg")
			this.Ctx.Output.Body(bts)
		}
	}
}
Esempio n. 2
0
func (handler *ImageWS) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()
	w.Header().Set("Connection", "keep-alive")
	w.Header().Set("Content-Type", "text/xml")

	Cat := cat.Instance()
	tran := Cat.NewTransaction("URL", "ImageWs.asmx")
	util.LogEvent(Cat, "URL", "URL.Client", map[string]string{
		"clientip": util.GetClientIP(r),
		"serverip": util.GetIP(),
		"proto":    r.Proto,
		"referer":  r.Referer(),
		//"agent":    request.UserAgent(),
	})
	var result util.Error
	defer func() {
		if p := recover(); p != nil {
			Cat.LogPanic(p)
		}
		if result.Err != nil && !result.IsNormal {
			tran.SetStatus(result.Err)

		} else {
			tran.SetStatus("0")
		}
		tran.Complete()
	}()
	bts, err := ioutil.ReadAll(r.Body)
	if err != nil {
		util.LogErrorEvent(Cat, "RequestReadError", err.Error())
		result = util.Error{IsNormal: false, Err: err, Type: "RequestReadError"}
		msg := []byte(err.Error())
		writeResponse(w, msg)
		return
	}
	req := request.Request{}
	result = EncodeRequest(Cat, bts, &req)
	if result.Err != nil && !result.IsNormal {
		writeResponse(w, []byte(result.Type))
		return
	}
	var (
		resp       interface{}
		header     *response.Header
		e          util.Error
		imgRequest = business.ImageRequest{Cat: Cat}
	)

	requestTran := Cat.NewTransaction("Request", strings.Replace(req.Header.RequestType, "Arch.Base.ImageWS.", "", -1))
	defer func() {
		if p := recover(); p != nil {
			Cat.LogPanic(p)
		}
		if result.Err != nil && !result.IsNormal {
			requestTran.SetStatus(result.Err)
		} else {
			requestTran.SetStatus(CATTRANSUCCESS)
		}
		requestTran.Complete()
	}()

	switch req.Header.RequestType {
	case REQUESTTYPE_SAVEIMAGE:
		resp, e = imgRequest.Save(&req.SaveRequest)
	case REQUESTTYPE_LOADIMAGE:
		resp, e = imgRequest.Download(&req.LoadImgRequest)
	case REQUESTTYPE_LOADZIP:
		resp, e = imgRequest.DownloadZip(&req.LoadZipRequest)
	case REQUESTTYPE_DELETEIMAGE:
		resp, e = imgRequest.Delete(&req.DeleteRequest)
	default:
		util.LogErrorEvent(Cat, "RequestTypeInvalid", req.Header.RequestType)
		e = util.Error{IsNormal: true, Err: errors.New("requesttype is invalid!"), Type: "RequestTypeInvalid"}
	}
	if e.Err != nil {
		result = e
		header = createFailHeader(req.Header, fmt.Sprintf("%v", e.Err))
	} else {
		header = transformHeader(req.Header, RESULTCODE_SUCCESS, "")
	}
	content, e := DecodeResponse(Cat, header, resp)
	if e.Err != nil {
		result = e
		writeResponse(w, []byte(result.Err.(error).Error()))
	} else {
		writeResponse(w, content)
	}
}