pi3requestdispatcher.cpp

来自「mini http server,可以集成嵌入到程序中,实现简单的web功能」· C++ 代码 · 共 148 行

CPP
148
字号
/*____________________________________________________________________________*\
 *

 Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.

 These sources, libraries and applications are
 FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
 as long as the following conditions are adhered to.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 

 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission. 

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

 *____________________________________________________________________________*|
 *
 * $Source: /cvsroot/pi3web/Pi3Web_200/Source/Servlet/Pi3RequestDispatcher.cpp,v $
 * $Date: 2003/05/13 18:42:19 $
 *
 Description:
	Execute an servlet extension.

\*____________________________________________________________________________*/
//$SourceTop:$

#include <jni.h>                            /* where everything is defined */
#include "org_pi3_servlet_core_Pi3RequestDispatcher.h" /* automatically created JNI header */
#include "PiAPI.h"
#include "Pi3API.h"
#include "ServletHandler.h"

/*
 * Class:     org_pi3_servlet_core_Pi3RequestDispatcher
 * Method:    getServlet
 * Signature: (Ljava/lang/String;Ljavax/servlet/ServletRequest;)Ljavax/servlet/Servlet;
 */
JNIEXPORT jobject JNICALL Java_org_pi3_servlet_core_Pi3RequestDispatcher_getServlet
  (JNIEnv *env, jobject dsp, jstring path, jobject req) {
	jclass cls = env->GetObjectClass(req);
	jmethodID getServletHandler;
	getServletHandler = env->GetMethodID( cls, "getServletHandler", "()I");
	// Errorhandling!
	if (!getServletHandler) { return NULL; };
	env->ExceptionClear();

	int SHandler = env->CallIntMethod(req, getServletHandler);
	if ( env->ExceptionOccurred() )
		{
		env->ExceptionDescribe();
		env->ExceptionClear();
		// Errorhandling!
		return NULL;
		};

	jmethodID getPiHttp;
	getPiHttp = env->GetMethodID( cls, "getPiHttp", "()I");
	// Errorhandling!
	if (!getPiHttp) { return NULL; };
	env->ExceptionClear();

	int PiHttp = env->CallIntMethod(req, getPiHttp);
	if ( env->ExceptionOccurred() )
		{
		env->ExceptionDescribe();
		env->ExceptionClear();
		// Errorhandling!
		return NULL;
		};

	jboolean isCopy;
	const char *pPath = env->GetStringUTFChars(path, &isCopy);
	Servlet *sh = (Servlet *)SHandler;

	jobject obj = sh->GetServlet( (PIHTTP *)PiHttp, env, pPath );
	env->ReleaseStringUTFChars(path, pPath);
	return obj;
};


/*
 * Class:     org_pi3_servlet_core_Pi3RequestDispatcher
 * Method:    doHandle
 * Signature: (Ljava/lang/String;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V
 */
JNIEXPORT void JNICALL Java_org_pi3_servlet_core_Pi3RequestDispatcher_doForward
(JNIEnv *env, jobject dsp, jstring path, jobject req, jobject res) {

	jclass cls = env->GetObjectClass(req);
	jmethodID getServletHandler;
	getServletHandler = env->GetMethodID( cls, "getServletHandler", "()I");
	// Errorhandling!
	if (!getServletHandler) { return; };
	env->ExceptionClear();

	int SHandler = env->CallIntMethod(req, getServletHandler);
	if ( env->ExceptionOccurred() )
		{
		env->ExceptionDescribe();
		env->ExceptionClear();
		// Errorhandling!
		return;
		};

	jmethodID getPiHttp;
	getPiHttp = env->GetMethodID( cls, "getPiHttp", "()I");
	// Errorhandling!
	if (!getPiHttp) { return; };
	env->ExceptionClear();

	int PiHttp = env->CallIntMethod(req, getPiHttp);
	if ( env->ExceptionOccurred() )
		{
		env->ExceptionDescribe();
		env->ExceptionClear();
		// Errorhandling!
		return;
		};

	jboolean isCopy;
	const char *pPath = env->GetStringUTFChars(path, &isCopy);
	Servlet *sh = (Servlet *)SHandler;

	sh->DoForward( (PIHTTP *)PiHttp, env, pPath, req, res );
	env->ReleaseStringUTFChars(path, pPath);
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?