i was trying to create a client server web api where the client calls a web-service say web1 and then web1 becomes a client of another web service say web2. web2 returns to web1 and thus the client executes. my aim is to create a web services composition and print the result as a submission of both web services.
while doing this i encountered this error:
line 1:0 no viable alternative at character 'H'
line 1:1 no viable alternative at character 'e'
line 1:2 no viable alternative at character 'l'
line 1:3 no viable alternative at character 'l'
line 1:4 no viable alternative at character 'o'
line 1:5 no viable alternative at character 'p'
line 1:6 no viable alternative at character 'r'
line 1:7 no viable alternative at character 'i'
line 1:8 no viable alternative at character 'y'
line 1:9 no viable alternative at character 'a'
line 0:-1 no viable alternative at input '<EOF>'
Exception in thread "main" javax.ws.rs.WebApplicationException: HTTP 400 Bad
Request
here 'hello' is the message that should run when i call getMessage() and 'priya' is name called on getName()
the code was:
//client
public class MessageClient {
public static void main(String[] args) {
Client client= ClientBuilder.newClient();
WebTarget baseTarget =
client.target("http://localhost:8080/messenger/webapi");
WebTarget messageTarget = baseTarget.path("messages");
WebTarget singleMsgTarget = messageTarget.path("{messageId}");
Message message1= singleMsgTarget
.resolveTemplate("messageId", "1")
.request()
.get(Message.class);
System.out.println(message1.getMessage());
}
}
//web1 (which is client of web2)
@Path("/messages")
public class MessageResources {
MessageService ms = new MessageService();
@GET
@Path("{messageId}")
@Produces(MediaType.APPLICATION_JSON)
public String getMessage(@PathParam("messageId") long id)
{
Client client= ClientBuilder.newClient();
WebTarget baseTarget=
client.target("http://localhost:8080/messenger/webapi");
WebTarget infoTarget= baseTarget.path("/info");
WebTarget singleInfoTarget= infoTarget.path("{infoId}");
InfoCreated info= singleInfoTarget
.resolveTemplate("infoId", "1")
.request()
.get(InfoCreated.class);
String name = info.getName();
Message message = ms.getMessage(id);
String msg=message.getMessage();
String result = msg.concat(name);
return result;
}
there is no error in the code, but the error appears at runtime.