Search in sources :

Example 16 with Logger

use of java.util.logging.Logger in project jersey by jersey.

the class HttpUrlConnector method _apply.

private ClientResponse _apply(final ClientRequest request) throws IOException {
    final HttpURLConnection uc;
    uc = this.connectionFactory.getConnection(request.getUri().toURL());
    uc.setDoInput(true);
    final String httpMethod = request.getMethod();
    if (request.resolveProperty(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, setMethodWorkaround)) {
        setRequestMethodViaJreBugWorkaround(uc, httpMethod);
    } else {
        uc.setRequestMethod(httpMethod);
    }
    uc.setInstanceFollowRedirects(request.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true));
    uc.setConnectTimeout(request.resolveProperty(ClientProperties.CONNECT_TIMEOUT, uc.getConnectTimeout()));
    uc.setReadTimeout(request.resolveProperty(ClientProperties.READ_TIMEOUT, uc.getReadTimeout()));
    secureConnection(request.getClient(), uc);
    final Object entity = request.getEntity();
    if (entity != null) {
        RequestEntityProcessing entityProcessing = request.resolveProperty(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class);
        if (entityProcessing == null || entityProcessing != RequestEntityProcessing.BUFFERED) {
            final long length = request.getLengthLong();
            if (fixLengthStreaming && length > 0) {
                // uc.setFixedLengthStreamingMode(long) was introduced in JDK 1.7 and Jersey client supports 1.6+
                if ("1.6".equals(Runtime.class.getPackage().getSpecificationVersion())) {
                    uc.setFixedLengthStreamingMode(request.getLength());
                } else {
                    uc.setFixedLengthStreamingMode(length);
                }
            } else if (entityProcessing == RequestEntityProcessing.CHUNKED) {
                uc.setChunkedStreamingMode(chunkSize);
            }
        }
        uc.setDoOutput(true);
        if ("GET".equalsIgnoreCase(httpMethod)) {
            final Logger logger = Logger.getLogger(HttpUrlConnector.class.getName());
            if (logger.isLoggable(Level.INFO)) {
                logger.log(Level.INFO, LocalizationMessages.HTTPURLCONNECTION_REPLACES_GET_WITH_ENTITY());
            }
        }
        request.setStreamProvider(contentLength -> {
            setOutboundHeaders(request.getStringHeaders(), uc);
            return uc.getOutputStream();
        });
        request.writeEntity();
    } else {
        setOutboundHeaders(request.getStringHeaders(), uc);
    }
    final int code = uc.getResponseCode();
    final String reasonPhrase = uc.getResponseMessage();
    final Response.StatusType status = reasonPhrase == null ? Statuses.from(code) : Statuses.from(code, reasonPhrase);
    final URI resolvedRequestUri;
    try {
        resolvedRequestUri = uc.getURL().toURI();
    } catch (URISyntaxException e) {
        throw new ProcessingException(e);
    }
    ClientResponse responseContext = new ClientResponse(status, request, resolvedRequestUri);
    responseContext.headers(uc.getHeaderFields().entrySet().stream().filter(stringListEntry -> stringListEntry.getKey() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    responseContext.setEntityStream(getInputStream(uc));
    return responseContext;
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) RequestEntityProcessing(org.glassfish.jersey.client.RequestEntityProcessing) URISyntaxException(java.net.URISyntaxException) Logger(java.util.logging.Logger) URI(java.net.URI) ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) HttpURLConnection(java.net.HttpURLConnection) ProcessingException(javax.ws.rs.ProcessingException)

Example 17 with Logger

use of java.util.logging.Logger in project jersey by jersey.

the class JerseyTest method unregisterLogHandler.

/**
     * Un-register {@link Handler log handler} from the list of root loggers.
     */
private void unregisterLogHandler() {
    for (final Logger root : getRootLoggers()) {
        root.setLevel(logLevelMap.get(root));
        root.removeHandler(getLogHandler());
    }
    logHandler = null;
}
Also used : Logger(java.util.logging.Logger)

Example 18 with Logger

use of java.util.logging.Logger in project jersey by jersey.

the class JerseyTest method registerLogHandler.

/**
     * Register {@link Handler log handler} to the list of root loggers.
     */
private void registerLogHandler() {
    final String recordLogLevel = getProperty(TestProperties.RECORD_LOG_LEVEL);
    final int recordLogLevelInt = Integer.valueOf(recordLogLevel);
    final Level level = Level.parse(recordLogLevel);
    logLevelMap.clear();
    for (final Logger root : getRootLoggers()) {
        logLevelMap.put(root, root.getLevel());
        if (root.getLevel().intValue() > recordLogLevelInt) {
            root.setLevel(level);
        }
        root.addHandler(getLogHandler());
    }
}
Also used : Level(java.util.logging.Level) Logger(java.util.logging.Logger)

Example 19 with Logger

use of java.util.logging.Logger in project graphdb by neo4j-attic.

