Im trying to implement hauwei-braze into my react native app. But when I implement the code I get the following error.
CustomService.java
import com.braze.Braze;
import com.braze.push.BrazeHuaweiPushHandler;
import com.huawei.hms.push.RemoteMessage;
public class CustomService extends HmsMessageService {
#Override
public void onNewToken(String token) {
super.onNewToken(token);
Braze.getInstance(this).setRegisteredPushToken(token);
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//super.onMessageReceived(remoteMessage);
if (BrazeHuaweiPushHandler.handleHmsRemoteMessageData(this, remoteMessage.getDataOfMap())) {
// Braze has handled the Huawei push notification
} else {
super.onMessageReceived(remoteMessage);
}
}
}
build.gradle
implementation 'com.huawei.hms:push:6.9.0.300'
AndroidManifest.xml
<meta-data
android:name="push_kit_auto_init_enabled" android:value="true" />
<service
android:name=".CustomService" android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
Error
error: non-static method handleHmsRemoteMessageData(Context,Map<String,String>) cannot be referenced from a static context
if (BrazeHuaweiPushHandler.handleHmsRemoteMessageData(this, remoteMessage.getDataOfMap())) {
I tried changing the version og the push implementation to the version 3 and 4
Related
I have tried modifying the code of this repo : Chiuki's android test
so it will fit Dagger's configuration for my project.
So What I did is :
1) Adding a Component for MainActivity :
#PerActivity
#Component(dependencies = DemoApplication.ApplicationComponent.class)
public interface MainActivityComponent {
void inject(MainActivity mainActivity);
Clock getClock();
}
2) Modifying Application class to create and provide ApplicationComponent :
private ApplicationComponent component;
#Override
public void onCreate() {
super.onCreate();
component = createComponent();
component.inject(this);
}
protected ApplicationComponent createComponent() {
return DaggerDemoApplication_ApplicationComponent.builder().build();
}
public ApplicationComponent component() {
return component;
}
3) Perform injection in MainActivity's onCreate() :
DaggerMainActivityComponent.builder()
.applicationComponent(((DemoApplication) getApplication()).component())
.build()
.inject(this);
and I can verify by running the app that it seems to working.
And now I'm trying to modify accordingly tests in androidTest folder so
they will keep working.
First step was to change createComponent() method inside MockDemoApplication to provide the mock Clock instance :
#Override
protected ApplicationComponent createComponent() {
return DaggerDemoApplication_ApplicationComponent.builder()
.clockModule(new ClockModule() {
#Override
Clock provideClock() {
return Mockito.mock(Clock.class);
}
})
.build();
}
And second step was to perform the injection in MainActivityTest inside setUp() method :
#Before
public void setUp() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
DemoApplication app
= (DemoApplication) instrumentation.getTargetContext().getApplicationContext();
DaggerMainActivityTest_TestComponent.builder()
.mockClockModule(new MockClockModule())
.build()
.inject(this);
}
So now I'm running the next test but it fails with AssertionFailedError :
Caused by: junit.framework.AssertionFailedError: 'with text: is "2008-09-23"' doesn't match the selected view.
Expected: with text: is "2008-09-23"
Got: "TextView{id=2131165184, res-name=date, visibility=VISIBLE, width=272, height=135, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=2017-11-22, input-type=0, ime-target=false, has-links=false}"
I'm guessing that the injection worked, since the test is not crashing with a NullPointerException when it calls clock instance, but somehow it is returning the
I'm trying to remove some boilerplate from routes in Camel.
For example, let's consider the two routes, which are similar and most of their inner stuff could be generated. I've created a component "template", which creates TemplateEndpoint, and modifyed an XML config to use the template component.
A custom method TemplateEndpoint.generateRoute (adding route definitions) is being called from StartupListener (defined in TemplateEndpoint.setSuffix).
So while Camel context starting, route definitions appear in the context, but the framework doesn't create route services for them and hence they don't get started.
How to start routes added in StartupListener?
Probably I'm facing an XY problem, and you can advice me a better approach to do the trick (i.e. adding and starting routes on the fly).
Similar two routes
<route id="route_A">
<from uri="restlet:/another1?restletMethods=GET" />
<to uri="first:run_A" />
<to uri="second:jump_A" />
<to uri="third:fly_A" />
</route>
<route id="route_B">
<from uri="restlet:/another2?restletMethods=GET" />
<to uri="first:run_B" />
<to uri="second:jump_B" />
<to uri="third:fly_B" />
</route>
Modified XML
<route id="route_A">
<from uri="restlet:/another1?restletMethods=GET" />
<to uri="template://?suffix=A" />
</route>
<route id="route_B">
<from uri="restlet:/another2?restletMethods=GET" />
<to uri="template://?suffix=B" />
</route>
Endpoint
public class TemplateEndpoint extends DefaultEndpoint {
/* some methods omitted */
// this endpoint creates a DefaultProducer, which does nothing
public void setSuffix(final String suffix) throws Exception {
this.getCamelContext().addStartupListener(new StartupListener() {
#Override
public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws Exception {
generateRoute(suffix)
.addRoutesToCamelContext(context);
}
});
}
private RouteBuilder generateRoute(final String suffix){
final Endpoint endpoint = this;
return new RouteBuilder() {
#Override
public void configure() throws Exception {
from(endpoint)
.to("first:run_" + suffix)
.to("second:jump_" + suffix)
.to("third:fly_" + suffix);
}
}
}
I would create a dynamic route builder e.g.
public class MyRouteBuilder extends RouteBuilder {
private String another;
private String letter;
public MyRouteBuilder(CamelContext context,String another, String letter) {
super(context);
this.another=another;
this.letter=letter;
}
#Override
public void configure() throws Exception {
super.configure();
from("restlet:/"+another+"?restletMethods=GET")
.to("first:run_"+letter)
.to("second:jump_"+letter)
.to("third:fly_"+letter);
}
}
and add it on some event e.g
public class ApplicationContextProvider implements ApplicationContextAware {
#Override
public void setApplicationContext(ApplicationContext context)
throws BeansException {
camelContext=(CamelContext)context.getBean("mainCamelContext");
camelContext.addRoutes(new MyRouteBuilder(camelContext, "another1","A"));
camelContext.addRoutes(new MyRouteBuilder(camelContext, "another2","B"));
..
I read about org.eclipse.e4.core.contexts.IContextFunction but could not find online an actual example.
My understanding is that a component implements an IContextFunction and on calling compute another object is lazily created.
But how/when the compute method is called it is not clear to me.
For example with the following:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
name="com.example.e4.rcp.todo.contextservice.translate">
<implementation class="com.example.e4.rcp.todo.contextservice.Test"/>
<service>
<provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
</service>
<property name="service.context.key" type="String"
value="com.example.e4.rcp.todo.contextservice.test"/>
</scr:component>
someone must call for the com.example.e4.rcp.todo.contextservice.test for compute to be called but it is unclear to me how this is used.
Does anyone have an example reference?
It is what gets injected into your pojos.
E.g.
public class YourPojo {
#Inject
#Named("com.example.e4.rcp.todo.contextservice.test")
private Object yourObject;
}
OR
public class YourPojo {
#Inject
public void test(IEclipseContext ctx) {
Object yourObject = ctx.get("com.example.e4.rcp.todo.contextservice.test");
}
}
OR
public class YourPojo {
#Inject
public void test(#Named("com.example.e4.rcp.todo.contextservice.test") Object yourObject) {
// consume yourObject
}
}
<form-bean name="RegisterForm" type="com.mysite.form.RegisterForm" />
<action path="/register" type="com.mysite.action.RegisterAction" name="RegisterForm" input="/register.jsp" validate="true">
<forward name="success" path="/welcome.jsp" />
<forward name="failure" path="/register.jsp" />
</action>
RegisterForm
public class RegisterForm extends ActionForm{
private String name;
/**
Constructor
Set+Get
**/
public ActionErrors validate(ActionMapping mapping, ServletRequest request) {
ActionErrors errorList = new ActionErrors();
System.out.println("VALIDATING");
return errorList;
}
}
This is all i have. For some reason it seems that the control flow jumps directly to the ActionForm's execute method because I can't even see the VALIDATING message in the console. Is there something I'm missing? Thanks!
You need to use the other overloaded validate() method that takes HttpServletRequest
An Axis 2 client (wsdl2java generated code) invoking an Axis 2 Webservice is not receiving a RuntimeException thrown from a Service. The invoked method is a void method.
The Axis 2 version I'm using for both client and server is 1.6.1.
When I run the following test it completes successfully and no Exception is received:
#Test
public void testMyService() throws RemoteException {
String target = "http://localhost:8080/services/MyService";
MyServiceStub myServiceStub = new MyServiceStub(target);
myServiceStub.doSomething();
}
MyService.java:
package com.afirme.webservice.service;
#Service
public class MyService {
public void doSomething() {
throw new IllegalArgumentException("Just testing!");
}
}
services.xml:
<serviceGroup>
<service name="MyService">
<description>
My Service
</description>
<messageReceivers>
<messageReceiver
mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
<messageReceiver
mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
<parameter name="SpringBeanName">myService</parameter>
</service>
</serviceGroup>
This operation is an in only one. So you won't receive any soap faults from that. If you want to throw faults your operation must be an in-out one.