Forums de discussion

Unresolved requirement: Import-Package: org.apache.http in Liferay 7

Thirumal Reddy, modifié il y a 7 années.

Unresolved requirement: Import-Package: org.apache.http in Liferay 7

Regular Member Publications: 216 Date d'inscription: 03/12/15 Publications récentes
Hi guys,
I created one module.In that module I implemented one webservices related java class.
Implementation file
package com.liferay.login.web.portlet.action;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCookieStore;
/*import org.apache.http.impl.client.DefaultHttpClient;*/
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import com.liferay.portal.kernel.util.StringUtil;
import com.vidyayug.global.service.DeploymentConfigLocalServiceUtil;
public class SakaiWSEntityProviderUtil {
public static String getWebservice(String webserviceURL, HttpContext httpContext) throws IOException {
@SuppressWarnings("deprecation")
/*HttpClient httpClient = new DefaultHttpClient();*/
HttpClient httpClient = HttpClientBuilder.create().build();

HttpGet httpGet = new HttpGet(webserviceURL);
HttpResponse response = httpClient.execute(httpGet, httpContext);
String responseData = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
return responseData;
}
public static HttpContext loginWebService(String webserviceURL, List<NameValuePair> params ) throws IOException{
/*HttpClient httpClient = new DefaultHttpClient();*/
HttpClient httpClient = HttpClientBuilder.create().build();
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
HttpPost postRequest = new HttpPost(
webserviceURL);
postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded");
postRequest.setEntity(new UrlEncodedFormEntity(params,"utf-8"));
HttpResponse response = httpClient.execute(postRequest, httpContext);
int status = response.getStatusLine().getStatusCode();
//System.out.println(status);
if(status!=201)
return null;
return httpContext;
}
public static String postWebService(String webserviceURL, List<NameValuePair> params, HttpContext httpContext ) throws IOException, URISyntaxException{
/*HttpClient httpClient = new DefaultHttpClient();*/
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost(
webserviceURL);
postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded");
postRequest.setEntity(new UrlEncodedFormEntity(params,"utf-8"));
HttpResponse response = httpClient.execute(postRequest, httpContext);
String responseData = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
return responseData;
}
public static String putWebService(String webserviceURL, List<NameValuePair> params, HttpContext httpContext)
throws IOException {
/*HttpClient httpClient = new DefaultHttpClient();*/
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPut putRequest = new HttpPut(
webserviceURL);
putRequest.setHeader("Content-Type", "application/x-www-form-urlencoded");
putRequest.setEntity(new UrlEncodedFormEntity(params,"utf-8"));
HttpResponse response = httpClient.execute(putRequest, httpContext);
String responseData = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
return responseData;
}

public static boolean updateTimeZone(String userId, String timezoneId){
try {
String sakaiPortalURL= DeploymentConfigLocalServiceUtil.getsakaiPortalURL();
//check user exists or not
String checkUserExistsURL = StringUtil.replace(CHECK_USER_EXISTS_URL, new String[] { "[$PORTAL_URL$]","[$USER_ID$]"},
new String[] { sakaiPortalURL, userId});

String response =SakaiWSEntityProviderUtil.getWebservice(checkUserExistsURL,null );
if(response.length()!=0){
System.out.println("User doesn't exists in Sakai."+userId);
return false;
}
String sakaiAdminUserId = DeploymentConfigLocalServiceUtil.getSakaiAdminUserName();
String sakaiAdminPassword = DeploymentConfigLocalServiceUtil.getSakaiAdminPassword();
List<NameValuePair> loginParams = new ArrayList<NameValuePair>();
loginParams.add(new BasicNameValuePair("_username", sakaiAdminUserId));
loginParams.add(new BasicNameValuePair("_password", sakaiAdminPassword));
String getUserSessionURL = StringUtil.replace(GET_USER_SESSION_URL, new String[] { "[$PORTAL_URL$]"},
new String[] { sakaiPortalURL});
HttpContext httpContext = SakaiWSEntityProviderUtil.loginWebService(getUserSessionURL,loginParams );
if(httpContext!=null){
String updateUserTZURL = StringUtil.replace(UPDATE_USER_TIME_ZONE_URL, new String[] { "[$PORTAL_URL$]","[$USER_ID$]","[$TIME_ZONE_ID$]"},
new String[] { sakaiPortalURL, userId, timezoneId});
List<NameValuePair> tzParams = new ArrayList<NameValuePair>();
SakaiWSEntityProviderUtil.putWebService(updateUserTZURL,tzParams,httpContext );

return true;
}else{
System.out.println("Can't obtain sakai session. Admin credentials might be wrong");
return false;
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Getting exception while interacting with sakai to update user time zone");
return false;
}

}
public static final String CHECK_USER_EXISTS_URL="[$PORTAL_URL$]/direct/user/[$USER_ID$]/exists.json";
public static final String GET_USER_SESSION_URL="[$PORTAL_URL$]/direct/session/new";
public static final String GET_USER_TIME_ZONE_URL="[$PORTAL_URL$]/direct/userPrefs/key/[$USER_ID$]/sakai:time.json";
public static final String UPDATE_USER_TIME_ZONE_URL="[$PORTAL_URL$]/direct/userPrefs/updateKey/[$USER_ID$]/sakai:time?timezone=[$TIME_ZONE_ID$]";
}


build.gradle
dependencies {
compile group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
compile group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
compile group: "com.liferay", name: "com.liferay.login.web", version: "1.0.0"
compile group: "javax.portlet", name: "portlet-api", version: "2.0"
compile group: "javax.servlet", name: "servlet-api", version: "2.5"
compile group: "jstl", name: "jstl", version: "1.2"
compile group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
compile project(":modules:Global:Global-api")
compile project(":modules:CreateFailedUserAccountsInSakai:CreateFailedUserAccountsInSakai-api")
compile 'javax.mail:mail:1.4.7'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'org.ow2.asm', name: 'asm-tree', version: '4.0'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.4'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.4'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.2'
compile group: 'commons-io', name: 'commons-io', version: '2.4'

}


bnd.bnd file
Bundle-SymbolicName: createaccoun.ext
Bundle-Version: 1.0.0
-includeresource:\
lib/axis.jar=axis-*.jar,\
lib/commons-discovery.jar=commons-discovery-*.jar,\
lib/httpclient.jar=httpclient-*.jar,\
lib/httpcore.jar=httpcore-*.jar,\
lib/commons-io.jar=commons-io-*.jar



I deployed this module, I get the build suceess.After that i moved jar into deployed folder.
Here i get the below message:
07:20:12,593 INFO [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:252] Processing createaccoun.ext.jar
07:20:19,703 INFO [fileinstall-D:/liferay7dbupgradation/bundles/osgi/modules][BundleStartStopLogger:38] STOPPED createaccoun.ext_1.0.0 [1054]


After that i tested that bundle in gogo shell it shows the
Unresolved requirement: Import-Package: org.apache.http


Could you please tell the process for resovle this issue.This is great help to me.

Pièces jointes:

thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Unresolved requirement: Import-Package: org.apache.http in Liferay 7

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
There is already a thread on this that is being worked.

Please don't open new threads on the same issue.