16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <e32def.h> |
19 #include <e32def.h> |
20 #include <centralrepository.h> |
20 #include <centralrepository.h> |
|
21 |
|
22 #ifdef RD_JAVA_S60_RELEASE_10_1_ONWARDS |
|
23 #include <CUserAgent.h> |
|
24 #else |
21 #include <cuseragent.h> |
25 #include <cuseragent.h> |
|
26 #endif |
|
27 |
22 #include "com_nokia_mj_impl_http_HttpConnectionNative.h" |
28 #include "com_nokia_mj_impl_http_HttpConnectionNative.h" |
23 #include "nativehttptransaction.h" |
29 #include "nativehttptransaction.h" |
24 #include "nativehttpsession.h" |
30 #include "nativehttpsession.h" |
25 #include "monitor.h" |
31 #include "monitor.h" |
26 #include "logger.h" |
32 #include "logger.h" |
52 |
58 |
53 //DEBUGCOMP_INT( KLogFileHttp ,"Java_com_symbian_midp_io_protocol_http_Protocol__1CreateHttpSession: handle = %d", handle ); |
59 //DEBUGCOMP_INT( KLogFileHttp ,"Java_com_symbian_midp_io_protocol_http_Protocol__1CreateHttpSession: handle = %d", handle ); |
54 return handle; |
60 return handle; |
55 } |
61 } |
56 |
62 |
57 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1dispose( |
|
58 JNIEnv*, |
|
59 jobject, |
|
60 jint aNativeHttpSessionHandle) |
|
61 { |
|
62 LOG(ESOCKET,EInfo,"http jni _dispose()"); |
|
63 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(aNativeHttpSessionHandle); |
|
64 delete session; |
|
65 } |
|
66 |
|
67 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1closeTransaction( |
63 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1closeTransaction( |
68 JNIEnv* aJni, |
64 JNIEnv* aJni, |
69 jobject aPeer, |
65 jobject aPeer, |
70 jint aNativeHttpTransaction) |
66 jint aNativeHttpTransaction) |
71 { |
67 { |
72 |
68 |
73 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
69 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
74 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
70 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
75 |
71 try |
76 tran->Dispose(); |
72 { |
|
73 tran->Dispose(); |
|
74 } |
|
75 catch(...) |
|
76 { |
|
77 // function server usage may throw an exception. |
|
78 // ignore, called when transcation is closed |
|
79 ELOG(ESOCKET,"Http JNI Error, exception caught!: _closeTransaction"); |
|
80 } |
77 delete tran; |
81 delete tran; |
78 } |
82 } |
79 |
83 |
80 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1createNativeTransaction( |
84 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1createNativeTransaction( |
81 JNIEnv* aJni, |
85 JNIEnv* aJni, |
82 jobject aPeer, |
86 jobject aPeer, |
83 jint aNativeHttpSession, |
87 jint aNativeHttpSession, |
84 jstring aUri, |
88 jstring aUri, |
85 jstring aRequestMethod) |
89 jstring aRequestMethod) |
86 { |
90 { |
|
91 LOG(ESOCKET,EInfo,"http jni _createNativeTransaction()"); |
87 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(aNativeHttpSession); |
92 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(aNativeHttpSession); |
88 //tran->iJniPeer = aJni->NewGlobalRef(aPeer); |
93 //tran->iJniPeer = aJni->NewGlobalRef(aPeer); |
89 TRAPD(handle, handle = session->CreateTransactionL(aJni, aPeer , aUri, aRequestMethod);); |
94 try |
90 return handle; |
95 { |
|
96 TRAPD(handle, handle = session->CreateTransactionL(aJni, aPeer , aUri, aRequestMethod);); |
|
97 return handle; |
|
98 } |
|
99 catch(...) |
|
100 { |
|
101 // function server usage may throw an exception. |
|
102 ELOG(ESOCKET,"Http JNI Error, exception caught!: _createTransaction"); |
|
103 return -1; |
|
104 } |
|
105 |
91 } |
106 } |
92 |
107 |
93 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1submitTransaction( |
108 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1submitTransaction( |
94 JNIEnv* aJni, |
109 JNIEnv* aJni, |
95 jobject aPeer, |
110 jobject aPeer, |
97 jobjectArray aHeaders, |
112 jobjectArray aHeaders, |
98 jbyteArray aPostData, |
113 jbyteArray aPostData, |
99 jint aPostDataLength, |
114 jint aPostDataLength, |
100 jint aResponseTimeout) |
115 jint aResponseTimeout) |
101 { |
116 { |
|
117 LOG(ESOCKET,EInfo,"http jni _submitTransaction"); |
102 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
118 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
103 int respTimeOut = aResponseTimeout; |
119 int respTimeOut = aResponseTimeout; |
104 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
120 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
105 TRAPD(err,tran->SubmitL(aJni, &aPeer,aHeaders, aPostData, aPostDataLength, respTimeOut)); |
121 try |
106 return err; |
122 { |
|
123 TRAPD(err,tran->SubmitL(aJni, &aPeer,aHeaders, aPostData, aPostDataLength, respTimeOut)); |
|
124 return err; |
|
125 } |
|
126 catch(...) |
|
127 { |
|
128 ELOG(ESOCKET,"Http JNI Error, exception caught!: _submitTransaction"); |
|
129 return -1; |
|
130 } |
107 } |
131 } |
108 |
132 |
109 JNIEXPORT jobjectArray JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getResponse( |
133 JNIEXPORT jobjectArray JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getResponse( |
110 JNIEnv* aJni, |
134 JNIEnv* aJni, |
111 jobject aPeer, |
135 jobject aPeer, |
112 jint aNativeHttpTransaction) |
136 jint aNativeHttpTransaction) |
113 { |
137 { |
|
138 LOG(ESOCKET,EInfo,"http jni _getResponse"); |
114 jobjectArray rawHeaders=NULL; |
139 jobjectArray rawHeaders=NULL; |
115 // java::util::Monitor *iMonitor2; |
140 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
116 // iMonitor2 = java::util::Monitor::createMonitor(); |
141 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
117 // iMonitor2->wait(); |
142 try |
118 |
143 { |
119 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
144 TRAPD(err, rawHeaders = tran->GetResponseL(aJni)); |
120 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
145 if (err!=KErrNone) |
121 TRAPD(err, rawHeaders = tran->GetResponseL(aJni)); |
146 { |
122 if (err!=KErrNone) |
147 rawHeaders=NULL; |
123 { |
148 } |
124 rawHeaders=NULL; |
149 } |
125 } |
150 catch(...) |
|
151 { |
|
152 rawHeaders=NULL; |
|
153 ELOG(ESOCKET,"Http JNI Error, exception caught!: _getResponse"); |
|
154 |
|
155 } |
126 return rawHeaders; |
156 return rawHeaders; |
127 } |
157 } |
128 |
158 |
129 |
159 |
130 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getBytes( |
160 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getBytes( |
132 jobject aPeer, |
162 jobject aPeer, |
133 jint aNativeHttpTransaction, |
163 jint aNativeHttpTransaction, |
134 jbyteArray aBytes, |
164 jbyteArray aBytes, |
135 jint aLength) |
165 jint aLength) |
136 { |
166 { |
|
167 LOG(ESOCKET,EInfo,"http jni _getBytes"); |
137 jbyte* bytes = aEnv->GetByteArrayElements(aBytes, NULL); |
168 jbyte* bytes = aEnv->GetByteArrayElements(aBytes, NULL); |
138 |
169 |
139 |
|
140 if (bytes == NULL) |
170 if (bytes == NULL) |
141 { |
171 { |
142 return -1; |
172 return -1; |
143 } |
173 } |
144 |
174 try |
145 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
175 { |
146 tran->iJniPeer = aEnv->NewWeakGlobalRef(aPeer); |
176 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
147 TInt length = tran->ReadBytes(reinterpret_cast<TUint8*>(bytes), aLength); |
177 tran->iJniPeer = aEnv->NewWeakGlobalRef(aPeer); |
148 |
178 TInt length = tran->ReadBytes(reinterpret_cast<TUint8*>(bytes), aLength); |
149 aEnv->ReleaseByteArrayElements(aBytes, bytes, NULL); |
179 |
150 return length; |
180 aEnv->ReleaseByteArrayElements(aBytes, bytes, NULL); |
|
181 return length; |
|
182 } |
|
183 catch(...) |
|
184 { |
|
185 ELOG(ESOCKET,"Http JNI Error, exception caught!: _getBytes"); |
|
186 return -1; |
|
187 } |
151 } |
188 } |
152 |
189 |
153 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1available( |
190 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1available( |
154 JNIEnv* aJni, |
191 JNIEnv* aJni, |
155 jobject aPeer, |
192 jobject aPeer, |
156 jint aNativeHttpTransaction) |
193 jint aNativeHttpTransaction) |
157 { |
194 { |
158 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
195 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
159 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
196 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
160 return tran->Available(); |
197 try |
|
198 { |
|
199 return tran->Available(); |
|
200 } |
|
201 catch(...) |
|
202 { |
|
203 ELOG(ESOCKET,"Http JNI Error, exception caught!: _available"); |
|
204 return -1; |
|
205 } |
161 } |
206 } |
162 |
207 |
163 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getUserAgentHeaderValue( |
208 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getUserAgentHeaderValue( |
164 JNIEnv *aJni, |
209 JNIEnv *aJni, |
165 jobject, jboolean aMidpRuntime) |
210 jobject, jboolean aMidpRuntime) |