List of usage examples for org.apache.thrift.transport THttpClient close
public void close()
From source file:org.apache.hadoop.hbase.thrift.HttpDoAsClient.java
License:Apache License
private void run() throws Exception { TTransport transport = new TSocket(host, port); transport.open();/*from w w w.j a v a2s . c o m*/ String url = "http://" + host + ":" + port; THttpClient httpClient = new THttpClient(url); httpClient.open(); TProtocol protocol = new TBinaryProtocol(httpClient); Hbase.Client client = new Hbase.Client(protocol); byte[] t = bytes("demo_table"); // // Scan all tables, look for the demo table and delete it. // System.out.println("scanning tables..."); for (ByteBuffer name : refresh(client, httpClient).getTableNames()) { System.out.println(" found: " + utf8(name.array())); if (utf8(name.array()).equals(utf8(t))) { if (refresh(client, httpClient).isTableEnabled(name)) { System.out.println(" disabling table: " + utf8(name.array())); refresh(client, httpClient).disableTable(name); } System.out.println(" deleting table: " + utf8(name.array())); refresh(client, httpClient).deleteTable(name); } } // // Create the demo table with two column families, entry: and unused: // ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>(); ColumnDescriptor col; col = new ColumnDescriptor(); col.name = ByteBuffer.wrap(bytes("entry:")); col.timeToLive = Integer.MAX_VALUE; col.maxVersions = 10; columns.add(col); col = new ColumnDescriptor(); col.name = ByteBuffer.wrap(bytes("unused:")); col.timeToLive = Integer.MAX_VALUE; columns.add(col); System.out.println("creating table: " + utf8(t)); try { refresh(client, httpClient).createTable(ByteBuffer.wrap(t), columns); } catch (AlreadyExists ae) { System.out.println("WARN: " + ae.message); } System.out.println("column families in " + utf8(t) + ": "); Map<ByteBuffer, ColumnDescriptor> columnMap = refresh(client, httpClient) .getColumnDescriptors(ByteBuffer.wrap(t)); for (ColumnDescriptor col2 : columnMap.values()) { System.out.println( " column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions)); } transport.close(); httpClient.close(); }
From source file:org.apache.hadoop.hbase.thrift.TestThriftHttpServer.java
License:Apache License
private void talkToThriftServer() throws Exception { THttpClient httpClient = new THttpClient("http://" + HConstants.LOCALHOST + ":" + port); httpClient.open();/* ww w . j a v a 2 s . c om*/ try { TProtocol prot; prot = new TBinaryProtocol(httpClient); Hbase.Client client = new Hbase.Client(prot); if (!tableCreated) { TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } finally { httpClient.close(); } }
From source file:org.apache.hadoop.hbase.thrift2.TestThrift2HttpServer.java
License:Apache License
@Override protected void talkToThriftServer(String url, int customHeaderSize) throws Exception { THttpClient httpClient = new THttpClient(url); httpClient.open();/* w w w.j a v a2 s. com*/ if (customHeaderSize > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < customHeaderSize; i++) { sb.append("a"); } httpClient.setCustomHeader("User-Agent", sb.toString()); } try { TProtocol prot; prot = new TBinaryProtocol(httpClient); THBaseService.Client client = new THBaseService.Client(prot); TTableName tTableName = new TTableName(); tTableName.setNs(Bytes.toBytes("")); tTableName.setQualifier(Bytes.toBytes(TABLENAME)); if (!tableCreated) { Assert.assertTrue(!client.tableExists(tTableName)); TTableDescriptor tTableDescriptor = new TTableDescriptor(); tTableDescriptor.setTableName(tTableName); TColumnFamilyDescriptor columnFamilyDescriptor = new TColumnFamilyDescriptor(); columnFamilyDescriptor.setName(Bytes.toBytes(TABLENAME)); tTableDescriptor.addToColumns(columnFamilyDescriptor); client.createTable(tTableDescriptor, new ArrayList<>()); tableCreated = true; } Assert.assertTrue(client.tableExists(tTableName)); } finally { httpClient.close(); } }
From source file:org.simbasecurity.client.filter.SimbaFilter.java
License:Apache License
private void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws ServletException, IOException { if (isUrlExcluded(request)) { chain.doFilter(request, response); return;// w w w.j av a2 s .c o m } RequestData requestData = RequestUtil.createRequestData(request, simbaWebURL, simbeEidSuccessUrl); FilterActionFactory actionFactory = new FilterActionFactory(request, response, chain); THttpClient tHttpClient = null; try { tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL()); TProtocol tProtocol = new TJSONProtocol(tHttpClient); AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client( tProtocol); ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, authenticationChainName); actionFactory.execute(actionDescriptor); } catch (Exception e) { throw new ServletException(e); } finally { if (tHttpClient != null) { tHttpClient.close(); } } }
From source file:org.simbasecurity.client.interceptor.SimbaJAXWSHandler.java
License:Apache License
@Override public boolean handleMessage(final SOAPMessageContext context) { if (isInboundMessage(context)) { try {/*from w w w. j ava 2 s .co m*/ final SOAPHeader header = context.getMessage().getSOAPHeader(); final HttpServletRequest httpServletRequest = (HttpServletRequest) context .get(MessageContext.SERVLET_REQUEST); final ServletContext servletContext = (ServletContext) context.get(MessageContext.SERVLET_CONTEXT); final RequestData requestData = RequestUtil.createWSSERequestData(httpServletRequest, header, getSimbaWebURL(servletContext)); THttpClient tHttpClient = null; try { tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL()); TProtocol tProtocol = new TJSONProtocol(tHttpClient); AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client( tProtocol); ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, "wsLoginChain"); if (!actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL)) { throw new SimbaWSAuthenticationException("Authentication Failed"); } String username = actionDescriptor.getPrincipal(); Principal principal = null; if (username != null) { principal = new UserPrincipal(username); } if (principal != null) { context.put(SimbaPrincipal.SIMBA_USER_CTX_KEY, principal); context.setScope(SimbaPrincipal.SIMBA_USER_CTX_KEY, MessageContext.Scope.APPLICATION); } } finally { if (tHttpClient != null) { tHttpClient.close(); } } } catch (Exception e) { throw new SimbaWSAuthenticationException("Authentication Failed", e); } } return true; }
From source file:org.simbasecurity.client.rest.jersey.JerseyBasicAuthenticationFilter.java
License:Apache License
@Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { ContainerRequest containerRequest = (ContainerRequest) containerRequestContext.getRequest(); Map<String, String> requestParameters = toMap(containerRequestContext.getUriInfo().getQueryParameters()); List<String> auth = containerRequest.getRequestHeader("authorization"); if (auth == null || auth.isEmpty()) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); }/*from w w w. j a v a2 s.c o m*/ String[] credentials = decode(auth.get(0)); requestParameters.put(AuthenticationConstants.USERNAME, credentials[0]); requestParameters.put(AuthenticationConstants.PASSWORD, credentials[1]); RequestData requestData = new RequestData(requestParameters, toMap(containerRequest.getRequestHeaders()), containerRequest.getAbsolutePath().toString(), simbaWebURL, null /* SSO Token */, null /* Client IP */, false, false, false, false, false, containerRequest.getMethod(), RequestUtil.HOST_SERVER_NAME, null, null); THttpClient tHttpClient = null; try { tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL()); TProtocol tProtocol = new TJSONProtocol(tHttpClient); AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client( tProtocol); ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, "wsLoginChain"); if (!actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL)) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } } catch (Exception e) { e.printStackTrace(); throw new WebApplicationException(e, Response.Status.UNAUTHORIZED); } finally { if (tHttpClient != null) { tHttpClient.close(); } } }
From source file:org.simbasecurity.servlet.FeedingServlet.java
License:Apache License
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { THttpClient tHttpClient = null; try {/* w ww . j a va 2 s . c om*/ tHttpClient = new THttpClient( SystemConfiguration.getSimbaServiceURL(getServletContext()) + "/authorizationService"); TProtocol tProtocol = new TJSONProtocol(tHttpClient); AuthorizationService.Client authorizationClient = new AuthorizationService.Client(tProtocol); PolicyDecision decision = authorizationClient .isResourceRuleAllowed(request.getUserPrincipal().getName(), "ANIMAL", "WRITE"); if (!decision.isAllowed()) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } response.sendRedirect("jsp/feeding.jsp"); } catch (Exception e) { throw new ServletException(e); } finally { if (tHttpClient != null) { tHttpClient.close(); } } }
From source file:org.wso2.carbon.identity.entitlement.pep.agent.thrift.Authenticator.java
License:Open Source License
private boolean authenticate() throws Exception { boolean isAuthenticated; try {//from www . ja va 2 s. com THttpClient client = new THttpClient(serverUrl); TProtocol protocol = new TCompactProtocol(client); AuthenticatorService.Client authClient = new AuthenticatorService.Client(protocol); client.open(); sessionId = authClient.authenticate(userName, password); client.close(); isAuthenticated = true; } catch (TException e) { throw new EntitlementAgentException("Error while authenticating with ThriftAuthenticator", e); } return isAuthenticated; }
From source file:org.wso2.carbon.identity.entitlement.proxy.thrift.Authenticator.java
License:Open Source License
private boolean authenticate() throws EntitlementProxyException { boolean isAuthenticated; try {/*from ww w . ja v a 2 s. com*/ THttpClient client = new THttpClient(serverUrl); TProtocol protocol = new TCompactProtocol(client); AuthenticatorService.Client authClient = new AuthenticatorService.Client(protocol); client.open(); sessionId = authClient.authenticate(userName, password); client.close(); isAuthenticated = true; } catch (Exception e) { throw new EntitlementProxyException("Error while authenticating with ThriftAuthenticator", e); } return isAuthenticated; }