Message Boards

how to refresh module

Scarletake Bwi, modified 2 Years ago.

how to refresh module

Expert Posts: 326 Join Date: 12/20/10 Recent Posts

hi 

i use liferay 7.4.3

i create a api module, and it be use in a mvc-module.

but, my api's log always cannot print out in console. i use liferay-studio to run server up.

private static Log LOGGER = LogFactoryUtil.getLog(MyAPI.class);

even i add log level category in Server Administration.

i found that may because the module not refresh, it still keep in old verion.

sometimes, i change compileOnly to compile in build.gradle, it will refresh to newest verion. 

what is the standard process to deploy after i modify my api?

thank you in advance.

thumbnail
Olaf Kock, modified 2 Years ago.

RE: how to refresh module

Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent Posts

Can you show the full class, or better a minimal full sample with steps to reproduce?

If the problem is related to OSGi classloading, a single line won't help spot the problem.

An approach might be to move the logging out of the API module into an implementation module.

Scarletake Bwi, modified 2 Years ago.

RE: RE: how to refresh module

Expert Posts: 326 Join Date: 12/20/10 Recent Posts

hi Olaf

sure

my class of api module

package com.ci.enosix.api;

import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.raritan.ci.enosix.constant.Constant;
import com.raritan.ci.enosix.vo.VendorContactVO;
import com.raritan.ci.enosix.vo.VendorVO;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

public class EnosixRest {
	private static Log LOGGER = LogFactoryUtil.getLog(EnosixRest.class);

	private HttpPost setPostAuthorization(HttpPost httpPost) {
		httpPost.addHeader("Authorization", Constant.ENCODED_AUTHORIZATION());
		httpPost.addHeader("Content-Type", "text/json");
		return httpPost;
	}

	private HttpGet setGetAuthorization(HttpGet httpGet) {
		httpGet.setHeader("Authorization", Constant.ENCODED_AUTHORIZATION());
		return httpGet;
	}

	

	private void loadContact(HttpClient client, VendorVO vendor) throws Exception {
		HttpResponse responseDetail = client.execute(this.setGetAuthorization(new HttpGet(Constant.REST_VENDOR_DETAIL(vendor.getVendorCode()))));
		if (responseDetail.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
			JSONObject responseJson = JSONFactoryUtil.createJSONObject(EntityUtils.toString(responseDetail.getEntity()));
			boolean success = responseJson.getBoolean("success");
			if (success) {
				if (vendor.getVendorName() == null || vendor.getVendorName().trim().length() == 0) {
					vendor.setVendorName(responseJson.getString("name"));
				}
				JSONArray jsonArrayKnvK = responseJson.getJSONObject("results").getJSONArray("knvK_TAB");
				for (int i = 0; i < jsonArrayKnvK.length(); i++) {
					JSONObject detailJson = jsonArrayKnvK.getJSONObject(i);
					int contactPersonNumber = detailJson.getInt("contactPersonNumber");

					HttpResponse responsePartner = client.execute(this.setGetAuthorization(new HttpGet(Constant.REST_PARTNER_DETAIL(contactPersonNumber))));
					if (responseDetail.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
						JSONObject responsePartnerJson = JSONFactoryUtil.createJSONObject(EntityUtils.toString(responsePartner.getEntity()));
						LOGGER.info(responsePartnerJson.toString());
						vendor.addContact(new VendorContactVO(contactPersonNumber, detailJson.getString("firstName"), detailJson.getString("name"), detailJson.getInt("function")));
						LOGGER.info(contactPersonNumber + detailJson.getString("firstName"));
					}
				}
			}
		} else {
			LOGGER.error(responseDetail.getStatusLine());
		}

	}

	public VendorVO getVendor(String vendorCode) throws Exception {
		HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(Constant.CREDENTIAL_PROVIDER()).build();
		VendorVO vendor = new VendorVO(vendorCode, null);
		this.loadContact(client, vendor);
		return vendor;
	}


}

bnd.bnd of my api-module

Bundle-Name: Enosix-api
Bundle-SymbolicName: com.raritan.ci.enosix
Bundle-Version: 1.0.0
Export-Package: \
    com.ci.enosix.api,\
    com.ci.enosix.vo

 

my build.gradle of mvc-module

dependencies {
	compileOnly group: "com.liferay.portal", name: "release.portal.api"

	cssBuilder group: "com.liferay", name: "com.liferay.css.builder", version: "3.0.2"
	compileOnly project(":modules:CI-Constant-api")
	compileOnly project(":modules:CI-CommonUtil-api")
	compileOnly project(":modules:CI-PoiUtil-api")

	compileOnly project(":modules:Enosix-api")


}

 

because i run server via liferay-studeo, always, after i modify code and save it, it will auto deploy and work. i don't even need to redeploy or build from gradle tasks.

thumbnail
Olaf Kock, modified 2 Years ago.

RE: how to refresh module

Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent Posts

The class you post is a standard class, not a @Component. I'm assuming you're creating it with something like

EnosixRest enosixRest = new EnosixRest();

This would create an object, tied to the class loaded once. And even if you now deploy a new module (through OSGi), it wouldn't magically replace the implementation. Rather, this would eliminate the possibility for the Garbage Collector to get rid of the old class, and object. OSGi can't do that magically for you.

Suggestion: Make this class a @Component, wire it through @Reference. That reference will automatically update and create a new object whenever you deploy the module again.

Scarletake Bwi, modified 2 Years ago.

RE: RE: how to refresh module

Expert Posts: 326 Join Date: 12/20/10 Recent Posts

hi Olaf

thank you.

i try make this class a @Component, wire it through @Reference.

if fail when i use 

@Component(
		immediate=true,
		service = EnosixRest.class
		)
public class EnosixRest {
> Task :modules:Enosix-api:jar FAILED
error  : [com.ci.enosix.api.EnosixRest] The component is not assignable to specified service javax.portlet.Portlet

my module is not a service-builder module, it's a just api-module.

is there any passable to use @Component in my case?

and, i own the servcer, is there any passabe, i can delete temp or somthing, force it build and deploy newest version?

 

thank you