the class XaResourceManager method checkXids.

synchronized void checkXids() throws IOException {
    msgLog.logMessage("XaResourceManager[" + name + "] sorting " + xidMap.size() + " xids");
    Iterator<Xid> keyIterator = xidMap.keySet().iterator();
    LinkedList<Xid> xids = new LinkedList<Xid>();
    while (keyIterator.hasNext()) {
        xids.add(keyIterator.next());
    }
    // comparator only used here
    Collections.sort(xids, new Comparator<Xid>() {

        public int compare(Xid o1, Xid o2) {
            Integer id1 = txOrderMap.get(o1);
            Integer id2 = txOrderMap.get(o2);
            if (id1 == null && id2 == null) {
                return 0;
            }
            if (id1 == null) {
                return Integer.MAX_VALUE;
            }
            if (id2 == null) {
                return Integer.MIN_VALUE;
            }
            return id1 - id2;
        }
    });
    // = null;
    txOrderMap.clear();
    Logger logger = Logger.getLogger(tf.getClass().getName());
    while (!xids.isEmpty()) {
        Xid xid = xids.removeFirst();
        XidStatus status = xidMap.get(xid);
        TransactionStatus txStatus = status.getTransactionStatus();
        XaTransaction xaTransaction = txStatus.getTransaction();
        int identifier = xaTransaction.getIdentifier();
        if (xaTransaction.isRecovered()) {
            if (txStatus.commitStarted()) {
                logger.fine("Marking 1PC [" + name + "] tx " + identifier + " as done");
                log.doneInternal(identifier);
                xidMap.remove(xid);
                recoveredTxCount--;
            } else if (!txStatus.prepared()) {
                logger.fine("Rolling back non prepared tx [" + name + "]" + "txIdent[" + identifier + "]");
                log.doneInternal(xaTransaction.getIdentifier());
                xidMap.remove(xid);
                recoveredTxCount--;
            } else {
                logger.fine("2PC tx [" + name + "] " + txStatus + " txIdent[" + identifier + "]");
            }
        }
    }
    checkIfRecoveryComplete();
}
Also used : Xid(javax.transaction.xa.Xid) Logger(java.util.logging.Logger) StringLogger(org.neo4j.kernel.impl.util.StringLogger) LinkedList(java.util.LinkedList)

Example 20 with Logger

use of java.util.logging.Logger in project graphdb by neo4j-attic.

the class TestNeo4jConstrains method testIllegalPropertyType.

@Test
public void testIllegalPropertyType() {
    Logger log = Logger.getLogger(NodeManager.class.getName());
    Level level = log.getLevel();
    log.setLevel(Level.OFF);
    try {
        Node node1 = getGraphDb().createNode();
        try {
            node1.setProperty(key, new Object());
            fail("Shouldn't validate");
        } catch (Exception e) {
        // good
        }
        try {
            Transaction tx = getTransaction();
            tx.success();
            tx.finish();
            fail("Shouldn't validate");
        } catch (Exception e) {
        }
        // good
        setTransaction(getGraphDb().beginTx());
        try {
            getGraphDb().getNodeById(node1.getId());
            fail("Node should not exist, previous tx didn't rollback");
        } catch (NotFoundException e) {
        // good
        }
        node1 = getGraphDb().createNode();
        Node node2 = getGraphDb().createNode();
        Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
        try {
            rel.setProperty(key, new Object());
            fail("Shouldn't validate");
        } catch (Exception e) {
        // good
        }
        try {
            Transaction tx = getTransaction();
            tx.success();
            tx.finish();
            fail("Shouldn't validate");
        } catch (Exception e) {
        }
        // good
        setTransaction(getGraphDb().beginTx());
        try {
            getGraphDb().getNodeById(node1.getId());
            fail("Node should not exist, previous tx didn't rollback");
        } catch (NotFoundException e) {
        // good
        }
        try {
            getGraphDb().getNodeById(node2.getId());
            fail("Node should not exist, previous tx didn't rollback");
        } catch (NotFoundException e) {
        // good
        }
    } finally {
        log.setLevel(level);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Level(java.util.logging.Level) Logger(java.util.logging.Logger) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Aggregations

Logger (java.util.logging.Logger)362 LogRecord (java.util.logging.LogRecord)43 Test (org.junit.Test)41 Handler (java.util.logging.Handler)35 File (java.io.File)18 IOException (java.io.IOException)18 ConsoleHandler (java.util.logging.ConsoleHandler)15 SimpleFormatter (java.util.logging.SimpleFormatter)15 Level (java.util.logging.Level)11 LogManager (java.util.logging.LogManager)10 ArrayList (java.util.ArrayList)8 StreamHandler (java.util.logging.StreamHandler)8 ResourceBundle (java.util.ResourceBundle)7 MockResponse (com.google.mockwebserver.MockResponse)6 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 FileHandler (java.util.logging.FileHandler)5 TestLogHandler (com.google.common.testing.TestLogHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4