Search in sources :

Example 1 with ResponseProcessingException

use of jakarta.ws.rs.client.ResponseProcessingException in project resteasy by resteasy.

the class SigningTest method testBadSignatureProxy.

@Test
public void testBadSignatureProxy() throws Exception {
    // ResteasyClientImpl client = new ResteasyClientImpl();
    ResteasyWebTarget target = client.target(generateBaseUrl());
    target.property(KeyRepository.class.getName(), repository);
    SigningProxy proxy = target.proxy(SigningProxy.class);
    try {
        String output = proxy.bad();
        throw new Exception("UNREACHABLE");
    } catch (ResponseProcessingException e) {
        LOG.error(e.getMessage(), e);
    // Assert.assertTrue(e.getCause() instanceof UnauthorizedSignatureException);
    }
}
Also used : KeyRepository(org.jboss.resteasy.security.doseta.KeyRepository) DosetaKeyRepository(org.jboss.resteasy.security.doseta.DosetaKeyRepository) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResponseProcessingException(jakarta.ws.rs.client.ResponseProcessingException) ProcessingException(jakarta.ws.rs.ProcessingException) SignatureException(java.security.SignatureException) ResponseProcessingException(jakarta.ws.rs.client.ResponseProcessingException) UnauthorizedSignatureException(org.jboss.resteasy.security.doseta.UnauthorizedSignatureException) Test(org.junit.Test)

Example 2 with ResponseProcessingException

use of jakarta.ws.rs.client.ResponseProcessingException in project resteasy by resteasy.

the class ClientInvocation method filterResponse.

protected ClientResponse filterResponse(ClientRequestContextImpl requestContext, ClientResponse response) {
    response.setProperties(configuration.getMutableProperties());
    ClientResponseFilter[] responseFilters = getResponseFilters();
    if (responseFilters != null && responseFilters.length > 0) {
        ClientResponseContextImpl responseContext = new ClientResponseContextImpl(response);
        for (ClientResponseFilter filter : responseFilters) {
            try {
                filter.filter(requestContext, responseContext);
            } catch (ResponseProcessingException e) {
                throw e;
            } catch (Throwable e) {
                throw new ResponseProcessingException(response, e);
            }
        }
    }
    return response;
}
Also used : ClientResponseFilter(jakarta.ws.rs.client.ClientResponseFilter) ResponseProcessingException(jakarta.ws.rs.client.ResponseProcessingException)

Example 3 with ResponseProcessingException

use of jakarta.ws.rs.client.ResponseProcessingException in project corese by Wimmics.

the class LogManager method process.

void process(EngineException e) {
    ContextLog log = getLog();
    String sub = DatatypeMap.createBlank().getLabel();
    log.set(sub, "a", REPORT);
    if (e.getURL() != null) {
        log.set(sub, URL, e.getURL().getServer());
        if (e.getURL().hasParameter()) {
            log.set(sub, URL_PARAM, e.getURL().getURL());
        }
    }
    if (e.getCause() instanceof ResponseProcessingException) {
        if (e.getObject() != null && e.getObject() instanceof Response) {
            Response resp = (Response) e.getObject();
            log.set(sub, INFO, resp.getStatusInfo().toString());
            log.set(sub, STATUS, resp.getStatus());
            String serv = getServer(resp);
            if (serv != null) {
                log.set(sub, SERVER, serv);
            }
            if (resp.getHeaderString("Date") != null) {
                log.set(sub, DATE, resp.getHeaderString("Date"));
            }
            trace(e.getURL(), resp);
        }
    }
    log.set(sub, MESSAGE, e.getMessage());
    if (e.getAST() != null) {
        log.set(sub, QUERY, DatatypeMap.genericPointer(e.getAST().toString()));
    }
}
Also used : Response(jakarta.ws.rs.core.Response) ContextLog(fr.inria.corese.sparql.triple.parser.context.ContextLog) ResponseProcessingException(jakarta.ws.rs.client.ResponseProcessingException)

Example 4 with ResponseProcessingException

