This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.ws.rs.client.Client; | |
import javax.ws.rs.client.ClientBuilder; | |
import javax.ws.rs.client.Entity; | |
import javax.ws.rs.client.WebTarget; | |
import javax.ws.rs.core.MediaType; | |
public class MyClient { | |
public static void main(String[] args) { | |
Client client = ClientBuilder.newClient(); | |
WebTarget target = client.target("http://localhost:8080/EntityParameters/Entity/test1"); | |
String response = target.request() | |
.post(Entity.entity("test body", MediaType.APPLICATION_XML), String.class); | |
System.out.println(response); | |
Client client2 = ClientBuilder.newClient(); | |
WebTarget target2 = client.target("http://localhost:8080/EntityParameters/Entity/test1"); | |
String entity = "<myMsg><id>2</id><msg>hello</msg></myMsg>"; | |
String response2 = target.request() | |
.post(Entity.entity(entity, MediaType.APPLICATION_XML), String.class); | |
System.out.println(response); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.ws.rs.Consumes; | |
import javax.ws.rs.POST; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
@Path("/") | |
public class Resources { | |
@Path("/test1") | |
@POST | |
@Consumes(MediaType.APPLICATION_XML) | |
@Produces(MediaType.APPLICATION_XML) | |
public String handle(String entityParam) { | |
System.out.println(entityParam); | |
return "entity parameter: " + entityParam; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependencies> | |
<dependency> | |
<groupId>javax</groupId> | |
<artifactId>javaee-web-api</artifactId> | |
<version>7.0</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.glassfish.jersey.containers</groupId> | |
<artifactId>jersey-container-servlet</artifactId> | |
<version>2.25.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.glassfish.jersey.media</groupId> | |
<artifactId>jersey-media-moxy</artifactId> | |
<version>2.25.1</version> | |
</dependency> | |
</dependencies> |
Bağımlılıkları eklemeyi unutursanız çok sinir bozucu bir hata ile karşılaşırsınız.Aslında ne kadar çok hata ile karşılaşırsanız o kadar iyi öğrenirsiniz.
İYİ ÇALIŞMALAR...
Hiç yorum yok:
Yorum Gönder