Can't publish in cometd channel - server-push

I'm getting this error when I try to publish a string in a channel:
java.lang.AbstractMethodError: org.cometd.client.BayeuxClient$BayeuxClientChannel.publish(Ljava/lang/Object;)V
this is the code that is trying to publish:
public class EnviadorMensagem implements Runnable {
private String nomeCanal;
private Mensagem mensagem;
private ClientSession cliente;
private boolean pausado = true;
private boolean cancelado = false;
#Override
public void run() {
while (pausado) {
pausar();
}
if (!cancelado) {
converterEEnviar();
}
}
private void pausar() {
synchronized (this) {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void converterEEnviar() {
ConversorMensagem conversor = new ConversorMensagem();
ClientSessionChannel canal = cliente.getChannel(nomeCanal);
canal.publish(conversor.converter(mensagem)); //<- the error happens here!!
}
public void ativar() {
synchronized (this) {
pausado = false;
this.notifyAll();
}
}
public void cancelar() {
synchronized (this) {
cancelado = true;
}
ativar();
}
public void setNomeCanal(String nomeCanal) {
this.nomeCanal = nomeCanal;
}
public void setMensagem(Mensagem mensagem) {
this.mensagem = mensagem;
}
public void setCliente(ClientSession cliente) {
this.cliente = cliente;
}
}
As you can see, this class is running in a separate thread.
this is part of my pom.xml:
<dependencies>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-client</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>bayeux-api</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>8.1.7.v20120910</version>
</dependency>
</dependencies>
Someone knows how to solve it??

You get AbstractMethodError when you compiled your code against a version of a library, but at runtime you are using another, that does not have that method, or has it with a different signature.
Double check your classpath and the CometD library versions you're using.

Related

Appium not recognising the elements

I am experiencing a weird problem in object identification. I have 3 fields username, password and login buttons. The username field is recognised and I am able to key in the data. But Appium is not recognising the other 2 fields no matter what. I need help.
public class LoginPageObjects {
#AndroidFindBy(uiAutomator = "new UiSelector().text(\" Employee ID or Email\")")
private AndroidElement username;
#AndroidFindBy(uiAutomator = "new UiSelector().text(\"Password\")" )
private AndroidElement password;
#AndroidFindBy(uiAutomator = "new UiSelector().text(\"LOGIN\")")
private AndroidElement loginsubmit;
public AndroidElement getUsername() {
return username;
}
public AndroidElement getPassword() {
return password;
}
public AndroidElement getLoginsubmit() {
return loginsubmit;
}
}
public class LoginPageFuncs extends LoginPageObjects {
private AndroidDriver driver;
public LoginPageFuncs(AndroidDriver driver) {
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
public void doLogin(Map<String, String> table) throws InterruptedException {
getUsername().sendKeys(table.get("username"));
getPassword().sendKeys(table.get("password"));
getLoginsubmit().click();
}
}
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.13.1</version>
</dependency>
</dependencies>
Maybe it's because of spaces with text you are trying to get.
Try this:
public class LoginPageObjects {
#AndroidFindBy(uiAutomator = "new UiSelector().textContains(\" Employee ID or Email\")")
private AndroidElement username;
#AndroidFindBy(uiAutomator = "new UiSelector().textContains(\"Password\")" )
private AndroidElement password;
#AndroidFindBy(uiAutomator = "new UiSelector().textContains(\"LOGIN\")")
private AndroidElement loginsubmit;
public AndroidElement getUsername() {
return username;
}
public AndroidElement getPassword() {
return password;
}
public AndroidElement getLoginsubmit() {
return loginsubmit;
}
}

Singleton Service in weblogic cluster is registering but not invoking activate method

I am implementing a singleton service in a weblogic 12.2.1.2 with EBJ 3.1 in a maven multimodule EAR project.
My singleton service is registering in the cluster.
This is the log from the node where is registered:
<BEA-000189> <The Singleton Service Appscoped_Singleton_Service is now active on this server.>
And this is from other node:
<BEA-003130> <Appscoped_Singleton_Service successfully activated on server iss3.>
The singleton service is implementing the interface weblogic.cluster.singleton.SingletonService but the methods activate and deactivate is not invoked when the nodes starts or shutdown.
I was reading something about versioned EARs and MANIFEST files but not understood this.
I need some help to make methods activate and deactivate be invoked.
This is my class:
import java.io.Serializable;
import javax.inject.Inject;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.test.MyTimerLocal;
import weblogic.cluster.singleton.SingletonService;
public class MySingletonServiceClass implements SingletonService, Serializable, MySingletonServiceInterface {
private static final long serialVersionUID = 3966807367110330202L;
private static final String jndiName = "MySingletonServiceClass";
private int myValue;
#Inject
private MyTimerLocal myTimer;
#Override
public int getMyValue() {
return this.myValue;
}
#Override
public synchronized void setMyValue(final int myValue) {
this.myValue = myValue;
}
#Override
public void activate() {
System.out.println("activate triggered");
Context ic = null;
try {
ic = new InitialContext();
ic.bind(MySingletonServiceClass.jndiName, this);
System.out.println("Object now bound in JNDI at " + MySingletonServiceClass.jndiName);
this.myValue = 5;
final String msg = "###################### MySingletonServiceClass.activate():: Fechamento agendado para " + this.myTimer.agendaExecucao() + " ###############";
System.out.println(msg);
} catch (final NamingException e) {
this.myValue = -1;
e.printStackTrace();
} finally {
try {
if (ic != null) {
ic.close();
}
} catch (final NamingException e) {
e.printStackTrace();
}
}
}
#Override
public void deactivate() {
System.out.println("deactivate triggered");
Context ic = null;
try {
ic = new InitialContext();
ic.unbind(MySingletonServiceClass.jndiName);
System.out.println("Context unbound successfully");
} catch (final NamingException e) {
e.printStackTrace();
}
}
}
Thanks for your time.
I got this working now with this in my src\main\application\META-INF\weblogic-application.xml
<wls:singleton-service>
<wls:class-name>com.test.MySingletonServiceClass</wls:class-name>
<wls:name>Appscoped_Singleton_Service</wls:name>
</wls:singleton-service>

unable to set useridentity in Mobilefirst [duplicate]

I am trying assign a userid to user and I am getting error . I am following as steps below.
server details.
<realm loginModule="AuthLoginModule" name="AuthRealm">
<className>com.worklight.integration.auth.AdapterAuthenticator</className>
<parameter name="login-function" value="AuthAdapter.onAuthRequired"/>
<parameter name="logout-function" value="AuthAdapter.onLogout"/>
</realm>
</realms>
<loginModule name="AuthLoginModule">
<className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
</loginModule>
<customSecurityTest name="AuthSecurityTest">
<test isInternalUserID="true" realm="AuthRealm"/>
</customSecurityTest>
Adapter
function onAuthRequired(headers, errorMessage){
errorMessage = errorMessage ? errorMessage : null;
return {
authStatus: "credentialsRequired",
errorMessage: errorMessage
};
}
function submitAuthentication(username, password){
// if (username==="user" && password === "password"){
var userIdentity = {
userId: username,
displayName: username,
attributes: {
foo: "bar"
}
};
WL.Server.setActiveUser("AuthRealm", userIdentity);
return {
authStatus: "complete"
};
// }
// return onAuthRequired(null, "Invalid login credentials");
}
function getSecretData(){
return {
secretData: "Very very very very secret data"
};
}
function onLogout(){
WL.Logger.debug("Logged out");
}
Adapter xml
<procedure name="submitAuthentication" securityTest="wl_unprotected" />
<procedure name="getSecretData" securityTest="AuthSecurityTest"/>
Android code:
public class MFPInitializer {
Context mContext;
public AndroidChallengeHandler challengeHandler;
private String realm = "AuthRealm";
WLClient client = null;
private static MFPInitializer mfpInitializer = new MFPInitializer();
/* A private Constructor prevents any other
* class from instantiating.
*/
private MFPInitializer() {
}
/* Static 'instance' method */
public static MFPInitializer getInstance() {
return mfpInitializer;
}
void mfpConnector(WLClient client) {
challengeHandler = new AndroidChallengeHandler(realm);
client.registerChallengeHandler(challengeHandler);
client.connect(new WLResponseListener() {
#Override
public void onSuccess(WLResponse wlResponse) {
Log.d("Success--- MFP_connect", wlResponse.getResponseText());
}
#Override
public void onFailure(WLFailResponse wlFailResponse) {
Log.d("fail-- MFP_connect", wlFailResponse.getErrorMsg());
}
});
}
public void logout() {
if (client != null) {
client.logout(realm, new WLRequestListener() {
#Override
public void onSuccess(WLResponse wlResponse) {
}
#Override
public void onFailure(WLFailResponse wlFailResponse) {
}
});
}
}
public WLClient mfpInit(Context context) {
mContext = context;
try {
client = WLClient.createInstance(context);
if (client != null) {
mfpConnector(client);
}
} catch (Exception e) {
e.printStackTrace();
}
return client;
}
public static void registerUser() {
try {
URI adapterPath = new URI("/adapters/AuthAdapter/getSecretData");
WLResourceRequest request = new WLResourceRequest(adapterPath, WLResourceRequest.GET);
request.setQueryParameter("params", "[]");
request.send(new WLResponseListener() {
#Override
public void onSuccess(WLResponse wlResponse) {
Log.d("onsuccess--------", wlResponse.getResponseText());
}
#Override
public void onFailure(WLFailResponse wlFailResponse) {
Log.d("onfail--------", wlFailResponse.getErrorMsg());
}
});
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
Android challenge Handler
public class AndroidChallengeHandler extends ChallengeHandler {
// private Activity parentActivity;
private WLResponse cachedResponse;
public AndroidChallengeHandler( String realm) {
super(realm);
// parentActivity = activity;
}
#Override
public void onFailure(WLFailResponse response) {
try {
submitFailure(response);
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void onSuccess(WLResponse response) {
submitSuccess(response);
}
#Override
public boolean isCustomResponse(WLResponse response) {
try {
if(response!= null &&
response.getResponseJSON()!=null &&
!response.getResponseJSON().isNull("authStatus") &&
response.getResponseJSON().getString("authStatus") != ""){
return true;
}
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
#Override
public void handleChallenge(WLResponse response){
cachedResponse = response;
Log.d( "handleChallenge: ---- ",response.getResponseText());
try {
if(response.getResponseJSON().getString("authStatus").equals("credentialsRequired")){
// MainAdapterBasedAuth.setMainText("handleChallenge->credentialsRequired");
// Intent login = new Intent(parentActivity, LoginAdapterBasedAuth.class);
// parentActivity.startActivityForResult(login, 1);
}
else if(response.getResponseJSON().getString("authStatus").equals("complete")){
Log.d( "handleChallenge: ---- ",response.getResponseText());
submitSuccess(cachedResponse);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void submitLogin( String userName, String password){
Object[] parameters = new Object[]{userName, password};
WLProcedureInvocationData invocationData = new WLProcedureInvocationData("AuthAdapter", "submitAuthentication");
invocationData.setParameters(parameters);
WLRequestOptions options = new WLRequestOptions();
options.setTimeout(30000);
submitAdapterAuthentication(invocationData, options);
}
}
Intally in activity 1 a I am calling, which will initialize wlclient and adding realm.
MFPInitializer.getInstance().mfpInit(getApplicationContext());
But when I am trying to submit the login to setuser to device in mobile first platform my app crashes
MFPInitializer mfpInitializer= MFPInitializer.getInstance();
mfpInitializer.challengeHandler.submitLogin("user","Passcode");
I am getting following errors
on android monitor.
ava.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.worklight.wlclient.WLRequest.shouldFailOnChallengeCancel()' on a null object reference
on eclipse(MFP)
An error occurred while invoking procedure [project _MFP]AuthAdapter/submitAuthenticationFWLSE0100E: parameters: [project _MFP]
Cannot change identity of an already logged in user in realm 'AuthRealm'. The application must logout first.
FWLSE0101E: Caused by: [pro
The above mentioned error got resolved but the new userid is not getting updated In the mobilefirst console.
Can you please help me where I am doing mistake.
As mentioned in the comments, this problem was resolved by updating to the latest available iFix release from the IBM Fix Central website.

Jackson #Deserializer doesn't work

This is a duplicated question of this
POJO
#Entity
#Table(name = "pet")
public class Pet {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long petId;
private String petName;
private Date birthday;
#JsonSerialize(using = Serializer.class)
public Date getBirthday() {
return birthday;
}
#JsonDeserialize(using = Deserializer.class)
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Long getPetId() {
return petId;
}
public void setPetId(Long petId) {
this.petId = petId;
}
public String getPetName() {
return petName;
}
public void setPetName(String petName) {
this.petName = petName;
}
}
Serializer
public class Serializer extends JsonSerializer<Date> {
#Override
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
System.out.println("Serializer");
}
}
Deserializer
public class Deserializer extends JsonDeserializer<Date> {
#Override
public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
System.out.println("Deserializer works.");
return new Date();
}
}
Maven Dependency
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.3.2</version>
</dependency>
update: controller code
#Transactional
#Controller
public class Demo {
#Resource
private Dao dao;
#ResponseBody
#RequestMapping("/test")
public String tester(Pet pet){
dao.saveOrUpdate(pet);
return "success";
}
#ResponseBody
#RequestMapping("/test2")
public List<Pet> tester2(){
List<Pet> pets = dao.query(Pet.class);
return pets;
}
}
however only Serializer will be invoked everytime, Deserializer doesn't take any effect, I can't see where is wrong, could anybody help me?
Thanks.

Allure. How to get screenshot on testFailure event. Use Java+Junit4+Maven

If I want to get screenshot when my Tests are failed, so what the best practice is? I try to do this next way:
1)overridre AllureRunListener:
public class SimpleScreenshotTestListener extends AllureRunListener{
#Override
public void testFailure(Failure failure) {
if (failure.getDescription().isTest()) {
fireTestCaseFailure(failure.getException());
} else {
startFakeTestCase(failure.getDescription());
fireTestCaseFailure(failure.getException());
finishFakeTestCase();
}
makeScreenshot("Failure screenshot");
}
}
The method makeScreenshot("Failure screenshot") is a static method in Util Class:
public final class Util {
private Util() {}
#Attachment(value = "{0}", type = "image/png")
public static byte[] makeScreenshot(String name) {
return ((TakesScreenshot) <Thread Local Driver>).getScreenshotAs(OutputType.BYTES);
}
}
3) In my pom file I use created listener
SimpleScreenshotTestListener:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
</argLine>
<properties>
<property>
<name>listener</name>
<value>cms.fireFox.Tps.SimpleScreenshotTestListener</value>
</property>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
And my question is : Is this way is the best way or should I do this easier.
Just use JUnit Rules like the following:
public class ScreenshotOnFailureRule implements TestRule {
public Statement apply(final Statement statement, final Description description) {
return new Statement() {
#Override
public void evaluate() throws Throwable {
try {
statement.evaluate();
} catch (Throwable t) {
captureScreenshot();
throw t;
}
}
#Attachment
private byte[] captureScreenshot() {
try {
return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
} catch (Exception e) {
// No need to crash the tests if the screenshot fails
}
}
};
}
}
So far as captureScreenshot() method is run on failure Allure will attach resulting PNG byte stream to test case. Further reading about rules.