Naresh
Naresh

Reputation: 187

Spring RestTemplate Beginner: The request sent by the client was syntactically incorrect ()

i am trying to access a Rest Resource for which i am able to test using curl id length should be 11 charecters if id's length is less than 11 for example '12345' https://somesite.com:7677/something/id/{id} iam getting 404 HTTP Error from my java code and curl which is as expected

if id's length is equal to 11 and it is invalid id then iam getting the same responce from curl and java

but if i give the valid id which is alredy present by curl i am getting proper json response but when iam trying to access the Rest resource from restTemplate it is showing the error as shown below

The request sent by the client was syntactically incorrect (). and there are no error logs for this request

Iam not able to figure it out from last 2 days, please provide your thoughts on this so that it will eb really help full for me My rest template configuration:

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
        <property name="messageConverters">
            <list>
                <ref bean="jsonHttpMessageConverter" />
            </list>
        </property>
    </bean>

Code which from which iam trying to access is

public List<Account> getAccounts(PersonNumber personNumber) {
        logger.warn("Inside getAccounts of TransferAgreement client");

        String url = "https://somesite.com:7677/something/id/12345";
        logger.warn("URL acessing "+personNumber.toString()+"  URL  "+ url);
       String a = restTemplate.getForObject(url, String.class);
       System.out.println(a);
        return null;
    }

Upvotes: 2

Views: 6119

Answers (2)

sdouglass
sdouglass

Reputation: 2390

Can you set up your development environment so you can set debugging breakpoints in the Spring code? If so, you can set a breakpoint at the last line of AbstractHttpMessageConverter.write(). Assuming you can evaluate Java expressions when your debugger has paused your app at the breakpoint, you should try to get the result of outputMessage.toString(), copy that out of your IDE, and paste it into a text editor. That will show you the JSON that RestTemplate is sending, so you can verify that it really is exactly the same as what you're sending via curl.

Upvotes: 0

ChrLipp
ChrLipp

Reputation: 15668

Assume that you are using Eclipse.

Enable logging for Spring

  • set logging level to debug or trace for Spring, see Logging
  • run your java example
  • add the logging output to your post

I think that enabling logging is enough, I expect an exception within Spring. But additionally, test if a request is executed:

Upvotes: 4

Related Questions