ClassNotFoundException trown when registering Midlet in the PushRegistry - java-me

I'm getting an odd error I can't get to the bottom of. When I register the midlet in the Push Registry it throws the ClassNotFoundException. I've used a very standard implementation straight from the API documentation just the url has been altered
// MIDlet class name
String midletClassName = this.getClass().getName();
// Register a static connection.
String url = "sms://:2049";
// Use an unrestricted filter.
String filter = "*";
PushRegistry.registerConnection(url, midletClassName, filter);
this for some reason throws the java.lang.ClassNotFoundException! When I view the JAD it looks ok:
MIDlet-1: AlarmHandler, ,sweoch.test.AlarmHandler
which is the class midletClassName equals at debug. So why is this trowing exceptions?

Related

Extend StagedModelDataHandler for Journal Article in Staging

I am working on local live staging in Liferay 7.1, in which I have one custom field in Web content. When I export those web content to local live, I want to check that custom field as result I would be export that web content.
So for that, I am extending doExportStagedModel in BaseStagedModelDataHandler as below.
#Component(immediate = true,service = {StagedModelDataHandler.class})
public class Demo extends BaseStagedModelDataHandler<JournalArticle> {
// All the stuff
#Override
protected void doExportStagedModel(
PortletDataContext portletDataContext, JournalArticle article)
throws Exception {
// overridden stuff
}
// Other stuff
}
When I am deploying this, I got below exception.
2018-11-20 04:04:12.669 ERROR The setJournalCreationStrategy method
has thrown an exception java.lang.IllegalArgumentException: argument
type mismatch
2018-11-20 04:04:12.850 ERROR The
setJournalFeedExportImportContentProcessor method has thrown an
exception java.lang.IllegalArgumentException: argument type mismatch
Does anybody having idea how can I do this proper way on this?

MVCResourceCommand to send binary data inside native journal portlet

I would like to send a binary file via an appended MVCResourceCommand I coded for the native journal portlet. But the program is unable to use the OutputStream provided by the resource request.
IOUtils.copy( input, response.getPortletOutputStream() );
Considering:
The code works perfectly on StrutsActions
In custom portlets, it also works
In StrutsActions:
IOUtils.copy( input, response.getOutputStream() );
However, the code throws an IllegalStateException, saying that the writer is being used when I call response.getOutputStream().
I know we can not mix these two
The code is not attempting to do so
I wonder if Liferay is doing something with that request before it reaches my extension of BaseMVCResourceCommand, this is specifically for that native portlet.
I checked the preview feature for a webcontect item, but its URL is for the view mode.
The URL is created from a portlet:resourceURL tag inserted through a JSP fragment and the command is in its own OSGi module.
For sure, the URL is correct and the command logs that it was hit, but the exception is thrown afterwards.
The portlet I am trying to change is the:
"com_liferay_journal_web_portlet_JournalPortlet"
Any thoughts?
PS: I know about the Servlet and Portlet ResponseUtils. but they also eventually try getting the stream, leadin to the same exception.
#Component( immediate = true,
property = {
"javax.portlet.name=" + JOURNAL, "mvc.command.name=/command"
},
service = MVCResourceCommand.class )
public class Resource extends BaseMVCResourceCommand {
#Override
public void doServeResource( ResourceRequest request, ResourceResponse response ) throws PortletException {
try {
response.getPortletOutputStream();
}
catch ( Exception e ) {
throw new PortletException( e );
}
}
}
Caused by: java.lang.IllegalStateException: Unable to obtain OutputStream because Writer is already in use
at com.liferay.portlet.MimeResponseImpl.getPortletOutputStream(MimeResponseImpl.java:75)
Update:
It seems this is the source of my issues (PortletURLImpl), still looking for a solution though:
if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
_copyCurrentRenderParameters = true;
}
When the URL is created it comes with all sources of garbage from the render phase. Including an MVCPath

change label value using value stored at session

i have two jsf pages (home.jsf and employees.jsf) ,
home page has a button that navigates to employees page,
while navigating i store value in session scope
at (Managed bean)
public void putSessionAL(ActionEvent actionEvent) {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("key","value");
}
public String navigate() {
return "employees";
}
i want to change Label at employees viewObject from UIHints tab depending on value stored at session using the following groovy expression
adf.context.sessionScope.key
and changed trustMode to trusted but it fires the following exception
oracle.jbo.script.ExprScriptException: JBO-29114 ADFContext is not setup to process messages for this exception. Use the exception stack trace and error code to investigate the root cause of this exception. Root cause error code is JBO-25188. Error message parameters are {0=Employees.FirstName, 1=, 2=oracle.jbo.script.ExprSecurityException}
at oracle.jbo.script.ExprScriptException.throwException(ExprScriptException.java:316)
at oracle.jbo.script.ExprScriptException.throwExceptionWithExprDef(ExprScriptException.java:387)
at oracle.jbo.ExprEval.processScriptException(ExprEval.java:599)
at oracle.jbo.ExprEval.doEvaluate(ExprEval.java:697)
at oracle.jbo.ExprEval.evaluate(ExprEval.java:508)
at oracle.jbo.ExprEval.evaluate(ExprEval.java:487)
at oracle.jbo.common.NamedObjectImpl.resolvePropertyRaw(NamedObjectImpl.java:680)
at oracle.jbo.server.DefObject.resolvePropertyRaw(DefObject.java:366)
One way to do it at the VO UIHint attribute label level will be programmaticaly by doing as follow :
In your VO go to the java tab and add the RowImpl java class
In the VORowImpl Add the following function
public String getMySessionLabel() {
return (String)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("key");
}
In the Label add the following EL expression :
adf.object.getMySessionLabel()
This technique allow you more control than pure EL, if you want to do more than getting from session for example. In your case pure EL, as you did, should work as well. (Would need to check what is wrong with yours, maybe just missing the
#{adf.context.sessionScope.key}
If you attempt to get your label from a method in viewRowImpl. So this will be executed at least once for each row. I think this solution isn't fit for your case.
anyway ADF as a framework added strong policy and validations in EL in general and especially in version 12.2.x.
The solution for you case as following:
Create new class in model layer which extends oracle.jbo.script.ExprSecurityPolicy class
Override checkProperty method.
#Override
public boolean checkProperty(Object object, String string, Boolean b) {
if (object.getClass().getName().equals("oracle.adf.share.http.ServletADFContext") && string.equals("sessionScope")) {
return true;
}
return super.checkProperty(object, string, b);
}
Open adf-config.xml source and in startup tag set your class ExprSecurityPolicy property.
like:
<startup ExprSecurityPolicy="model.CustomExprSecurityPolicy">

Java Cucumber: How to get string parameter values from all the steps in a single scenario

I'm looking for a way to get all the parameters that are being passed in each step before entering the actual scenario for each scenario in my feature file.
Sample feature file:
Feature: Login action
Background:
When "{login url}" is open
Scenario: Registered user provides valid username and password
Given user enters username "{username}" and password "test password"
And user clicks on "btnLogin"
Then user is logged in
Parameters I want to get:
{login url}
{username}
password
btnLogin
What I tried so far:
I have tried using a common hook that will be automatically used by all of my scenarios:
public class ScenarioHook {
public ScenarioHook() {
}
#Before
public void setupScenario(Scenario scenario) throws InterruptedException {
//Here I am currently watching the {scenario} object and I can see all the steps
//but I still dont know where to get the passed parameter values.
}
#After
public void teardownScenario() throws InterruptedException {
}
}
UPDATE 1:
The reason why I want to do this is I want to manipulate the strings (if possible). e.g. all data enclosed in "{}" will be transformed to something else before entering the actual scenario.
You can use the #Transform annotation to change the value of the parameter to the step definition.
For this you will need to create a class which contains the logic of the string modification and will return the modified value.
public class StringTransformer extends Transformer<String>{
public String transform(String value) {
return "transformed "+value;
}
}
Next you need to include this class in your stepdefinition using the #Transform annotation in front of the method argument.
#When("^Login with (.*?)$")
public void helloHere(#Transform(StringTransformer.class) String userName)
{
System.out.println("TEXT --- " + userName);
}
This should give you the new transformed string. You can use this to create objects from your initial string. (Actually that is what it is used for)
Cucumber Sceanario class will not provide you this information as I don't think all steps are actually being loaded and parsed before starting executing the scenario but parsed one by one during the scenario execution. One option I can think of is to create a background step where you will manually include all parameters involved in the scenario. For example:
Feature: Login action
Background:
Given these parameters are using within this scenario: "{login url}", "{username}", "password", "btnLogin"
When "{login url}" is open

Capturing a javafx Change event with mockito throws an IllegalStateException

I want to test using mockito, that some events are triggered when a javafx ObservableList is modified.
I have tried to to it this way :
#Test
public void handleListChanged() throws Exception {
// [given]
ObservableList<String> list = FXCollections.observableArrayList();
ListChangeListener<String> listener = mock(ListChangeListener.class);
list.addListener(listener);
// [when]
list.add("test");
// [then]
ArgumentCaptor<Change> argument = ArgumentCaptor.forClass(Change.class);
verify(listener).onChanged(argument.capture());
assertTrue(argument.getValue().wasAdded());
}
bu an IllegalStateException raises on the last line :
java.lang.IllegalStateException
at com.sun.javafx.collections.NonIterableChange.checkState(NonIterableChange.java:101)
at com.sun.javafx.collections.NonIterableChange.getPermutation(NonIterableChange.java:81)
at javafx.collections.ListChangeListener$Change.wasPermutated(ListChangeListener.java:156)
at javafx.collections.ListChangeListener$Change.wasAdded(ListChangeListener.java:165)
at FXCollectionsTest.handleListChanged(FXCollectionsTest.java:28
The documentation of the wasAdded() method warns that an IllegalArgumentException could be thrown "if this Change is in initial state" but i don't understand it.
Why my code is not working ?
Is there a solution for testing this code using mockito ?
You must call the next method first on the Change object before you can call any other method like wasAdded.
Unit test
assertTrue(argument.getValue().next());
assertTrue(argument.getValue().wasAdded());
Documentation
public abstract boolean next()
Go to the next change. In initial state is invalid a require a call to next() before calling other methods. The first next() call will make this object represent the first change.
Source

Resources