GWT serialization policy file - gwt-rpc

I have a GWT2.6.1 application. I uses a RPC call. I defined service, serviceAsync, serviceImpl. But I consistently got following errors:
INFO: javax.servlet.ServletContext log: logLevelServlet: ERROR: The serialization policy file '/analytics/E4322B1E292CEFFC5E147EAE677D2BFF.gwt.rpc' was not found; did you forget to include it in this deployment?
com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: javax.servlet.ServletContext log: logLevelServlet: ERROR: The serialization policy file '/analytics/E4322B1E292CEFFC5E147EAE677D2BFF.gwt.rpc' was not found; did you forget to include it in this deployment?
com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: javax.servlet.ServletContext log: logLevelServlet: Downloaded serialization policy from http://localhost:9876/policies/E4322B1E292CEFFC5E147EAE677D2BFF.gwt.rpc
EPARecord.java
public class EPARecord implements Serializable {
private static final long serialVersionUID = -6723643433565890894L;
private String timeStamp;
private String logLevel;
private String event;
private String comment;
public EPARecord(){}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getLogLevel() {
return logLevel;
}
public void setLogLevel(String logLevel) {
this.logLevel = logLevel;
}
public String getEvent() {
return event;
}
public void setEvent(String event) {
this.event = event;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}
LogLevelService.java
#RemoteServiceRelativePath("loglevel")
public interface LogLevelService extends RemoteService {
EPARecord[] getEAPRecords(String level) throws IllegalArgumentException;
}
LogLevelServiceAysnc.java
public interface LogLevelServiceAsync {
void getEAPRecords(String level, AsyncCallback<EPARecord[]> callback) throws IllegalArgumentException;
}
I cleard browser cache, and I clear the project and rebuild it. It always give the same erorr. I suppose EPARecord file has all String attributes and it is serializable. And in remote interface, it transfer array of EPARecord, it shall be ok without customerized implementation of serializable.

i take some problem.you can remove it and run again your app,if you have "inherits name='com.google.gwt.user.theme.clean.Clean'" code line into your *.gwt.xml file.

I had this problem when I wanted to connect to the local database with the GAE application. When I recreated my applications without GAE the problem disappeared.

Related

How do I get IEventBroker injected into an e4 OSGI service component

I am trying to get IEventBroker injected into my code to send out notifications.
Everything else works but eventBroker never gets injected. I do not get any compile time errors.
It just comes up null when the code is executed.
I've trimmed the code because it wouldn't let me submit it.
Thanks for any help in advance!
package com.test.services.internal;
imports ...
#Component
public class EnvironmentServiceImpl implements IEnvironmentService {
#Inject
private IEventBroker eventBroker;
private EntityManagerFactory entityManagerFactory;
private EntityManager entityManager;
#Activate
#SuppressWarnings("unchecked")
protected void activateComponent() {
getAll(environments -> {
if (environments.isEmpty()) {
List<Environment> initialModel = getMockEnvironments();
initialModel.forEach(this::save);
}
});
}
#Deactivate
protected void deactivateComponent() {
}
#Override
public void getAll(Consumer<List<Environment>> taskConsumer) {
eventBroker.post(EnvironmentEventConstants.TOPIC_ENVIRONMENT_LOADED,
createEventData(EnvironmentEventConstants.TOPIC_ENVIRONMENT_LOADED, updateEnvironment.getId()));
}
private Map<String, String> createEventData(String topic, String environmentId) {
}
}

How to use DI in this example?

I followed this example https://learn.microsoft.com/pt-br/azure/app-service/webjobs-sdk-get-started and it is working fine. What I want to do is to make the connection strings (strongly typed) available in all methods within Functions class. My Connection Strings object:
namespace MyApp.Domain
{
public class Secrets
{
public class ConnectionStrings
{
public string SqlServer {get; set;}
public string Storage {get; set;}
public string SendGrid {get; set;}
public string AzureWebJobsDashboard { get; set; }
public string AzureWebJobsStorage {get; set;}
}
}
}
In web project I use (and it works perfectly):
services.Configure<Secrets.ConnectionStrings>(Configuration.GetSection("CUSTOMCONNSTR_ConnectionStrings"));
and in the classes' constructors I use:
public class EmailController: ControllerBase
{
private readonly MyEmail _myEmail;
public EmailController(MyEmail MyEmail)
{
_myEmail = MyEmail;
}
[HttpGet]
public async Task<ActionResult<string>> SendEmail()
{
try
{
...
return await _myEmail.SendMailMI3D(myMsg);
}
catch (System.Exception ex)
{
return ex.Message + " - " + ex.StackTrace;
}
}
[HttpGet("sendgrid")]
public string GetSendGrid(long id)
{
return _myEmail.SendGridConnStr();
}
}
But this way doesn't work on webjobs (console apps).
I tried to insert a simple Console.WriteLine in Functions' constructor but it doesn't work as well. So I think this is the problem: Functions' constructor is not being called. So when I insert a message in my queue I receive this error message related to DI Connection String:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage ---> System.NullReferenceException: Object reference not set to an instance of an object.
Can anybody please help me? Thanks a lot.
public Functions(IOptions<Secrets.ConnectionStrings> ConnectionStrings)
{
_connectionStrings = ConnectionStrings;
Console.WriteLine("Simple line");
Console.WriteLine($"Functions constructor: ${_connectionStrings.Value.SendGrid}");
}
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage ---> System.NullReferenceException: Object reference not set to an instance of an object.
Dependency Injection is available in WebJobs but you do need to take the extra step to create an IJobActivator to define the injection.
namespace NetCoreWebJob.WebJob
{
public class JobActivator : IJobActivator
{
private readonly IServiceProvider services;
public JobActivator(IServiceProvider services)
{
this.services = services;
}
public T CreateInstance<T>()
{
return services.GetService<T>();
}
}
}
Inside Main()
var config = new JobHostConfiguration();
config.JobActivator = new JobActivator(services.BuildServiceProvider());
That should allow the runtime to utilize the parameterized constructor.

Alaways goin in onFailure in retrofit2.0

I am trying to hit the api : www.xyz.com/abc_cc/cc/userregister/newuser
This is my Code :
public class MainActivity extends AppCompatActivity {
public static final String BASE_URL = "abc.com/abc_cc/cc/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(getUnsafeOkHttpClient())
.addConverterFactory(GsonConverterFactory.create())
.build();
Endpoints endpoints= retrofit.create(Endpoints.class);
endpoints.newuser("{\"full_name\":\"sss\",\"states_id\":\"20\",\"mobile\":\"9876543210\",\"password\":\"******\",\"accept_terms\":true,\"Userid\":\"0\",\"refer\":\"\",\"ip-address\":\"1.2.3.4\",\"device_type\":\"samsung J5\",\"os-version\":\"5.0.1\",\"client\":\"app\",\"secret_key\":\"44\"}")
.enqueue(new retrofit2.Callback<Items>() {
#Override
public void onResponse(retrofit2.Call<Items> call, retrofit2.Response<Items> response) {
System.out.println("onResponse : "+response.message());
System.out.println("onResponse : "+response.body());
System.out.println("onResponse : "+response.code());
System.out.println("onResponse : "+response.errorBody());
System.out.println("onResponse : "+response.isSuccessful());
System.out.println("onResponse : "+response.raw());
System.out.println("onResponse : "+response);
}
#Override
public void onFailure(retrofit2.Call<Items> call, Throwable t) {
System.out.println("onFailure"+call);
}
});
}
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
#Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] chain,
String authType) throws CertificateException {
}
#Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] chain,
String authType) throws CertificateException {
}
#Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[0];
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts,
new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext
.getSocketFactory();
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient = okHttpClient.newBuilder()
.sslSocketFactory(sslSocketFactory)
.hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER).build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Interface :
public interface Endpoints {
#POST("/userregister/newuser")
#FormUrlEncoded
Call<Items> newuser(#Field("Data") String Data);
}
POJO class :
public class Items {
#SerializedName("Response-Status")
#Expose
private Boolean responseStatus;
#SerializedName("Response-Validate")
#Expose
private Boolean responseValidate;
#SerializedName("Response-Message")
#Expose
private String responseMessage;
#SerializedName("Response-Data")
#Expose
private ResponseData responseData;
public Boolean getResponseStatus() {
return responseStatus;
}
public void setResponseStatus(Boolean responseStatus) {
this.responseStatus = responseStatus;
}
public Boolean getResponseValidate() {
return responseValidate;
}
public void setResponseValidate(Boolean responseValidate) {
this.responseValidate = responseValidate;
}
public String getResponseMessage() {
return responseMessage;
}
public void setResponseMessage(String responseMessage) {
this.responseMessage = responseMessage;
}
public ResponseData getResponseData() {
return responseData;
}
public void setResponseData(ResponseData responseData) {
this.responseData = responseData;
}
}
I am getting this response :
{protocol=http/1.1, code=404, message=Not Found, url=www.xyz.com/userregister/newuser}
I have given the proper url then why is it taking only half of it?
I have tried the example from https://code.tutsplus.com/tutorials/sending-data-with-retrofit-2-http-client-for-android--cms-27845. This example and the link given in the example are working fine, but if I do the same with my url then I get the above error
I Hope kindly check your parsing issues may occurred.
#Override
public void onFailure(retrofit2.Call<Items> call, Throwable t) {
System.out.println("onFailure"+call);
//add this lije you got exceptions.
t.printStackTrace();
}
Change your Endpoints interface for this:
public interface Endpoints {
#POST("userregister/newuser")
#FormUrlEncoded
Call<Items> newuser(#Field("Data") String Data);
}
Note that I removed the trailing slash /. This way Retrofit appends the path you defined to the BASE_URL.
refer to the docs for Retrofit.Builder for a more detailed explanation, but pay particular attention to these bits:
Base URLs should always end in /.
A trailing / ensures that endpoints values which are relative paths
will correctly append themselves to a base which has path components.
...
Endpoint values which contain a leading / are absolute.
Absolute values retain only the host from baseUrl and ignore any
specified path components.
as presently written, the path referenced in your call to Endpoints.newuser() is absolute, and therefore the path segments after the host in your base URL are dropped (as this is the documented behavior).
therefore, you should change your Endpoints interface to use relative paths instead, like so:
public interface Endpoints {
#POST("userregister/newuser")
#FormUrlEncoded
Call<Items> newuser(#Field("Data") String Data);
}

NServiceBus Configuration with Custom Container

I am trying to re-use the service registrations in an assembly that I use through a few services in my solution. I follow the example listed from the NServiceBus website to implement the solution. When following that, unless I add the IWantCustomInitialization interface, my Init method (and IoC container implementation) appears not to function. When I have that interface implemented, I get exceptions (listed in SO questions here and here). I can't seem to get it to work that there are no exceptions AND the dependencies in my MessageHandler are being populated properly. Here is my current EndpointConfig implementation.
[EndpointSLA("00:00:30")]
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, UsingTransport<Msmq>, INeedInitialization {
public void Init() {
Configure.With().ObjectBuilderAdapter();
}
}
public class ObjectBuilderAdapter : IContainer {
readonly IDependencyInjector injector;
public ObjectBuilderAdapter(IDependencyInjectionBuilder dependencyInjectionBuilder) {
injector = dependencyInjectionBuilder.Create(); //This method does all the common service registrations that I am trying to re-use
//injector.RegisterType<ExtractIncomingPrincipal, PrincipalExtractor>();
}
public void Dispose() {
injector.Dispose();
}
public object Build(Type typeToBuild) {
return injector.Resolve(typeToBuild);
}
public IContainer BuildChildContainer() {
return new ObjectBuilderAdapter(new DependencyInjectorBuilder());
}
public IEnumerable<object> BuildAll(Type typeToBuild) {
return injector.ResolveAll(typeToBuild);
}
public void Configure(Type component, DependencyLifecycle dependencyLifecycle) {
injector.RegisterType(component);
}
public void Configure<T>(Func<T> component, DependencyLifecycle dependencyLifecycle) {
injector.RegisterType(component);
}
public void ConfigureProperty(Type component, string property, object value) {
if (injector is AutofacDependencyInjector) {
((AutofacDependencyInjector)injector).ConfigureProperty(component, property, value);
} else {
Debug.WriteLine("Configuring {0} for property {1} but we don't handle this scenario.", component.Name, property);
}
}
public void RegisterSingleton(Type lookupType, object instance) {
injector.RegisterInstance(lookupType, instance);
}
public bool HasComponent(Type componentType) {
return injector.IsRegistered(componentType);
}
public void Release(object instance) { }
}
public static class Extensions {
public static Configure ObjectBuilderAdapter(this Configure config) {
ConfigureCommon.With(config, new ObjectBuilderAdapter(new DependencyInjectorBuilder()));
return config;
}
}
Note: When I use the INeedInitialization interface, I get the ComponentNotRegisteredException when it's looking for IStartableBus.
When you are trying to swap the built in container, then you need to implement IWantCustomInitialization in the same class that implements IConfigureThisEndpoint.
You can use your own container and register all your types in there and tell NSB to use that container.
For example:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
public void Init()
{
var container = new ContainerBuilder().Build();
Configure.With()
.AutofacBuilder(container);
}
}

Help troubleshooting JAXB unmarshalling NPE

I am working with an API which I do not have control on, which returns XMLs.
Basically I have directory object that can contain multiple directory and file objects which are not wrapped by any tag, among few other primitive fields.
file object contains few primitive fields, and 2 lists which are wrapped by tPathList and oPathList tags.
Below is an example of such XML:
<hwreply>
<result>1</result>
<directory>
<file>
<created>DATE</created>
<modified>DATE</modified>
<name>STRING</name>
<size>INT</size>
<tPath>STRING</tPath>
<oPath>STRING</oPath>
<aPath>STRING</aPath>
<tPathList>
<tPath>STRING</tPath>
...
</tPathList>
<oPathList>
<oPath>STRING</oPath>
...
</oPathList>
</file>
<file>...</file>
...
<directory>...</directory>
<directory>...</directory>
...
<nEntries>5</nEntries>
<created>DATE</created>
<modified>DATE</modified>
</directory>
</hwreply>
I have created Directory and File objects, and OpenDirectory which is the root. When I call
OpenDirectory od = response.getEntity(OpenDirectory.class);
I get the following exception:
Exception in thread "main" java.lang.NullPointerException
at com.sun.xml.internal.bind.v2.runtime.reflect.Lister$CollectionLister.addToPack(Lister.java:290)
at com.sun.xml.internal.bind.v2.runtime.reflect.Lister$CollectionLister.addToPack(Lister.java:254)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Scope.add(Scope.java:106)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty$ReceiverImpl.receive(ArrayERProperty.java:195)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.endElement(UnmarshallingContext.java:507)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.endElement(SAXConnector.java:145)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2938)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:200)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:173)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:120)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:103)
at com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider.readFrom(XMLRootElementProvider.java:115)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:111)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:553)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:506)
at liveperson.lphosting.plugins.cdn.proxy.highwinds.HighwindsProxy.getDirectory(HighwindsProxy.java:49)
at liveperson.lphosting.plugins.cdn.proxy.highwinds.HighwindsProxy.main(HighwindsProxy.java:59)
I figured that it relates to one of the lists that I have, but I couldn't figure where did I go wrong. Any help would be appreciated.
Thanks in advance.
Below are the classes (minus few fields/methods):
#XmlRootElement(name = "hwreply")
public class OpenDirectory extends ResponseBase {
#XmlElement(name="session")
public Session getSession() {...}
public void setSession(Session session) {...}
#XmlElement(name="directory")
public Directory getDirectory() {...}
public void setDirectory(Directory directory) {...}
}
public class Directory {
...
private List<Directory> directories;
private List<File> files;
#XmlElement(name="nEntries")
public int getnEntries() {...}
public void setnEntries(int nEntries) {...}
#XmlElement(name="name")
public String getName() {... }
public void setName(String name) {... }
#XmlElement(name="readonly")
public boolean isReadonly() {... }
public void setReadonly(boolean readonly) { ... }
#XmlElement (name="created")
public String getCreated() { ... }
public void setCreated(String created) { ... }
#XmlElement(name="modified")
public String getModified() {... }
public void setModified(String modified) {... }
#XmlElements(
#XmlElement(name="directory", type=Directory.class)
)
public List<Directory> getDirectories() {
return directories;
}
public void setDirectories(List directories) {
this.directories = directories;
}
#XmlElements(
#XmlElement(name="file", type=File.class)
)
public List<File> getFiles() {
return files;
}
public void setFiles(List files) {
this.files = files;
}
}
public class File {
private List<String> tPathList;
private List<String> oPathList;
#XmlElement(name="xferStatus")
public int getXferStatus() {...}
public void setXferStatus(int xferStatus) {...}
#XmlElement(name="size")
public int getSize() {...}
public void setSize(int size) {...}
#XmlElement(name="tPath")
public String gettPath() {...}
public void settPath(String tPath) {...}
#XmlElement(name="oPath")
public String getoPath() {...}
public void setoPath(String oPath) {...}
#XmlElementWrapper(name="tPathList")
#XmlElements(
#XmlElement(name="tPath", type=String.class)
)
public List gettPathList() {
return tPathList;
}
public void settPathList(List tPathList) {...}
#XmlElementWrapper(name="oPathList")
#XmlElements(
#XmlElement(name="oPath", type=String.class)
)
public List getoPathList() {
return oPathList;
}
public void setoPathList(List oPathList) {
this.oPathList = oPathList;
}
}
Problem is solved by OP himself, adding it as an answer.
Found the problem. If it helps anyone:
setFiles(List files) in File class, should be setFiles(List<File> files).
I also had the same exception. but the solution was different. I share it here, for future problem solvers. When you invoke JAXBContext.newInstance(), have a look at the returned object.
Usually it should be of type com.sun.xml.bind.v2.runtime.JAXBContextImpl. However if it comes from some glassfish3 library like:
jar:file.../glassfish3/glassfish/modules/jaxb-osgi.jar
that threw me the same exception. A changed the order of classpath, and finally the unmarshalling worked fine, if the JAXBContext.newInstance() finds the first implementing JAXBContext class from this jar:
jar:file:.../.m2/repository/com/sun/xml/bind/jaxb-impl/2.x.x/jaxb-impl-2.x.x.jar

Resources