简体   繁体   中英

java.lang.IllegalArgumentException: URI is not absolute Error in spingboot application

I am trying to call an App1 from App2. Both are in springboot and are hosted in Cloudfoundry. I am getting the below error while doing the process.

java.lang.IllegalArgumentException: URI is not absolute

But when I call the App1 from postman it works perfectly. Also when I call App1(at cloudfoundry) from App2(from localmachine) it works fine.

public class ClassA {
private String app1URL;

public ClassA(ConfigClass config) { 
    this.app1URL= config.getApp1Url();
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    this.rest = new RestTemplate(requestFactory);        
    this.headers = new HttpHeaders();
    headers.add("Accept", "*/*");
}

    public String get(long employeeId, String token) {
      HttpEntity<String> requestEntity = new HttpEntity<>(headers);
      String app1URL = this.app1URL + "employee?employeeid="
            + employeeId+"&access_token=" + token;
      ResponseEntity<String> responseEntity = rest.exchange((app1URL), 
      HttpMethod.GET, requestEntity,String.class);
      return responseEntity.getBody();
}

When I hardcode the app1URL with actual value it works in cloudfoundry.So I suspect some issue with resolving the this.app1URL at cloudfoundry. Stack trace as below:

java.lang.IllegalArgumentException: URI is not absolute
 at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:85) ~[spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.8.REL

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-w

 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-web

 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.8.RELEASE.jar!/:4.3.8.RELE

 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) [spring-security-web-4.2.2.RELEASE.jar!/:4.2

 at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) [spring-security-web-4.2.2.RELEASE.jar!/:

 at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.8.RELEASE.

 at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) [spring-security-web-4.2.2.RELEASE.ja

 at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
 at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) [spring-security-web-4.2.2.RELEASE.jar!/:4.2.2.RE

 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar!/:4.2

 at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) [spring-security-web-4.

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) [spring-security-web-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]
 at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) [spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
 at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) [spring-security-web-4.2.2.RELEASE.j

Temporary solution: I have to hardcode the url in the java code to make it work. Seems the url is not getting resoved from application.properties as well as manifest.yml file(tried both)

Exposure API from one App to an another App, I suppose you might need to enable service discovery and get registered,(like in Eureka Server), as they would be hosted on same space of cloud foundry.

Hope the below link would help you

Pivotal link for service registry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM