8

I build a Java Restfull Web Service to be called by ionic apps running on Android Mobil devices.

The code is successfully running on Android 4.4 Mobile.

but not running on any other android mobile devices with os :android lollipop, marshmallow.

webservices web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <display-name>test</display-name>
    <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <!-- <servlet-class>com.sun.jersey.server.impl.container.servlet.ServletAdaptor</servlet-class> -->
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>test</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

Rest webservice code

package test;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

@Path("/test")
public class test_Services
{
    @POST
    @Consumes("application/x-www-form-urlencoded")
    @Path("/insertTest")
    public String InsertTest(String json)
    {
        System.out.println("POST JSON>>>>>>>>>>>>>"+json);
        return json.toString();
    }
}

Rest webservice dependencies

enter image description here

Here is Hybride Application using ionic and angularjs code

$http({
    method: 'POST',                
    url: 'http://mapps.testlab.local:8080/test/test/insertTest',
    data: data,
    headers: {                   
        "Content-Type": "application/x-www-form-urlencoded"
    }
}).then(function successCallback(res) {
}, function errorCallback(err) {           
    deferred.reject(res.err);            
});

When i debug that using chrome on Android lollipop and marshmallow it gives me the following error:

Failed to load resource: net::ERR_NAME_NOT_RESOLVED

Please help me to fix this issue. I am using JAVA using Eclipse Mars.1

user3441151
  • 1,880
  • 6
  • 35
  • 79

2 Answers2

0

you must be doing something wrong. As the method is POST call to server, you can't hit the restService using simple browser and you have to use some browser extension like-POSTMAN in google chrome. First install the extension then call the webUrl using the POSTMAN. If you got some response means your api got called. Now you have to call the right api and debug the api is it working fine or not. This may resolve your issue.

As you were saying you are trying to hit the weburl from android device, but the code provided by you is not at all android source.

Ankush Bist
  • 1,862
  • 1
  • 15
  • 32
0

when i call ping mapps.testlab.local on my pc i get unknown host error meaning that there is no dns server that knows how to translate "mapps.testlab.local" to an ip adress. Do all your android devices have access to a dns-server via wlan-intranet that know "mapps.testlab.local" ? or are the non-working devices connected to the internet that does not know "mapps.testlab.local"?

k3b
  • 14,517
  • 7
  • 53
  • 85