use of javax.ws.rs.POST in project quickstarts by jboss-switchyard.
the class ReverseService method reverse.
@POST
@Path("/")
@WebMethod(action = "urn:switchyard-quickstart:camel-soap-proxy:1.0")
@WebResult(name = "text")
public String reverse(@WebParam(name = "text") String text) throws Exception {
if (text.equals("fault")) {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault sf = factory.createFault("myfaultstring", new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server"));
sf.setFaultActor("myFaultActor");
Detail d = sf.addDetail();
QName entryName = new QName("urn:switchyard-quickstart:camel-soap-proxy:1.0", "order", "PO");
DetailEntry entry = d.addDetailEntry(entryName);
QName name = new QName("urn:switchyard-quickstart:camel-soap-proxy:1.0", "symbol");
SOAPElement symbol = entry.addChildElement(name);
symbol.addTextNode("SUNW");
throw new SOAPFaultException(sf);
}
return new StringBuilder(text).reverse().toString();
}
use of javax.ws.rs.POST in project jersey by jersey.
the class MessageBoardResourceBean method addMessage.
@POST
public Response addMessage(String msg) throws URISyntaxException {
Message m = singleton.addMessage(msg);
URI msgURI = ui.getRequestUriBuilder().path(Integer.toString(m.getUniqueId())).build();
return Response.created(msgURI).build();
}
use of javax.ws.rs.POST in project jersey by jersey.
the class BasicClientTest method testAsyncClientInvocation.
@Test
public void testAsyncClientInvocation() throws InterruptedException, ExecutionException {
final WebTarget resource = target().path("resource");
Future<Response> f1 = resource.request().async().post(text("post1"));
final Response response = f1.get();
assertEquals("post1", response.readEntity(String.class));
Future<String> f2 = resource.request().async().post(text("post2"), String.class);
assertEquals("post2", f2.get());
Future<List<JaxbString>> f3 = resource.request().async().get(new GenericType<List<JaxbString>>() {
});
assertEquals(Arrays.asList("a", "b", "c").toString(), f3.get().stream().map(input -> input.value).collect(Collectors.toList()).toString());
CompletableFuture<String> future1 = new CompletableFuture<>();
final TestCallback<Response> c1 = new TestCallback<Response>(future1) {
@Override
protected String process(Response result) {
return result.readEntity(String.class);
}
};
resource.request().async().post(text("post"), c1);
assertEquals("post", future1.get());
CompletableFuture<String> future2 = new CompletableFuture<>();
final TestCallback<String> c2 = new TestCallback<String>(future2) {
@Override
protected String process(String result) {
return result;
}
};
resource.request().async().post(text("post"), c2);
assertEquals("post", future2.get());
CompletableFuture<String> future3 = new CompletableFuture<>();
final TestCallback<List<JaxbString>> c3 = new TestCallback<List<JaxbString>>(future3) {
@Override
protected String process(List<JaxbString> result) {
return result.stream().map(jaxbString -> jaxbString.value).collect(Collectors.toList()).toString();
}
};
resource.request().async().get(c3);
assertEquals(Arrays.asList("a", "b", "c").toString(), future3.get());
}
use of javax.ws.rs.POST in project jersey by jersey.
the class BookmarksResource method postForm.
@POST
@Consumes("application/json")
public Response postForm(JSONObject bookmark) throws JSONException {
final BookmarkEntity bookmarkEntity = new BookmarkEntity(getBookmarkId(bookmark.getString("uri")), userResource.getUserEntity().getUserid());
bookmarkEntity.setUri(bookmark.getString("uri"));
bookmarkEntity.setUpdated(new Date());
bookmarkEntity.setSdesc(bookmark.getString("sdesc"));
bookmarkEntity.setLdesc(bookmark.getString("ldesc"));
userResource.getUserEntity().getBookmarkEntityCollection().add(bookmarkEntity);
TransactionManager.manage(utx, new Transactional(em) {
public void transact() {
em.merge(userResource.getUserEntity());
}
});
URI bookmarkUri = uriInfo.getAbsolutePathBuilder().path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
return Response.created(bookmarkUri).build();
}
use of javax.ws.rs.POST in project jersey by jersey.
the class CdiTransactionalResource method transferMoney.
@POST
public String transferMoney(@QueryParam("from") long from, @QueryParam("to") long to, String amount) {
final Account toAccount = entityManager.find(Account.class, to);
if (toAccount != null) {
try {
toAccount.setBalance(toAccount.getBalance() + Long.decode(amount));
entityManager.merge(toAccount);
final Account fromAccount = entityManager.find(Account.class, from);
fromAccount.setBalance(fromAccount.getBalance() - Long.decode(amount));
if (fromAccount.getBalance() < 0) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Transaction failed. Not enough money on the funding account.").build());
}
entityManager.merge(fromAccount);
return "Transaction sucessful.";
} catch (Exception e) {
if (e instanceof WebApplicationException) {
throw (WebApplicationException) e;
} else {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Something bad happened.").build());
}
}
} else {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Target account not found.").build());
}
}
Aggregations