67 { |
67 { |
68 |
68 |
69 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
69 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
70 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
70 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
71 try |
71 try |
72 { |
72 { |
73 tran->Dispose(); |
73 tran->Dispose(); |
74 } |
74 } |
75 catch(...) |
75 catch (...) |
76 { |
76 { |
77 // function server usage may throw an exception. |
77 // function server usage may throw an exception. |
78 // ignore, called when transcation is closed |
78 // ignore, called when transcation is closed |
79 ELOG(ESOCKET,"Http JNI Error, exception caught!: _closeTransaction"); |
79 ELOG(ESOCKET,"Http JNI Error, exception caught!: _closeTransaction"); |
80 } |
80 } |
81 delete tran; |
81 delete tran; |
82 } |
82 } |
83 |
83 |
84 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1createNativeTransaction( |
84 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1createNativeTransaction( |
85 JNIEnv* aJni, |
85 JNIEnv* aJni, |
86 jobject aPeer, |
86 jobject aPeer, |
87 jint aNativeHttpSession, |
87 jint aNativeHttpSession, |
88 jstring aUri, |
88 jstring aUri, |
89 jstring aRequestMethod) |
89 jstring aRequestMethod) |
90 { |
90 { |
91 LOG(ESOCKET,EInfo,"http jni _createNativeTransaction()"); |
91 LOG(ESOCKET,EInfo,"http jni _createNativeTransaction()"); |
92 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(aNativeHttpSession); |
92 NativeHttpSession* session = reinterpret_cast<NativeHttpSession*>(aNativeHttpSession); |
93 //tran->iJniPeer = aJni->NewGlobalRef(aPeer); |
93 //tran->iJniPeer = aJni->NewGlobalRef(aPeer); |
94 try |
94 try |
95 { |
95 { |
96 TRAPD(handle, handle = session->CreateTransactionL(aJni, aPeer , aUri, aRequestMethod);); |
96 TRAPD(handle, handle = session->CreateTransactionL(aJni, aPeer , aUri, aRequestMethod);); |
97 return handle; |
97 return handle; |
98 } |
98 } |
99 catch(...) |
99 catch (...) |
100 { |
100 { |
101 // function server usage may throw an exception. |
101 // function server usage may throw an exception. |
102 ELOG(ESOCKET,"Http JNI Error, exception caught!: _createTransaction"); |
102 ELOG(ESOCKET,"Http JNI Error, exception caught!: _createTransaction"); |
103 return -1; |
103 return -1; |
104 } |
104 } |
105 |
105 |
106 } |
106 } |
107 |
107 |
108 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1submitTransaction( |
108 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1submitTransaction( |
109 JNIEnv* aJni, |
109 JNIEnv* aJni, |
110 jobject aPeer, |
110 jobject aPeer, |
112 jobjectArray aHeaders, |
112 jobjectArray aHeaders, |
113 jbyteArray aPostData, |
113 jbyteArray aPostData, |
114 jint aPostDataLength, |
114 jint aPostDataLength, |
115 jint aResponseTimeout) |
115 jint aResponseTimeout) |
116 { |
116 { |
117 LOG(ESOCKET,EInfo,"http jni _submitTransaction"); |
117 LOG(ESOCKET,EInfo,"http jni _submitTransaction"); |
118 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
118 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
119 int respTimeOut = aResponseTimeout; |
119 int respTimeOut = aResponseTimeout; |
120 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
120 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
121 try |
121 try |
122 { |
122 { |
123 TRAPD(err,tran->SubmitL(aJni, &aPeer,aHeaders, aPostData, aPostDataLength, respTimeOut)); |
123 TRAPD(err,tran->SubmitL(aJni, &aPeer,aHeaders, aPostData, aPostDataLength, respTimeOut)); |
124 return err; |
124 return err; |
125 } |
125 } |
126 catch(...) |
126 catch (...) |
127 { |
127 { |
128 ELOG(ESOCKET,"Http JNI Error, exception caught!: _submitTransaction"); |
128 ELOG(ESOCKET,"Http JNI Error, exception caught!: _submitTransaction"); |
129 return -1; |
129 return -1; |
130 } |
130 } |
131 } |
131 } |
132 |
132 |
133 JNIEXPORT jobjectArray JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getResponse( |
133 JNIEXPORT jobjectArray JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getResponse( |
134 JNIEnv* aJni, |
134 JNIEnv* aJni, |
135 jobject aPeer, |
135 jobject aPeer, |
136 jint aNativeHttpTransaction) |
136 jint aNativeHttpTransaction) |
137 { |
137 { |
138 LOG(ESOCKET,EInfo,"http jni _getResponse"); |
138 LOG(ESOCKET,EInfo,"http jni _getResponse"); |
139 jobjectArray rawHeaders=NULL; |
139 jobjectArray rawHeaders=NULL; |
140 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
140 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
141 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
141 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
142 try |
142 try |
143 { |
143 { |
144 TRAPD(err, rawHeaders = tran->GetResponseL(aJni)); |
144 TRAPD(err, rawHeaders = tran->GetResponseL(aJni)); |
145 if (err!=KErrNone) |
145 if (err!=KErrNone) |
146 { |
146 { |
147 rawHeaders=NULL; |
147 rawHeaders=NULL; |
148 } |
148 } |
149 } |
149 } |
150 catch(...) |
150 catch (...) |
151 { |
151 { |
152 rawHeaders=NULL; |
152 rawHeaders=NULL; |
153 ELOG(ESOCKET,"Http JNI Error, exception caught!: _getResponse"); |
153 ELOG(ESOCKET,"Http JNI Error, exception caught!: _getResponse"); |
154 |
154 |
155 } |
155 } |
156 return rawHeaders; |
156 return rawHeaders; |
157 } |
157 } |
158 |
158 |
159 |
159 |
160 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getBytes( |
160 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getBytes( |
162 jobject aPeer, |
162 jobject aPeer, |
163 jint aNativeHttpTransaction, |
163 jint aNativeHttpTransaction, |
164 jbyteArray aBytes, |
164 jbyteArray aBytes, |
165 jint aLength) |
165 jint aLength) |
166 { |
166 { |
167 LOG(ESOCKET,EInfo,"http jni _getBytes"); |
167 LOG(ESOCKET,EInfo,"http jni _getBytes"); |
168 jbyte* bytes = aEnv->GetByteArrayElements(aBytes, NULL); |
168 jbyte* bytes = aEnv->GetByteArrayElements(aBytes, NULL); |
169 |
169 |
170 if (bytes == NULL) |
170 if (bytes == NULL) |
171 { |
171 { |
172 return -1; |
172 return -1; |
173 } |
173 } |
174 try |
174 try |
175 { |
175 { |
176 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
176 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
177 tran->iJniPeer = aEnv->NewWeakGlobalRef(aPeer); |
177 tran->iJniPeer = aEnv->NewWeakGlobalRef(aPeer); |
178 TInt length = tran->ReadBytes(reinterpret_cast<TUint8*>(bytes), aLength); |
178 TInt length = tran->ReadBytes(reinterpret_cast<TUint8*>(bytes), aLength); |
179 |
179 |
180 aEnv->ReleaseByteArrayElements(aBytes, bytes, NULL); |
180 aEnv->ReleaseByteArrayElements(aBytes, bytes, NULL); |
181 return length; |
181 return length; |
182 } |
182 } |
183 catch(...) |
183 catch (...) |
184 { |
184 { |
185 ELOG(ESOCKET,"Http JNI Error, exception caught!: _getBytes"); |
185 ELOG(ESOCKET,"Http JNI Error, exception caught!: _getBytes"); |
186 return -1; |
186 return -1; |
187 } |
187 } |
188 } |
188 } |
189 |
189 |
190 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1available( |
190 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1available( |
191 JNIEnv* aJni, |
191 JNIEnv* aJni, |
192 jobject aPeer, |
192 jobject aPeer, |
194 { |
194 { |
195 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
195 NativeHttpTransaction* tran = reinterpret_cast<NativeHttpTransaction*>(aNativeHttpTransaction); |
196 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
196 tran->iJniPeer = aJni->NewWeakGlobalRef(aPeer); |
197 try |
197 try |
198 { |
198 { |
199 return tran->Available(); |
199 return tran->Available(); |
200 } |
200 } |
201 catch(...) |
201 catch (...) |
202 { |
202 { |
203 ELOG(ESOCKET,"Http JNI Error, exception caught!: _available"); |
203 ELOG(ESOCKET,"Http JNI Error, exception caught!: _available"); |
204 return -1; |
204 return -1; |
205 } |
205 } |
206 } |
206 } |
207 |
207 |
208 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getUserAgentHeaderValue( |
208 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_http_HttpConnectionNative__1getUserAgentHeaderValue( |
209 JNIEnv *aJni, |
209 JNIEnv *aJni, |