Search in sources :

Example 66 with POST

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();
}
Also used : QName(javax.xml.namespace.QName) DetailEntry(javax.xml.soap.DetailEntry) SOAPElement(javax.xml.soap.SOAPElement) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFactory(javax.xml.soap.SOAPFactory) Detail(javax.xml.soap.Detail) Path(javax.ws.rs.Path) WebMethod(javax.jws.WebMethod) POST(javax.ws.rs.POST) WebResult(javax.jws.WebResult)

Example 67 with POST

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();
}
Also used : Message(org.glassfish.jersey.examples.jersey_ejb.entities.Message) URI(java.net.URI) POST(javax.ws.rs.POST)

Example 68 with POST

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());
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ClientConfig(org.glassfish.jersey.client.ClientConfig) Assert.assertNotSame(org.junit.Assert.assertNotSame) Path(javax.ws.rs.Path) Client(javax.ws.rs.client.Client) CompletableFuture(java.util.concurrent.CompletableFuture) Application(javax.ws.rs.core.Application) ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) AsyncInvoker(javax.ws.rs.client.AsyncInvoker) ClientBuilder(javax.ws.rs.client.ClientBuilder) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) JerseyTest(org.glassfish.jersey.test.JerseyTest) InvocationCallback(javax.ws.rs.client.InvocationCallback) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Assert.fail(org.junit.Assert.fail) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) POST(javax.ws.rs.POST) ClientRequestContext(javax.ws.rs.client.ClientRequestContext) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Invocation(javax.ws.rs.client.Invocation) ThreadPoolExecutorProvider(org.glassfish.jersey.spi.ThreadPoolExecutorProvider) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Collectors(java.util.stream.Collectors) Entity.text(javax.ws.rs.client.Entity.text) NotFoundException(javax.ws.rs.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) WriterInterceptorContext(javax.ws.rs.ext.WriterInterceptorContext) Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) WebTarget(javax.ws.rs.client.WebTarget) ClientAsyncExecutor(org.glassfish.jersey.client.ClientAsyncExecutor) Assert.assertEquals(org.junit.Assert.assertEquals) Response(javax.ws.rs.core.Response) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 69 with POST

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();
}
Also used : BookmarkEntity(org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity) URI(java.net.URI) Date(java.util.Date) Transactional(org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 70 with POST

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());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST)

Aggregations

POST (javax.ws.rs.POST)513 Path (javax.ws.rs.Path)360 Consumes (javax.ws.rs.Consumes)242 Produces (javax.ws.rs.Produces)222 ApiOperation (io.swagger.annotations.ApiOperation)133 ApiResponses (io.swagger.annotations.ApiResponses)107 IOException (java.io.IOException)74 URI (java.net.URI)63 WebApplicationException (javax.ws.rs.WebApplicationException)62 Timed (com.codahale.metrics.annotation.Timed)55 Response (javax.ws.rs.core.Response)50 TimedResource (org.killbill.commons.metrics.TimedResource)36 CallContext (org.killbill.billing.util.callcontext.CallContext)35 AuditEvent (org.graylog2.audit.jersey.AuditEvent)33 HashMap (java.util.HashMap)32 BadRequestException (co.cask.cdap.common.BadRequestException)24 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)24 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)23 Account (org.killbill.billing.account.api.Account)22 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)20