You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by jm...@apache.org on 2001/03/14 20:39:57 UTC
cvs commit: xml-soap/java/src/org/apache/soap/providers/com COMProvider.properties Log.java Makefile RPCProvider.cpp RPCProvider.h RPCProvider.java dbgutils.h
jmsnell 01/03/14 11:39:57
Added: java/src/org/apache/soap/providers/com
COMProvider.properties Log.java Makefile
RPCProvider.cpp RPCProvider.h RPCProvider.java
dbgutils.h
Log:
Adding COM Provider to CVS tree
Revision Changes Path
1.1 xml-soap/java/src/org/apache/soap/providers/com/COMProvider.properties
Index: COMProvider.properties
===================================================================
#
msg.comprovider.ok=\
COMProvider successful, return object: "{0}"
msg.comprovider.inlocate=\
Entered {0} for "{1}" and method "{2}".
msg.comprovider.dllfail=\
Failed to load dll for COMProvder. Check path. {0}
msg.comprovider.badMethod=\
Object uri "{0}" invalid method called "{1}". Not listed in deployment descriptor.
msg.comprovider.info.parms=\
Parameter "{0}" class is: "{1}" , to sting is: "{2}
msg.comprovider.info.cominf=\
COM progid "{0}" threading model"{1}".
msg.comprovider.error.nullprog=\
COMProvider internal error: invoke called on a null progid:"{0}" uri:"{1}".
msg.comprovider.error.nullmname=\
COMProvider internal error: invoke called on a null method name"{0}".
msg.comprovider.error.nativeError=\
COMProvider: native code exception:{0}
msg.comprovider.error.exp=\
COMProvider: Exeption in processing native response:{0}
#endof msg file
1.1 xml-soap/java/src/org/apache/soap/providers/com/Log.java
Index: Log.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* 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 end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* 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 APACHE SOFTWARE FOUNDATION 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.soap.providers.com;
import java.io.* ;
import java.util.* ;
import java.text.MessageFormat;
import javax.servlet.* ;
import javax.servlet.http.* ;
import org.apache.soap.util.* ;
import java.lang.Math;
public class Log
{
private ServletContext sc= null;
static Log log= null;
public static final short INFORMATION = 0x1000;
public static final short SUCCESS= 0x100;
public static final short WARNING = 0x10;
public static final short ERROR = 1;
public static final short NOINIT = -1;
static short currentLevel=NOINIT;
static final String pname= "org.apache.soap.providers.com";
static final String cname= pname + ".COMProvider";
protected static final String msgFile= cname;
protected java.io.PrintStream ls= null;
protected static ResourceBundle rb=null;
public static synchronized void init( Servlet servlet) //Specialize for HTTP.
{
if(log != null) return;
String params= null;
if(servlet != null) params= servlet.getServletConfig().getInitParameter("comprovider.msglvl");
java.io.PrintStream ls= null;
String propInit= params == null ? findMessageString("loginit") : params;
if(propInit != null)
{
StringTokenizer tok= new StringTokenizer(propInit);
String f1= tok.hasMoreTokens() ? tok.nextToken() : "";
if( f1.length() != 0)
{
if( 0 == f1.compareTo("="))
{
String f2= null;
try{
f2= tok.hasMoreTokens() ? tok.nextToken() : "";
Class cl= Class.forName(f2);
Object o= cl.newInstance();
if( o instanceof Log)
{
((Log)o).init( servlet, params);
}
else
{
ls= System.err;
System.err.println("Log handler:" + f2 + " not an instance of Log."); //Just keep going.
log= new Log(null, "-file -" ); //Instance allows for subclassing.
}
}
catch ( Exception e)
{
log= new Log(null, "-file -" );
System.err.println("Error in loading log handler=" + f2 + "exception " + e); //Just keep going.
}
return; //done.
}
}
}
log= new Log(servlet, params); //Instance allows for subclassing.
}
public void init( Servlet servlet, String params){/* Do nothing */};
public Log( Servlet servlet, String params)
{
currentLevel= ERROR;
if(null != params)
for( StringTokenizer tok= new StringTokenizer(params);tok.hasMoreTokens();)
{
String f1= tok.nextToken();
if( 0 == f1.compareTo("-noservletlog"))
{
servlet= null;
}
else if( 0 == f1.compareTo("-file"))
{
if(tok.hasMoreTokens())
{
String f2= tok.nextToken();
if( 0 == f2.compareTo("+") ) ls= System.out;
else if( 0 == f2.compareTo("-")) ls= System.err;
else
{
try
{
ls= new PrintStream(new BufferedOutputStream( new FileOutputStream( f2, true)), true);
}catch( java.io.FileNotFoundException e)
{
ls= System.err;
}
}
}
}
else
{
try{
if(0==f1.compareToIgnoreCase("INFORMATION")) currentLevel= INFORMATION | SUCCESS | WARNING | ERROR;
else if(0==f1.compareToIgnoreCase("SUCCESS")) currentLevel= SUCCESS | WARNING | ERROR;
else if(0==f1.compareToIgnoreCase("WARNING")) currentLevel= WARNING | ERROR;
else if(0==f1.compareToIgnoreCase("ERROR"));
else currentLevel= Short.parseShort(params);
}catch(Exception e) { currentLevel= ERROR;}
}
}//endfor
if(null != servlet) sc= servlet.getServletConfig().getServletContext();
}
public static void init()
{
init( null);
}
public static String getMessage(String msgId, Object[] args)
{
String ret= findMessageString(msgId, args);
if(ret == null)
ret= "Missing msg id \""+ msgId +"\" in \"" + msgFile +"\".";
return ret;
}
public static String findMessageString(String msgId)
{
return findMessageString(msgId, null);
}
public static String findMessageString(String msgId, Object[] args)
{
String ret= null;
try
{
if( rb == null) rb = ResourceBundle.getBundle (msgFile, Locale.getDefault());
String formatString = rb.getString(msgId);
if (args == null) ret= formatString;
else
{
MessageFormat formatter = new MessageFormat(formatString);
ret= formatter.format(args);
}
} catch (java.util.MissingResourceException mre) {
}
return ret;
}
public String logit(final int level, String s) //Could be over ride. called by CPP!!!
{
if( s == null) s= "null";
if(ls != null) ls.println(s);
if( null != sc) sc.log(s);
return s;
}
public String logit(final int level, final String msgId, final Object[] args) //Could be over ride.
{
String s= getMessage(msgId, args);
logit(level, s);
return s;
}
public static final String msg(final int level, final String msg )
{
return log.logit(level, msg);
}
public static final String msg(final int level, final String msgId, Object o )
{
if( (level & currentLevel) == 0 ) return "" ;
return msg( level, msgId, new Object[] {o});
}
public static final String msg(final int level, final String msgId, Object o, Object o2 )
{
if( (level & currentLevel) == 0 ) return "" ;
return msg( level, msgId, new Object[] {o,o2});
}
public static final String msg(final int level, final String msgid, Object o, Object o2, Object o3 )
{
if( (level & currentLevel) == 0 ) return "" ;
return msg( level, msgid, new Object[] {o,o2,o3});
}
public static final String msg(final int level, final String msgId, Object o, Object o2, Object o3, Object o4 )
{
if( (level & currentLevel) == 0 ) return "" ;
return msg( level, msgId, new Object[] {o,o2,o3,o4});
}
public static final String msg(final int level, final String msgId, final Object[] args)
{
if( (level & currentLevel) == 0 ) return "" ;
return log.logit( level, msgId, args);
}
public static final short getLevel()
{
return currentLevel;
}
public static final boolean willLog(short level)
{
return (level & currentLevel) == 0;
}
}
1.1 xml-soap/java/src/org/apache/soap/providers/com/Makefile
Index: Makefile
===================================================================
#Make file for COMProvider
JNIHeader=org_apache_soap_providers_com_RPCProvider.h
COMProviderPackage=org.apache.soap.providers.com
OUTDIR=
INTDIR=
!ifdef ANTBUILD
!message Ant build home dir is: $(ANTBUILDTARGET)
!message Ant build classpath is $(ANTBUILDCLASSPATH)
MAKECLASSPATH=$(ANTBUILDCLASSPATH:/=\)
TARGETDIR=$(ANTBUILDTARGET:/=\)
TARGETS=$(TARGETDIR)\COMProvider.dll
#handle ANTBUIILD debug indicator
!UNDEF DEBUG
!IF "$(ANTBUILDDEBUG)" == "righton"
DEBUG=1
!ENDIF
!ELSE
TARGETDIR=.
TARGETS=RPCProvider.class $(TARGETDIR)\COMProvider.dll
MAKECLASSPATH=$(CLASSPATH)
!ENDIF
!ifdef DEBUG
!MESSAGE DEBUG BUILD!!! DEBUG BUILD!!! DEBUG BUILD!!! DEBUG BUILD!!! DEBUG BUILD!!! DEBUG BUILD!!! DEBUG BUILD!!! DEBUG BUILD!!!
CPP_OPTIONS=/MDd /Gm /Zi /Od /D /YX /D _DEBUG /D DEBUG
RSC_OPIONS=/d _DEBUG /d DEBUG
LINK_OPTIONS=/debug /pdbtype:sept /INCREMENTAL:YES
LINK_LIBS= MSVCRTD.LIB
JDEBUG= -g
!else
CPP_OPTIONS=/MD /O2 /D NDEBUG
RSC_OPIONS=/d NDEBUG
LINK_OPTIONS= /RELEASE /INCREMENTAL:NO
LINK_LIBS= MSVCRT.LIB
JDEBUG=
!endif
JNI_INCLUDE=/I$(JAVA_HOME)/include /I$(JAVA_HOME)/include/win32
CPP_OPTIONS= $(CPP_OPTIONS) /D _UNICODE /D UNICODE
CPP=cl.exe /c
# /D WIN32_LEAN_AND_MEAN /D VC_EXTRALEAN #Leaves out COM stuff
CPP_PROJ=/nologo /W3 /GX /D_WIN32_WINNT=0x400 /DWINVER=0x400\
$(CPP_OPTIONS) /D _WINDOWS /D _WINDLL\
/D _AFXDLL /D _USRDLL /I . /Fo$(INTDIR) /Fd$(INTDIR) /FD
LINK32=cl.exe
# /NODEFAULTLIB\/IMPLIB:NUL
LINK32_FLAGS= /link /nologo /subsystem:windows /dll \
/pdb:$(OUTDIR)COMProvider.pdb /machine:I386 \
$(LINK_OPTIONS) $(LINK_LIBS)
LINK_LIBS= $(LINK_LIBS)\
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib \
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
LINK32_OBJS= \
$(INTDIR)RPCProvider.obj
all : $(TARGETS)
$(TARGETDIR)\COMProvider.dll : \
$(LINK32_OBJS)
$(LINK32) $(LINK32_OBJS) $(LINK32_FLAGS) /out:$(TARGETDIR)\COMProvider.dll
!ifdef DEBUG
if exist $(TARGETDIR)\COMProvider.dll copy $(TARGETDIR)\COMProvider.dll $(TARGETDIR)\COMProvider_g.dll
!else
if exist $(TARGETDIR)\COMProvider.exp del $(TARGETDIR)\COMProvider.exp
if exist $(TARGETDIR)\COMProvider.lib del $(TARGETDIR)\COMProvider.lib
if exist $(TARGETDIR)\COMProvider.ilk del $(TARGETDIR)\COMProvider.ilk
!endif
$(INTDIR)RPCProvider.obj : RPCProvider.cpp \
$(JNIHeader)
$(CPP) $(CPP_PROJ) $(JNI_INCLUDE) RPCProvider.cpp
$(JNIHeader) : RPCProvider.java
javah -classpath $(MAKECLASSPATH) \
-jni $(COMProviderPackage).RPCProvider
RPCProvider.class : RPCProvider.java
javac $(JDEBUG) $*.java
clean :
if exist $(TARGETDIR)\COMProvider.dll del $(TARGETDIR)\COMProvider.dll
if exist $(JNIHeader) erase $(JNIHeader)
-for %x in (*.dll) do erase %x
-for %x in (*.ilk) do erase %x
-for %x in (*.pdb) do erase %x
-for %x in (*.class) do erase %x
-for %x in (*.idb) do erase %x
-for %x in (*.obj) do erase %x
#ENDOF MAKEFILE
1.1 xml-soap/java/src/org/apache/soap/providers/com/RPCProvider.cpp
Index: RPCProvider.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* 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 end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* 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 APACHE SOFTWARE FOUNDATION 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#pragma warning(disable:4786) /*Very annoying warning that symbol exceeds debug info size*/
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <iostream>
#include <deque>
#include <string>
#include <cassert>
#include <new>
#include <new.h>
#include <algorithm>
#include <jni.h>
#include <process.h>
#include <windows.h>
#include "RPCProvider.h"
using namespace std;
HRESULT variant2object (JNIEnv *jenv, const VARIANT &var, jobject &ret, bool *localRefCreated= NULL);
wchar_t ModuleName[MAX_PATH *2 ]={0};
HANDLE thisModule;
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID fImpLoad)
{
if(fdwReason == DLL_PROCESS_ATTACH)
{
thisModule= hinstDll;
GetModuleFileName( hinstDll, ModuleName, sizeof ModuleName);
}
return true;
}
void dumpVariant( VARIANT &v)
{
switch( v.vt)
{
case VT_I4 :
fwprintf(stderr, L"Integer: %d\n", v.lVal);
break;
case VT_BSTR :
fwprintf(stderr, L"BStr: %s\n", v.bstrVal);
break;
case VT_BOOL:
fwprintf(stderr, L"Boolean: %d\n", v.boolVal);
break;
}
}
/*These can someday go into a msg resource file for NLS translation */
int msgCLSID2stringfailed= (int) L"Failed to convert string to clsid hr= 0x%1!lx!";
int msgNoParms= (int) L"The number of parameters I got is: %1!u!";
int msgComInitfailed= (int) L"COM Initialize failed hr= 0x%1!lx!";
int msgCLSIDnMethod= (int) L"CLSID is:%1, method to execute is:%2";
int msgPROGIDnMethod=(int) L"Progid is:%1, method to execute is:%2";
int msgPROGID2CLSID=(int) L"Failed to convert progid to clsid hr= 0x%1!lx!";
int msgFailedCoCreate=(int) L"Failed to create instance and interface IID_Dispatch hr=0x%1!lx!";
int msgFailedGetdipid=(int) L"Failed to get dispid for method %1";
int msgFailedDIInvoke=(int) L"Invoke of method %1 failed. hr=0x%2!lx!";
int msgSuccess=(int) L"Success! Return back to java.";
int msgCoTaskMemAllocFail=(int) L"Insufficient resources CoTaskMemAlloc failed.";
int msgCalledDLL= (int) L"In DLL:%1!s!";
int msgInvokeFailedParms= (int) L"COMProvider: method:%1!s! received error %2!lu!. Error source: %3!ls!\t. Description:%4!s!";
int msgInvokeFailedParms2= (int) L"Bad argument:%1!lu! method %2!ls!. hr=0x%3!lx!";
int msgInvokeFailed= (int) L"Invoke of method %1!s! failed. hr=0x%2!lx!";
int msgUnknowCPPException= (int) L"An unknown CPP exception has occurred";
int msgFailedConvertReturn= (int) L"Failed to convert return parameter, variant type:0x%1!lx!, Object:%2!s!, Method:%3!s!";
int msgFailedMemory= (int) L"Failed to allocate memory!";
const short LOG_INFORMATION = 0x1000;
const short LOG_SUCCESS= 0x100;
const short LOG_WARNING = 0x10;
const short LOG_ERROR = 1;
short eventLevel= LOG_ERROR;
struct Undoit
{
void (__stdcall*coinit )(void);
IDispatch *idisp;
VARIANT *vp;
~Undoit()
{
if (NULL != idisp ) { idisp->Release(); idisp= NULL;}
if (NULL != vp) { CoTaskMemFree(vp); vp= NULL;}
if( NULL != coinit) { coinit(); coinit= NULL ; }
}
};
class COMProvider
{
jobject jPP; //the java pluggable provider
JNIEnv *env;
static const char* javaClass;
public:
COMProvider(JNIEnv *e, jobject jthis):jPP(jthis),env(e){};
WORD getMethodDispatchType( const wchar_t *mname)
{
WORD ret = DISPATCH_METHOD;
if(0 == wcsncmp(L"get_", mname, 4)) ret= DISPATCH_PROPERTYGET;
else if(0 == wcsncmp(L"set_", mname, 4)) ret= DISPATCH_PROPERTYPUT;
return ret;
}
jobject invoke (jstring jthreadingModel, jstring jprogid, jstring jmethodName, jbyteArray parms_in)
{
eventlog(LOG_SUCCESS, msgCalledDLL, ModuleName );
wchar_t progid[256];
Undoit undoit;
ZeroIt(undoit);
jsize noParmsBytes= NULL == parms_in ? 0 : env->GetArrayLength( parms_in);
unsigned noParms= noParmsBytes/ sizeof VARIANT;
eventlog(LOG_SUCCESS, msgNoParms, noParms );
char *x= NULL;
if(noParms)
{
x= (char*)CoTaskMemAlloc( noParmsBytes );
if( NULL == x)
{
throwSoapException( msgCoTaskMemAllocFail );
return NULL;
}
memset(x, 0, noParmsBytes);
jboolean iscopy;
jbyte *jpeer= env->GetByteArrayElements(parms_in, &iscopy);
memcpy(x, jpeer, noParmsBytes);
if(iscopy == JNI_TRUE) env->ReleaseByteArrayElements(parms_in,jpeer,0);
}
// VARIANT *vp= (VARIANT *)x;
undoit.vp= (VARIANT *)x;
/*
for(int i=0; i< noParms; ++i)
{
dumpVariant(vp[i]);
}
*/
DWORD coInit= COINIT_MULTITHREADED; //The default.
bool oleInit= false;
jboolean isCopy;
wchar_t *cstr= (wchar_t *)env->GetStringChars(jthreadingModel, &isCopy);
if(0== wcscmp(cstr, L"MULTITHREADED"))
{ //just
coInit= COINIT_MULTITHREADED; //Just recognize it.
}
else if(0== wcscmp(cstr, L"APARTMENTTHREADED"))
{
coInit= COINIT_APARTMENTTHREADED;
}
else if(0== wcscmp(cstr, L"SINGLEAPARTMENTTHREADED"))
{
oleInit= true;
}
if(isCopy == JNI_TRUE) env->ReleaseStringChars(jthreadingModel, cstr);
HRESULT hr;
if(oleInit)
{
hr= OleInitialize(NULL);
if (ASSERT_FAILED(hr))
{
eventlog(LOG_WARNING, msgComInitfailed, hr);
throwSoapException( msgComInitfailed, hr );
return NULL;
}
undoit.coinit= OleUninitialize; //Ensure we uninitialize.
}
else
{
hr= CoInitializeEx(NULL, coInit);
if (ASSERT_FAILED(hr))
{
eventlog(LOG_WARNING, msgComInitfailed, hr);
throwSoapException( msgComInitfailed, hr );
return NULL;
}
undoit.coinit= CoUninitialize; //Ensure we uninitialize.
}
cstr= (wchar_t *)env->GetStringChars(jmethodName, &isCopy);
wchar_t *methodName= _wcsdup(cstr);
if(isCopy == JNI_TRUE) env->ReleaseStringChars(jmethodName, cstr);
if(!methodName)
{
eventlog(LOG_ERROR, msgFailedMemory);
throwSoapException( msgFailedMemory);
return NULL;
}
CLSID clsid;
cstr= (wchar_t*) env->GetStringChars(jprogid, &isCopy);
if( L'{' == cstr[0]) //clsid is specified as a string
{
hr= CLSIDFromString(cstr, &clsid );
if (ASSERT_FAILED(hr))
{
throwSoapException( msgCLSID2stringfailed, hr );
if(isCopy == JNI_TRUE) env->ReleaseStringChars(jprogid, cstr);
if(methodName) free(methodName);
return NULL;
}
eventlog(LOG_INFORMATION, msgCLSIDnMethod , cstr, methodName);
}
else
{
eventlog(LOG_INFORMATION, msgPROGIDnMethod , cstr, methodName);
hr= CLSIDFromProgID( cstr, &clsid);
if (ASSERT_FAILED(hr))
{
eventlog(LOG_WARNING, msgPROGID2CLSID, hr );
if(isCopy == JNI_TRUE) env->ReleaseStringChars(jprogid, cstr);
throwSoapException( msgPROGID2CLSID, hr );
if(methodName) free(methodName);
return NULL;
}
}
ZeroIt(progid);
wcsncpy(progid, cstr, (sizeof(progid)/(sizeof progid[0]))-1);
if(isCopy == JNI_TRUE) env->ReleaseStringChars(jprogid, cstr);
//Start doing COM stuff
hr= CoCreateInstance( clsid, NULL, CLSCTX_ALL, IID_IDispatch, (void **)&undoit.idisp );
if (ASSERT_FAILED(hr))
{
eventlog(LOG_WARNING, msgFailedCoCreate, hr );
throwSoapException( msgFailedCoCreate, hr);
if(methodName) free(methodName);
return NULL;
}
DISPID dispid;
ZeroIt(dispid);
bool isSet= false;
unsigned nameOffset= 0;
if(0 == wcsncmp(L"get_", methodName, 4)) nameOffset= 4;
else if(0 == wcsncmp(L"set_", methodName, 4)) { nameOffset= 4; isSet= true;}
wchar_t * mname= methodName+ nameOffset;
hr= undoit.idisp->GetIDsOfNames(IID_NULL, &mname, 1, GetUserDefaultLCID(), &dispid);
if (ASSERT_FAILED(hr))
{
eventlog(LOG_WARNING, msgFailedGetdipid, methodName );
throwSoapException(msgFailedGetdipid, methodName );
if(methodName) free(methodName);
return NULL;
}
DISPPARAMS dispparams;
ZeroIt( dispparams);
dispparams.rgvarg= undoit.vp;
dispparams.cArgs= noParms;
DISPID didpp= DISPID_PROPERTYPUT;
if(isSet)
{
dispparams.cNamedArgs= 1 ;
dispparams.rgdispidNamedArgs= &didpp;
}
VARIANT result;
ZeroIt(result);
EXCEPINFO expInfo;
ZeroIt( expInfo);
unsigned parg;
ZeroIt( parg);
hr= undoit.idisp->Invoke(dispid, IID_NULL, GetUserDefaultLCID(), getMethodDispatchType(methodName), &dispparams, &result, &expInfo, &parg);
if(hr == DISP_E_EXCEPTION )
{
unsigned long err= (unsigned long) expInfo.wCode;
if (err == 0l) err= (unsigned long) expInfo.scode;
wchar_t *source= expInfo.bstrSource ? expInfo.bstrSource : L"";
wchar_t *desc= expInfo.bstrDescription ? expInfo.bstrDescription : L"";
throwSoapException(msgInvokeFailedParms,methodName, err, source, desc);
if(methodName) free(methodName);
return NULL;
}
if (ASSERT_FAILED(hr))
{
if(hr == DISP_E_TYPEMISMATCH || hr == DISP_E_PARAMNOTFOUND)
{
throwSoapException(msgInvokeFailedParms2, noParms- parg , methodName, hr );
if(methodName) free(methodName);
return NULL;
}
eventlog(LOG_WARNING, msgFailedDIInvoke, methodName,hr );
throwSoapException(msgInvokeFailed , methodName, hr);
if(methodName) free(methodName);
return NULL;
}
jobject jresult= NULL;
hr= variant2object (env, result, jresult);
if (ASSERT_FAILED(hr))
{
eventlog(LOG_ERROR, msgFailedConvertReturn, V_VT (&result), progid, methodName);
throwSoapException(msgFailedConvertReturn, V_VT (&result), progid, methodName);
if(methodName) free(methodName);
return NULL;
}
if(methodName) free(methodName);
eventlog(LOG_SUCCESS, msgSuccess );
return jresult;
}
//Throw a Java SOAP Exception.
BOOL throwSoapException( const wchar_t *msg)
{
if(NULL== msg) msg= L"Exception thrown by COMProvider";
jstring jmsg= env->NewStringUTF(ws2mbs(msg));
jclass jcASE= env->FindClass(javaClass);
jmethodID mid= env->GetStaticMethodID(jcASE,"getSOAPException","(Ljava/lang/String;)Lorg/apache/soap/SOAPException;");
jthrowable jt= (jthrowable) env->CallStaticObjectMethod(jcASE,mid, jmsg);
env->Throw(jt);
return true;
}
BOOL throwSoapException( int id, ...)
{
va_list a;
va_start( a, id);
wchar_t *msgbuf= NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_STRING ,
(wchar_t *)id, 0, 3, (wchar_t *) &msgbuf, 10000, &a);
if(NULL== msgbuf || *msgbuf == L'\0') msgbuf= L"Exception thrown by COMProvider";
jstring jmsg= env->NewStringUTF(ws2mbs(msgbuf));
LocalFree( msgbuf );
jclass jcASE= env->FindClass(javaClass);
jmethodID mid= env->GetStaticMethodID(jcASE,"getSOAPException","(Ljava/lang/String;)Lorg/apache/soap/SOAPException;");
jthrowable jt= (jthrowable) env->CallStaticObjectMethod(jcASE,mid, jmsg);
env->Throw(jt);
env->DeleteLocalRef(jmsg);
return true;
}
BOOL eventlog(short eventtype, int id, ...)
{
if( (eventtype & eventLevel) == 0 ) return false;
va_list a;
va_start( a, id);
wchar_t *msgbuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_STRING,
(wchar_t *)id, 0, 3, (wchar_t *) &msgbuf, 10000, &a);
// fwprintf( stderr, L"%s\n", msgbuf);
jclass spClass= env->GetObjectClass(jPP);
jstring jmsg= env->NewStringUTF(ws2mbs(msgbuf));
jmethodID mid= env->GetMethodID(spClass, "logit", "(ILjava/lang/String;)V");
env->CallVoidMethod(jPP, mid, (jint)eventtype, jmsg);
env->DeleteLocalRef(jmsg);
LocalFree( msgbuf );
return true;
}
};//class COMProvider
const char* COMProvider::javaClass= "org/apache/soap/providers/com/RPCProvider";
extern "C" JNIEXPORT jobject JNICALL Java_org_apache_soap_providers_com_RPCProvider_invoke
(JNIEnv *env, jobject jo, jstring threadingModel, jstring jprogid, jstring jmethodName, jbyteArray parms_in)
{
CRTDBGBRK
COMProvider cp(env, jo);
#ifdef NDEBUG //This also will to debug on demand so if we are debugging don't do the catch.
try
{
#endif
env->ExceptionClear(); //Ignore all previous errors.
return cp.invoke(threadingModel, jprogid, jmethodName, parms_in);
#ifdef NDEBUG
}
catch( ... )
{ //Main point here is not to trap the JVM!
env->ExceptionClear(); //Ignore all previous errors.
cp.throwSoapException( msgUnknowCPPException);
return NULL;
}
#endif
}
extern "C" JNIEXPORT void JNICALL Java_org_apache_soap_providers_com_RPCProvider_initlog(JNIEnv *env, jclass jc, jshort jlvl)
{
eventLevel= jlvl;
}
extern "C" JNIEXPORT jbyteArray JNICALL Java_org_apache_soap_providers_com_RPCProvider_nativeConvertToBString(JNIEnv *env, jclass jc, jstring s)
{
env->ExceptionClear(); //Let a calling thread to invoke a call record the error.
jboolean isCopy;
const wchar_t * cs= env->GetStringChars(s, &isCopy);
BSTR bstrS=SysAllocString(cs);
if(isCopy == JNI_TRUE) env->ReleaseStringChars(s, cs);
jbyteArray jByteArray= env->NewByteArray(sizeof bstrS);
jbyte *jr= env->GetByteArrayElements(jByteArray, &isCopy);
void *x =bstrS;
memcpy(jr, &x, sizeof x);
if(isCopy == JNI_TRUE) env->ReleaseByteArrayElements(jByteArray,jr,0);
return jByteArray;
}
/* make objects from primitives */
jobject bsf_makeBoolean (JNIEnv *jenv, int val) {
jclass classobj = jenv->FindClass ( "java/lang/Boolean");
jmethodID constructor =
jenv->GetMethodID (classobj, "<init>", "(Z)V");
return jenv->NewObject (classobj, constructor, (jboolean) val);
}
jobject bsf_makeByte (JNIEnv *jenv, int val) {
jclass classobj = jenv->FindClass ( "java/lang/Byte");
jmethodID constructor =
jenv->GetMethodID ( classobj, "<init>", "(B)V");
return jenv->NewObject ( classobj, constructor, (jbyte) val);
}
jobject bsf_makeShort (JNIEnv *jenv, int val) {
jclass classobj = jenv->FindClass ( "java/lang/Short");
jmethodID constructor =
jenv->GetMethodID ( classobj, "<init>", "(S)V");
return jenv->NewObject ( classobj, constructor, (jshort) val);
}
jobject bsf_makeInteger (JNIEnv *jenv, int val) {
jclass classobj = jenv->FindClass ( "java/lang/Integer");
jmethodID constructor =
jenv->GetMethodID ( classobj, "<init>", "(I)V");
return jenv->NewObject ( classobj, constructor, (jint) val);
}
jobject bsf_makeLong (JNIEnv *jenv, long val) {
jclass classobj = jenv->FindClass ( "java/lang/Long");
jmethodID constructor =
jenv->GetMethodID ( classobj, "<init>", "(J)V");
return jenv->NewObject ( classobj, constructor, (jlong) val);
}
jobject bsf_makeFloat (JNIEnv *jenv, float val) {
jclass classobj = jenv->FindClass ( "java/lang/Float");
jmethodID constructor =
jenv->GetMethodID ( classobj, "<init>", "(F)V");
return jenv->NewObject ( classobj, constructor, (jfloat) val);
}
jobject bsf_makeDouble (JNIEnv *jenv, double val) {
jclass classobj = jenv->FindClass ( "java/lang/Double");
jmethodID constructor =
jenv->GetMethodID ( classobj, "<init>", "(D)V");
return jenv->NewObject ( classobj, constructor, (jdouble) val);
}
HRESULT variant2object (JNIEnv *jenv, const VARIANT &var, jobject &jresult, bool *localRefCreated)
{
HRESULT result = S_OK;
char *buf= NULL;
if(localRefCreated) *localRefCreated= true; //this is mostly the case.
switch (V_VT (&var)) {
case VT_ERROR:
case VT_EMPTY:
case VT_NULL:
if(localRefCreated) *localRefCreated= false;
jresult = NULL;
break;
case VT_I1:
jresult = bsf_makeByte (jenv, (int) V_I1 (&var));
break;
case VT_I2:
jresult = bsf_makeShort (jenv, (int) V_I2 (&var));
break;
case VT_I4:
jresult = bsf_makeInteger (jenv, (int) V_I4 (&var));
break;
case VT_I8:
/* where's V_I8??? */
jresult = bsf_makeLong (jenv, (long) V_I4 (&var));
break;
case VT_R4:
jresult = bsf_makeFloat (jenv, (float) V_R4 (&var));
break;
case VT_R8:
jresult = bsf_makeDouble (jenv, (double) V_R8 (&var));
break;
case VT_BSTR:
/* if its a string with the right stuff, retract the object */
buf= ws2mbs(var.bstrVal);
jresult = jenv->NewStringUTF (buf);
break;
case VT_BOOL:
jresult = bsf_makeBoolean (jenv, (int) V_BOOL (&var));
break;
case VT_VARIANT:
result = variant2object (jenv, *(V_VARIANTREF (&var)), jresult, localRefCreated);
break;
case VT_UI1:
jresult = bsf_makeShort (jenv, (int) V_UI1 (&var));
break;
case VT_UI2:
jresult = bsf_makeInteger (jenv, (int) V_UI2 (&var));
break;
case VT_UI4:
jresult = bsf_makeLong (jenv, (long) V_UI4 (&var));
break;
case VT_UI8:
/* where's V_UI8??? */
jresult = bsf_makeLong (jenv, (long) V_UI4 (&var));
break;
case VT_INT:
jresult = bsf_makeInteger (jenv, V_INT (&var));
break;
case VT_UINT:
jresult = bsf_makeLong (jenv, (long) V_UINT (&var));
break;
default:
if (V_ISBYREF (&var))
{
if((var.vt & (VT_BYREF|VT_ARRAY)) == (VT_BYREF|VT_ARRAY))
{ //It is an array by reference.
result= DISP_E_BADVARTYPE; //rrfoo can support needs work.
/*
//var.vt&= (~VT_BYREF);
VARIANT arraybyref;
ZeroIt(arraybyref);
arraybyref.vt = VT_ARRAY;
arraybyref.parray= *var.pparray;
result= variant2object(jenv, arraybyref, jresult localRefCreated);
*/
}
else
{ //This is a reference ... dereference.
result = variant2object (jenv, *((VARIANT *)var.byref), jresult, localRefCreated);
}
}
else
{
result= DISP_E_BADVARTYPE;
break;
}
} //endswitch to variant.
if(!jresult && localRefCreated) *localRefCreated= false;
return result;
}
1.1 xml-soap/java/src/org/apache/soap/providers/com/RPCProvider.h
Index: RPCProvider.h
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* 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 end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* 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 APACHE SOFTWARE FOUNDATION 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#if !defined I9b76b170db194c3c92c61e375e31a96e
#define I9b76b170db194c3c92c61e375e31a96e
#include <deque>
#include <malloc.h>
#include <exception>
#include <new>
#include <new.h>
#include <windows.h>
#include <jni.h>
#include "dbgutils.h"
#include "org_apache_soap_providers_com_RPCProvider.h"
extern wchar_t ModuleName[MAX_PATH *2 ];
extern HANDLE thisModule;
inline wchar_t *mbs2wsConvert(const char *s, void *d)
{
size_t size= strlen(s);
if(d && !size) *(wchar_t *)d= L'\0';
if(d && size)
{
((wchar_t *)d)[MultiByteToWideChar(
CP_ACP, // code page
MB_COMPOSITE, // character-type options
s, // address of string to map
size, // number of bytes in string
(wchar_t *)d, // address of wide-character buffer
((size<<1)+1) // size of buffer
)
]= L'\0';
}
return (wchar_t *) d;
}
#define mbs2ws(s) (mbs2wsConvert((s), _alloca( (2+strlen((const char *)(s)))<<1)))
inline LPOLESTR mbs2LPOLESTR(const char *s)
{
wchar_t *ws= mbs2ws(s);
if(ws)
{
return _wcsdup(ws);
}
return NULL;
}
inline LPOLESTR mbs2LPOLESTR(const std::string &s)
{
return mbs2LPOLESTR( s.c_str());
}
inline char *ws2mbsConvert(const wchar_t *s, void *d)
{
size_t size= wcslen(s); //It maybe the same size as the widechar string
if(!size && d) *((char*)d)= '\0';
if(d && size){((char *)d)[WideCharToMultiByte
(
CP_ACP, // code page
WC_COMPOSITECHECK, // character-type options
s, // address of string to map
size, // number of chars in string
(char *)d, // address of mbs-character buffer
size<<1, // size of buffer in bytes , //Use system default character.
NULL,
NULL
)
]= L'\0';
}
return (char *) d;
}
#define ws2mbs(s) (ws2mbsConvert((s), _alloca( ((2+(wcslen((const wchar_t *)(s))<<1))))))
template<class T> inline void ZeroIt(T &t){ memset(&t, 0, sizeof t);};
#endif /*I9b76b170-db19-4c3c-92c6-1e375e31a96e */
1.1 xml-soap/java/src/org/apache/soap/providers/com/RPCProvider.java
Index: RPCProvider.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* 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 end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* 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 APACHE SOFTWARE FOUNDATION 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.soap.providers.com;
import java.io.* ;
import java.util.* ;
import java.text.MessageFormat;
import javax.servlet.* ;
import javax.servlet.http.* ;
import org.apache.soap.* ;
import org.apache.soap.rpc.* ;
import org.apache.soap.server.* ;
import org.apache.soap.util.* ;
import java.lang.Math;
public class RPCProvider implements Provider
{
private DeploymentDescriptor dd ;
private Envelope envelope ;
private Call call ;
private String methodName ;
private String targetObjectURI ;
private HttpServlet servlet ;
private HttpSession session ;
private byte[] vp= null;
private String progid= null;
private ServletContext sc= null;
private String threadingModel= null;
private static boolean initLog= false;
public void locate( DeploymentDescriptor dd,
Envelope env,
Call call,
String methodName,
String targetObjectURI,
SOAPContext reqContext)
throws SOAPException
{
HttpServlet servlet = (HttpServlet) reqContext.getProperty( Constants.BAG_HTTPSERVLET );
HttpSession session = (HttpSession) reqContext.getProperty( Constants.BAG_HTTPSESSION );
sc= servlet.getServletConfig().getServletContext();
if(!initLog)
{
Log.init(servlet);
initlog(Log.getLevel());
initLog=true;
}
Log.msg(Log.SUCCESS, "msg.comprovider.inlocate", getClass().getName(), targetObjectURI, methodName );
if( null != dllLoadException)
{
Log.msg(Log.ERROR, "msg.comprovider.dllfail", dllLoadException );
throw dllLoadException;
}
//This validates that the method name is listed in the deployment descriptor.
if (!MessageRouter.validMessage (dd, methodName)) {
String msg=
Log.msg(Log.ERROR, "msg.comprovider.badMethod", targetObjectURI, methodName);
throw new SOAPException (Constants.FAULT_CODE_SERVER, msg);
}
Vector parms= call.getParams();
int noParms= 0;
if(parms != null)
{
vp= new byte[sizeOfVariant * parms.size()];
noParms= parms.size();
}
for(int i=0; i < noParms; ++i)
{
Log.msg(Log.INFORMATION, "msg.comprovider.info.parms", new Integer(i), parms.elementAt(i).getClass().getName(), parms.elementAt(i).toString());
//Yes. Prameters are reversed here.
objectToVariant( ((Parameter)(parms.elementAt(noParms - i -1))).getValue(), vp, i * sizeOfVariant);
}
Hashtable props = dd.getProps();
progid= (String) props.get("progid");
if(null== progid)
{
if(targetObjectURI.startsWith("urn:"))
{
progid= targetObjectURI.substring(4);
}
else
progid= targetObjectURI;
}
threadingModel= (String) props.get("threadmodel");
if( null == threadingModel) threadingModel= "MULTITHREADED";
Log.msg(Log.INFORMATION, "msg.comprovider.info.cominf", progid, threadingModel );
this.dd = dd ;
this.envelope = env ;
this.call = call ;
this.methodName = methodName ;
this.targetObjectURI = targetObjectURI ;
this.servlet = servlet ;
this.session = session ;
// Add logic to locate/load the service here
} //Endof of locate
public void invoke(SOAPContext reqContext, SOAPContext resContext)
throws SOAPException
{
if( null != dllLoadException)
{
Log.msg(Log.ERROR, "msg.comprovider.dllfail", dllLoadException );
throw dllLoadException;
}
if( null == progid)
{
String msg= Log.msg(Log.ERROR, "msg.comprovider.error.nullprog", methodName, targetObjectURI);
throw new SOAPException( Constants.FAULT_CODE_SERVER, msg);
}
if( null == methodName)
{
String msg= Log.msg(Log.ERROR, "msg.comprovider.error.nullmname", targetObjectURI);
throw new SOAPException( Constants.FAULT_CODE_SERVER, msg);
}
// If you want the client to use a new targetObjectURI for subsequence
// calls place it here (targetObjectURI on 'new Response').
// i.e. we added an 'instance-id' to the urn
Object ret= null;
try{
ret= invoke( threadingModel, progid, methodName, vp);
}catch( Exception e)
{
String msg= Log.msg(Log.ERROR, "msg.comprovider.error.nativeError", e.toString());
throw new SOAPException( Constants.FAULT_CODE_SERVER, msg);
}
try {
Parameter pret= null;
if(ret != null) pret= new Parameter(RPCConstants.ELEM_RETURN , ret.getClass(), ret, null);
vp=null; //dereference.
Response resp = new Response( targetObjectURI, // URI
call.getMethodName(), // Method
pret, // ReturnValue
null, // Params
null, // Header
call.getEncodingStyleURI (), // encoding
resContext ); // response soapcontext - not supported yet
Envelope env = resp.buildEnvelope();
StringWriter sw = new StringWriter();
env.marshall( sw, call.getSOAPMappingRegistry(), resContext );
resContext.setRootPart( sw.toString(), Constants.HEADERVAL_CONTENT_TYPE_UTF8);
}
catch( Exception e ) {
String msg= Log.msg(Log.ERROR, "msg.comprovider.error.exp", e.toString());
if ( e instanceof SOAPException ) throw (SOAPException ) e ;
throw new SOAPException( Constants.FAULT_CODE_SERVER, msg );
}
Log.msg(Log.SUCCESS, "msg.comprovider.ok", ret == null ? "*null*" : ret.toString() );
} //invoke
/* JNI Code ---------------------------------------------------------------------------------------------------------------------------------------- */
static SOAPException dllLoadException= null; //Can hold an exception on from the loading of the c++ dll.
static final String libName= "COMProvider"; //C++ dll name.
protected void logit( int level, String msg) //Called by CPP
{
Log.msg(level, msg);
}
static final String pname= "org.apache.soap.providers.com";
static final String cname= pname + ".RPCProvider";
static
{
try
{
System.loadLibrary (libName);
}
catch(java.lang.SecurityException e)
{
dllLoadException= new SOAPException(Constants.FAULT_CODE_SERVER, "SecurityException from " + cname + " loading library:" + libName + " " + e.getMessage(),e);
}
catch(java.lang.UnsatisfiedLinkError e)
{
dllLoadException= new SOAPException(Constants.FAULT_CODE_SERVER, "UnsatisfiedLinkError from " + cname + " loading library:" + libName + " " + e.getMessage(),e);
}
} //Endof static
private static SOAPException getSOAPException( String msg)
{
return new SOAPException(Constants.FAULT_CODE_SERVER, msg);
}
private native Object invoke(String threadingModel, String progId, String methodName, byte[] parms) throws SOAPException;
private static native void initlog(short level);
private static native byte[] nativeConvertToBString( String o );
/* Java to CPP Marshalling code. ---------------------------------------------------------------------------------------------------------------------------------------- */
private static final int sizeOfVariant= 16;
private final byte[] objectToVariant( Object o ) throws SOAPException
{
return objectToVariant( o, null, 0);
}
private final byte[] objectsToVariants( Object[] o ) throws SOAPException
{
byte[] bo= new byte[ o.length * sizeOfVariant];
for(int i=0; i < o.length; ++i)
objectToVariant( o[i], bo, i * sizeOfVariant);
return bo;
}
private final byte[] objectToVariant( Object o, byte[] bo, int os) throws SOAPException
{
byte[] v= bo;
if( null == v)
{
v= new byte[sizeOfVariant]; //Size of a variant
os=0;
}
if( null== o)
{ //to be safe.
v[os+0] = 1; //VT_NULL
v[os+1] = 0;
}
else if(o instanceof java.lang.Boolean) //VT_R8
{
v[os+0] = 11; //VT_BOOL
v[os+1] = 0;
byte x= (byte)( (((Boolean) o).booleanValue()) ? 0xff: 0);
v[os+8]= x;
v[os+9]= x;
v[os+10]= x;
v[os+11]= x;
}
else if(o instanceof java.lang.Integer) //VT_R8
{
v[os+0] = 3; //VT_I4
v[os+1] = 0;
int x= ((Integer)o).intValue();
v[os+8]= (byte)x;
v[os+9]= (byte)((x>>>8) & 0xff);
v[os+10]= (byte)((x>>>16) & 0xff);
v[os+11]= (byte)((x>>>24) & 0xff);
}
else if( o instanceof java.lang.String)
{
v[os+0] = 8; //VT_BSTR
v[os+1] = 0;
byte[] pbs= nativeConvertToBString( (String) o );
v[os+8]= pbs[0];
v[os+9]= pbs[1];
v[os+10]= pbs[2];
v[os+11]= pbs[3];
}
else if(o instanceof java.lang.Long) //VT_R8
{ //COM has no long type so promote it to double which can contain it.
v[os+0] = 5; //VT_R8
v[os+1] = 0;
long x= Double.doubleToLongBits((double)(((Long)o).longValue()));
v[os+8]= (byte)x;
v[os+9]= (byte)((x>>>8) & 0xff);
v[os+10]= (byte)((x>>>16) & 0xff);
v[os+11]= (byte)((x>>>24) & 0xff);
v[os+12]= (byte)((x>>>32) & 0xff);
v[os+13]= (byte)((x>>>40) & 0xff);
v[os+14]= (byte)((x>>>48) & 0xff);
v[os+15]= (byte)((x>>>56) & 0xff);
}
else if(o instanceof java.lang.Short)
{
v[os+0] = 2; //VT_I2
v[os+1] = 0;
int x= ((Short)o).intValue();
v[os+8]= (byte)x;
v[os+9]= (byte)((x>>>8) & 0xff);
v[os+10]= (byte)((x>>>16) & 0xff);
v[os+11]= (byte)((x>>>24) & 0xff);
}
else if(o instanceof java.lang.Float)
{
v[os+0] = 4; //VT_R4
v[os+1] = 0;
int x= Float.floatToIntBits(((Float)o).floatValue());
v[os+8]= (byte)x;
v[os+9]= (byte)((x>>>8) & 0xff);
v[os+10]= (byte)((x>>>16) & 0xff);
v[os+11]= (byte)((x>>>24) & 0xff);
}
else if(o instanceof java.lang.Double) //VT_R8
{
v[os+0] = 5; //VT_R8
v[os+1] = 0;
long x= Double.doubleToLongBits(((Double)o).doubleValue());
v[os+8]= (byte)x;
v[os+9]= (byte)((x>>>8) & 0xff);
v[os+10]= (byte)((x>>>16) & 0xff);
v[os+11]= (byte)((x>>>24) & 0xff);
v[os+12]= (byte)((x>>>32) & 0xff);
v[os+13]= (byte)((x>>>40) & 0xff);
v[os+14]= (byte)((x>>>48) & 0xff);
v[os+15]= (byte)((x>>>56) & 0xff);
}
else if(o instanceof java.lang.Byte)
{
v[os+0] = 17; //VT_UI1
v[os+1] = 0;
byte x= ((Byte)o).byteValue();
v[os+8]= x;
}
else if(o instanceof java.lang.Character)
{
v[os+0] = 17; //VT_UI1
v[os+1] = 0;
byte x= (byte) ((Character)o).charValue();
v[os+8]= x;
}
else if(o instanceof java.lang.Void)
{
v[os+0] = 1; //VT_NULL
v[os+1] = 0;
}
else if( o.getClass().isArray())
{
// ArrayInfo ai= new ArrayInfo(o);
// v= ai.toVariant();
throw new SOAPException(Constants.FAULT_CODE_SERVER, "Currently arrays are unsupported, type received:" + o.getClass().getName());
}
else
{
throw new SOAPException(Constants.FAULT_CODE_SERVER, "Currently unsupported data type received:" + o.getClass().getName());
/*
// v[os+0] = 9; //VT_DISPATCH for object
// v[os+1] = 0;
byte[] cppref= null;
if(o instanceof )
{
// System.arraycopy(cppref,0,v,8, cppref.length);
}
else if(o ) //Specific request to return back empty
{
v[os+0] = 0; //VT_EMPTY
v[os+1] = 0;
}
else
{
// cppref= nativeObjectToVariant(o);
System.arraycopy(cppref,0,v,8, cppref.length);
}
*/
}
return v;
}
} //Endof RPCProvider
1.1 xml-soap/java/src/org/apache/soap/providers/com/dbgutils.h
Index: dbgutils.h
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* 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 end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* 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 APACHE SOFTWARE FOUNDATION 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#ifndef __DBGUTLSH_INCLUDED__
#define __DBGUTLSH_INCLUDED__
#if !defined(NDEBUG)
#include <CRTDBG.H>
#define CRTDBGBRK {if(getenv("CRTDBGBRK")){ _CrtDbgBreak();}}
#else
#define CRTDBGBRK
#endif
#if defined(FAILED)
#include <cassert>
#if defined(NDEBUG)
#define ASSERT_FAILED FAILED
#else
#define ASSERT_FAILED(S) ( (true == FAILED((S))) ?((bool) (assert(0),true)) : false)
#endif
#endif
#endif //__DBGUTLSH_INCLUDED__