70 TInt NativeHttpTransaction::NewL(JNIEnv &aJni, jobject aPeer, HttpSessionClient& aSession, |
70 TInt NativeHttpTransaction::NewL(JNIEnv &aJni, jobject aPeer, HttpSessionClient& aSession, |
71 const TDesC* aUri, const TDesC* aRequestMethod,java::util::FunctionServer* aFuncServer) |
71 const TDesC* aUri, const TDesC* aRequestMethod,java::util::FunctionServer* aFuncServer) |
72 { |
72 { |
73 NativeHttpTransaction* self = new(ELeave) NativeHttpTransaction(aSession,aFuncServer); |
73 NativeHttpTransaction* self = new(ELeave) NativeHttpTransaction(aSession,aFuncServer); |
74 |
74 |
75 // Cleanup the event source object if a leave occurs during construction: |
75 |
76 //TConstructor selfCleanup(self, aJni); |
|
77 self->ConstructL(aJni, aPeer, /*aServer, */ aUri, aRequestMethod); |
76 self->ConstructL(aJni, aPeer, /*aServer, */ aUri, aRequestMethod); |
78 |
77 |
79 |
78 |
80 // Pop the cleanup of the object and create a handle: |
79 // Pop the cleanup of the object and create a handle: |
81 return reinterpret_cast<int>(self); //selfCleanup.GetHandle(); |
80 return reinterpret_cast<int>(self); //selfCleanup.GetHandle(); |
84 void NativeHttpTransaction::ConstructL(JNIEnv& aJni, jobject aPeer,/* TJavaEventServer aServer,*/ |
83 void NativeHttpTransaction::ConstructL(JNIEnv& aJni, jobject aPeer,/* TJavaEventServer aServer,*/ |
85 const TDesC* aUri, const TDesC* aRequestMethod) |
84 const TDesC* aUri, const TDesC* aRequestMethod) |
86 { |
85 { |
87 |
86 |
88 |
87 |
89 // iJniPeer = aJni.NewWeakGlobalRef(aPeer); |
|
90 iJniPeer = aJni.NewWeakGlobalRef(aPeer); |
88 iJniPeer = aJni.NewWeakGlobalRef(aPeer); |
91 // CJavaEventSourceBase::ConstructL(aJni, aPeer, aServer); |
89 |
92 //Set up the Java Call Backs HttpConnectionNative |
90 |
93 /* |
|
94 jclass httpNativeClass = aJni.FindClass( "com/nokia/mj/impl/http/HttpConnectionNative" ); |
|
95 if ( httpNativeClass == NULL ) |
|
96 { |
|
97 User::Leave( KErrGeneral ); |
|
98 } |
|
99 iTransactionCallbackMethod = aJni.GetMethodID( httpNativeClass, "transactionSubmitCallback", "(I)V" ); |
|
100 if ( iTransactionCallbackMethod == NULL ) |
|
101 { |
|
102 User::Leave( KErrGeneral ); |
|
103 } |
|
104 |
|
105 iNotifyDataReadyForReadMethod = aJni.GetMethodID( httpNativeClass, "dataReadyForReadCallBack", "(I)V" ); |
|
106 if ( iNotifyDataReadyForReadMethod == NULL ) |
|
107 { |
|
108 User::Leave( KErrGeneral ); |
|
109 } |
|
110 */ |
|
111 // iFuncServer->attachToVm(aJni, aPeer); |
91 // iFuncServer->attachToVm(aJni, aPeer); |
112 int handle = reinterpret_cast<int>(this); |
92 int handle = reinterpret_cast<int>(this); |
113 int urihandle = reinterpret_cast<int>(aUri); |
93 int urihandle = reinterpret_cast<int>(aUri); |
114 int methodhandle = reinterpret_cast<int>(aRequestMethod); |
94 int methodhandle = reinterpret_cast<int>(aRequestMethod); |
115 //open the transaction |
95 //open the transaction |
116 //User::LeaveIfError(ExecuteTrap(&NativeHttpTransaction::ExecuteCreateTransactionL, this , aUri , aRequestMethod)); |
96 |
117 CallMethodL(this, &NativeHttpTransaction::ExecuteCreateTransactionL,handle,urihandle , methodhandle, iFuncServer); |
97 CallMethodL(this, &NativeHttpTransaction::ExecuteCreateTransactionL,handle,urihandle , methodhandle, iFuncServer); |
118 //ExecuteCreateTransactionL( this , aUri , aRequestMethod); |
98 |
119 } |
99 } |
120 |
100 |
121 void NativeHttpTransaction::ExecuteCreateTransactionL(int aSelfhandle, int aUrihandle, int aMethodhandle) |
101 void NativeHttpTransaction::ExecuteCreateTransactionL(int aSelfhandle, int aUrihandle, int aMethodhandle) |
122 { |
102 { |
123 NativeHttpTransaction* aSelf = reinterpret_cast<NativeHttpTransaction*>(aSelfhandle); |
103 NativeHttpTransaction* aSelf = reinterpret_cast<NativeHttpTransaction*>(aSelfhandle); |
186 { |
165 { |
187 delete postBuf; |
166 delete postBuf; |
188 postBuf = NULL; |
167 postBuf = NULL; |
189 } |
168 } |
190 |
169 |
191 // ExecuteSubmitL( this, &rawHeaderArray , postBuf); |
170 |
192 CleanupStack::PopAndDestroy();//rawHeaderArray; |
171 CleanupStack::PopAndDestroy();//rawHeaderArray; |
193 } |
172 } |
194 |
173 |
195 void NativeHttpTransaction::ExecuteSubmitL(int aSelfhandle , int aRawHeadershandle , int aPostBufhandle, int aResponseTimeout) |
174 void NativeHttpTransaction::ExecuteSubmitL(int aSelfhandle , int aRawHeadershandle , int aPostBufhandle, int aResponseTimeout) |
196 { |
175 { |
197 //RPointerArray<HBufC8>* aRawHeaders; |
176 |
198 NativeHttpTransaction *aSelf = reinterpret_cast<NativeHttpTransaction*>(aSelfhandle); |
177 NativeHttpTransaction *aSelf = reinterpret_cast<NativeHttpTransaction*>(aSelfhandle); |
199 RPointerArray<HBufC8>* aRawHeaders = reinterpret_cast<RPointerArray<HBufC8>*>(aRawHeadershandle); |
178 RPointerArray<HBufC8>* aRawHeaders = reinterpret_cast<RPointerArray<HBufC8>*>(aRawHeadershandle); |
200 HBufC8* aPostBuf = reinterpret_cast<HBufC8*>(aPostBufhandle); |
179 HBufC8* aPostBuf = reinterpret_cast<HBufC8*>(aPostBufhandle); |
201 |
180 |
202 aSelf->iTransactionClient->SubmitL(aRawHeaders, aPostBuf, aResponseTimeout); |
181 aSelf->iTransactionClient->SubmitL(aRawHeaders, aPostBuf, aResponseTimeout); |
205 jobjectArray NativeHttpTransaction::GetResponseL(JNIEnv* aJni) |
184 jobjectArray NativeHttpTransaction::GetResponseL(JNIEnv* aJni) |
206 { |
185 { |
207 jobjectArray objArray=NULL; |
186 jobjectArray objArray=NULL; |
208 RPointerArray<HBufC8> rawHeaders(KResponseGranularity); |
187 RPointerArray<HBufC8> rawHeaders(KResponseGranularity); |
209 CleanupStack::PushL(TCleanupItem(CleanUpResetAndDestroy,&rawHeaders)); |
188 CleanupStack::PushL(TCleanupItem(CleanUpResetAndDestroy,&rawHeaders)); |
210 //User::LeaveIfError(ExecuteTrap(&NativeHttpTransaction::ExecuteGetResponseL, this, &rawHeaders)); |
189 |
211 int handle = reinterpret_cast<int>(this); |
190 int handle = reinterpret_cast<int>(this); |
212 |
191 |
213 int arrayhandle = reinterpret_cast<int>(&rawHeaders); |
192 int arrayhandle = reinterpret_cast<int>(&rawHeaders); |
214 CallMethodL(this, &NativeHttpTransaction::ExecuteGetResponseL,handle,arrayhandle , iFuncServer); |
193 CallMethodL(this, &NativeHttpTransaction::ExecuteGetResponseL,handle,arrayhandle , iFuncServer); |
215 //ExecuteGetResponseL( this, &rawHeaders); |
194 |
216 const TInt headerCount = rawHeaders.Count(); |
195 const TInt headerCount = rawHeaders.Count(); |
217 if (headerCount>KErrNone) |
196 if (headerCount>KErrNone) |
218 { |
197 { |
219 jclass stringClass = aJni->FindClass("java/lang/String"); |
198 jclass stringClass = aJni->FindClass("java/lang/String"); |
220 User::LeaveIfNull(stringClass); |
199 User::LeaveIfNull(stringClass); |
251 * or -1 if there is no more data because the end of the stream |
230 * or -1 if there is no more data because the end of the stream |
252 * has been reached. |
231 * has been reached. |
253 */ |
232 */ |
254 TInt NativeHttpTransaction::ReadBytes(TUint8* aBytes, TInt aLength) |
233 TInt NativeHttpTransaction::ReadBytes(TUint8* aBytes, TInt aLength) |
255 { |
234 { |
256 //return Execute(&NativeHttpTransaction::ExecuteReadBytes, this, aBytes , aLength); |
235 |
257 int handle = reinterpret_cast<int>(this); |
236 int handle = reinterpret_cast<int>(this); |
258 int uinthandle = reinterpret_cast<int>(aBytes); |
237 int uinthandle = reinterpret_cast<int>(aBytes); |
259 |
238 |
260 int ret = 0; |
239 int ret = 0; |
261 CallMethod(ret,this, &NativeHttpTransaction::ExecuteReadBytes,handle,uinthandle,aLength,iFuncServer); |
240 CallMethod(ret,this, &NativeHttpTransaction::ExecuteReadBytes,handle,uinthandle,aLength,iFuncServer); |
262 |
241 |
263 return ret; |
242 return ret; |
264 //return ExecuteReadBytes( this, aBytes , aLength); |
243 |
265 } |
244 } |
266 |
245 |
267 TInt NativeHttpTransaction::ExecuteReadBytes(int aSelfhandle, int aByteshandle, TInt aLength) |
246 TInt NativeHttpTransaction::ExecuteReadBytes(int aSelfhandle, int aByteshandle, TInt aLength) |
268 { |
247 { |
269 NativeHttpTransaction *aSelf = reinterpret_cast<NativeHttpTransaction*>(aSelfhandle); |
248 NativeHttpTransaction *aSelf = reinterpret_cast<NativeHttpTransaction*>(aSelfhandle); |
275 |
254 |
276 void NativeHttpTransaction::SubmitComplete(TInt aStatus) |
255 void NativeHttpTransaction::SubmitComplete(TInt aStatus) |
277 { |
256 { |
278 LOG(ESOCKET,EInfo,"+NativeHttpTransaction::SubmitComplete"); |
257 LOG(ESOCKET,EInfo,"+NativeHttpTransaction::SubmitComplete"); |
279 |
258 |
280 // jclass httpNativeClass = NULL; |
259 |
281 // httpNativeClass = iJniObject->FindClass("com/nokia/mj/impl/http/HttpConnectionNative"); |
|
282 // jmethodID iMethodID = NULL; |
|
283 // iMethodID = iJniObject->GetMethodID( httpNativeClass, "transactionSubmitCallback", "(I)V" ); |
|
284 // if ( httpNativeClass == NULL ) |
|
285 // { |
|
286 // LOG(ESOCKET,EInfo,"+httpNativeClass is null"); |
|
287 // } |
|
288 // if ( iMethodID == NULL ) |
|
289 // { |
|
290 // LOG(ESOCKET,EInfo,"+iMethodID is NULL"); |
|
291 // } |
|
292 /* if ( iJniPeer == NULL ) |
|
293 { |
|
294 LOG(ESOCKET,EInfo,"+iJniPeer is null"); |
|
295 }*/ |
|
296 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(iFuncServer); |
260 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(iFuncServer); |
297 session->doSubmitCallback(aStatus,iJniPeer); |
261 session->doSubmitCallback(aStatus,iJniPeer); |
298 |
262 |
299 // PostEvent(new (ELeave) CHttpTransactionEvent(iTransactionCallbackMethod, aStatus ),CJavaEventBase::ENotifyPriority); |
|
300 LOG(ESOCKET,EInfo,"-NativeHttpTransaction::SubmitComplete"); |
263 LOG(ESOCKET,EInfo,"-NativeHttpTransaction::SubmitComplete"); |
301 } |
264 } |
302 |
265 |
303 void NativeHttpTransaction::DataReadyForRead(TInt aStatus) |
266 void NativeHttpTransaction::DataReadyForRead(TInt aStatus) |
304 { |
267 { |
305 LOG(ESOCKET,EInfo,"+NativeHttpTransaction::DataReadyForRead"); |
268 LOG(ESOCKET,EInfo,"+NativeHttpTransaction::DataReadyForRead"); |
306 |
|
307 // jclass httpNativeClass = NULL; |
|
308 // httpNativeClass = iJniObject->FindClass("com/nokia/mj/impl/http/HttpConnectionNative"); |
|
309 // jmethodID iMethodReadCallBackID = NULL; |
|
310 // iMethodReadCallBackID = iJniObject->GetMethodID( httpNativeClass, "dataReadyForReadCallBack", "(I)V" ); |
|
311 // |
|
312 // iFuncServer->mJniEnv->CallVoidMethod(mJavaPeerObject,iMethodReadCallBackID,1); |
|
313 |
269 |
314 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(iFuncServer); |
270 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(iFuncServer); |
315 session->doReadCallback(aStatus,iJniPeer); |
271 session->doReadCallback(aStatus,iJniPeer); |
316 |
272 |
317 //PostEvent(new (ELeave) CHttpTransactionEvent(iNotifyDataReadyForReadMethod, aStatus ),CJavaEventBase::ENotifyPriority); |
|
318 LOG(ESOCKET,EInfo,"-NativeHttpTransaction::DataReadyForRead"); |
273 LOG(ESOCKET,EInfo,"-NativeHttpTransaction::DataReadyForRead"); |
319 } |
274 } |
320 |
275 |
321 void NativeHttpTransaction::ExecuteCloseTransaction(int aSelfhandle) |
276 void NativeHttpTransaction::ExecuteCloseTransaction(int aSelfhandle) |
322 { |
277 { |
325 } |
280 } |
326 |
281 |
327 void NativeHttpTransaction::Dispose() |
282 void NativeHttpTransaction::Dispose() |
328 { |
283 { |
329 LOG(ESOCKET,EInfo,"+NativeHttpTransaction::Dispose()"); |
284 LOG(ESOCKET,EInfo,"+NativeHttpTransaction::Dispose()"); |
330 //iFuncServer->stopServer(); |
|
331 CloseTransaction(); |
285 CloseTransaction(); |
332 delete iTransactionClient; |
286 delete iTransactionClient; |
333 iTransactionClient=NULL; |
287 iTransactionClient=NULL; |
334 // iFuncServer->detachFromVm(); |
|
335 |
288 |
336 LOG(ESOCKET,EInfo,"-NativeHttpTransaction::Dispose()"); |
289 LOG(ESOCKET,EInfo,"-NativeHttpTransaction::Dispose()"); |
337 } |
290 } |
338 |
291 |
339 |
292 |
340 void NativeHttpTransaction::CloseTransaction() |
293 void NativeHttpTransaction::CloseTransaction() |
341 { |
294 { |
342 //ExecuteV(&NativeHttpTransaction::ExecuteCloseTransaction, this); |
|
343 int handle = reinterpret_cast<int>(this); |
295 int handle = reinterpret_cast<int>(this); |
344 CallMethod(this, &NativeHttpTransaction::ExecuteCloseTransaction,handle,iFuncServer); |
296 CallMethod(this, &NativeHttpTransaction::ExecuteCloseTransaction,handle,iFuncServer); |
345 //ExecuteCloseTransaction( this); |
|
346 } |
297 } |
347 |
298 |
348 |
299 |
349 |
300 |
350 OS_EXPORT TInt NativeHttpTransaction::GetSecurityInfo() |
301 OS_EXPORT TInt NativeHttpTransaction::GetSecurityInfo() |