use of jakarta.ws.rs.client.ResponseProcessingException in project corese by Wimmics.

the class Service method getResponse.

Response getResponse(String url, String mime) {
    logger.info("Service:  " + url + " " + mime);
    clientBuilder.connectTimeout(timeout, TimeUnit.MILLISECONDS);
    Client client = clientBuilder.build();
    WebTarget target = client.target(url);
    Builder build = target.request(mime);
    // Builder build = target.request();
    Response resp = build.get();
    if (resp.getMediaType() != null) {
        recordFormat(resp.getMediaType().toString());
    }
    getCreateReport().setResponse(resp);
    if (resp.getStatus() == Response.Status.SEE_OTHER.getStatusCode() || resp.getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode()) {
        String myUrl = resp.getLocation().toString();
        logger.warn(String.format("Service redirection: %s to: %s", url, myUrl));
        if (myUrl.equals(url)) {
            throw new jakarta.ws.rs.RedirectionException(resp);
        }
        return getResponse(myUrl, mime);
    }
    if (resp.getStatus() >= Response.Status.BAD_REQUEST.getStatusCode()) {
        String res = resp.readEntity(String.class);
        ResponseProcessingException ex = new ResponseProcessingException(resp, res);
        if (isLog() && getLog() != null) {
            // use case: @federate call not within ProviderService
            // log here
            getLog().addException(new EngineException(ex, ex.getMessage()).setURL(getURL()).setObject(ex.getResponse()));
        }
        logger.error("Response status: " + resp.getStatus());
        logger.info("message: " + res);
        throw ex;
    }
    return resp;
}
Also used : Response(jakarta.ws.rs.core.Response) Builder(jakarta.ws.rs.client.Invocation.Builder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) EngineException(fr.inria.corese.sparql.exceptions.EngineException) ResponseProcessingException(jakarta.ws.rs.client.ResponseProcessingException) WebTarget(jakarta.ws.rs.client.WebTarget) RedirectionException(jakarta.ws.rs.RedirectionException) Client(jakarta.ws.rs.client.Client)

Example 5 with ResponseProcessingException

use of jakarta.ws.rs.client.ResponseProcessingException in project corese by Wimmics.

the class QueryProcess method service.

/**
 * Annotated query with a service send query to server
 *
 * @federate <http://dbpedia.org/sparql>
 * select where {}
 * Mapping m may contain Binding which may contain Log
 * use case: xt:sparql("@federate <uri> select where")
 */
Mappings service(Query q, Mapping m) throws EngineException {
    Service serv = new Service(q.getService());
    serv.setBind(getCreateBinding(m));
    serv.setLog(true);
    try {
        return serv.query(q, m);
    } catch (LoadException | ResponseProcessingException ex) {
        throw new EngineException(ex);
    }
}
Also used : EngineException(fr.inria.corese.sparql.exceptions.EngineException) Service(fr.inria.corese.core.load.Service) ResponseProcessingException(jakarta.ws.rs.client.ResponseProcessingException) LoadException(fr.inria.corese.core.load.LoadException)

Aggregations

ResponseProcessingException (jakarta.ws.rs.client.ResponseProcessingException)26 Response (jakarta.ws.rs.core.Response)15 Test (org.junit.jupiter.api.Test)11 IOException (java.io.IOException)7 EngineException (fr.inria.corese.sparql.exceptions.EngineException)4 ProcessingException (jakarta.ws.rs.ProcessingException)4 RedirectionException (jakarta.ws.rs.RedirectionException)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 WebApplicationException (jakarta.ws.rs.WebApplicationException)2 Client (jakarta.ws.rs.client.Client)2 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)2 Builder (jakarta.ws.rs.client.Invocation.Builder)2 WebTarget (jakarta.ws.rs.client.WebTarget)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 PushbackInputStream (java.io.PushbackInputStream)2 ReaderInputStream (org.apache.cxf.io.ReaderInputStream)2 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)2 LoadException (fr.inria.corese.core.load.LoadException)1 Service (fr.inria.corese.core.load.Service)1