But connect to my localhost web server from Android Emulator is working fine.
I used the OAUTH
for security and used Spring RESTful
Web Service in web server.
My android stuff for connection config:
public static final String API_HOST = "http://192.168.x.x:8080/"; //this is my pc ip address, (test with 10.0.2.2 but no work)
public static final String API_BASE_URI = API_HOST + "MyProject/api/v1/";
public static final String API_OAUTH_URI = API_HOST + "MyProject/oauth/";
public static final String API_CLIENT_ID = "abrer112";
public static final String API_CLIENT_SECRET = "a12101!#*$JE4323";
public static final int API_HTTP_STATUS_SUCCESS = 200;
public static final int API_HTTP_STATUS_UNAUTHORISED = 401;
public static final int API_HTTP_STATUS_BAD_REQUEST = 400;
public static final int API_HTTP_STATUS_UNPROCESSABLE_ENTITY = 422;
public static final String API_OAUTH_HEADER_AUTH_PREFIX = "Bearer ";
// ROLES
public static final String ROLE_ADMIN = "ADMIN";
public static final String ROLE_MANAGER = "MANAGER";
public static final String ROLE_USER = "USER";
Server settings:
my xml file:
<!-- Protect API URIs with ROLES -->
<sec:http pattern="/api/v1/**" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint" auto-config="true"
use-expressions="true">
<sec:anonymous enabled="false" />
<sec:intercept-url pattern="/api/v1/admin/**" access="hasRole('ADMIN')" />
<sec:intercept-url pattern="/api/v1/manager/**"
access="hasRole('MANAGER') or hasRole('ADMIN')" />
<sec:intercept-url pattern="/api/v1/user/**"
access="hasRole('USER') or hasRole('MANAGER') or hasRole('ADMIN')" />
<sec:custom-filter ref="resourceServerFilter"
before="PRE_AUTH_FILTER" />
<sec:access-denied-handler ref="oauthAccessDeniedHandler" />
</sec:http>
Java file: eg:
@RestController
@RequestMapping("/user/passwords")
public class ChangePasswordController {
All connection and settings are very fine and I can always connect this web server from Android Studio Emulator
but can't connect from Android app
and Android Studio USB Devices.
Is there something I missed to do? Any help appreciated.
Note: possible duplicate at this ?? But I can't figure out the solution. Appreciated for any help!