public static void main(String[] args) { String response; String filetoUpload; if (args.length == 1) filetoUpload = args[0]; else filetoUpload = "/Users/aditya/Downloads/poc.pdf"; // Load the Properties Files Configs.loadProperties(); // Create a Entity Document which stores the details of the File EntityDocument entDoc = new EntityDocument("Twitter", Configs.getFolderId(), "png"); // Prepare the Post Request to be sent PostRequestBuilder req = new PostRequestBuilder(filetoUpload, entDoc); try { HttpService.uploadDoc(req.preparePostRequest()); // Read the Response received response = HttpService.readResponse(); // Convert to SFDCResponse Instance SFDCResponse sr = SFDCResponse.convertResponse(response); } catch (ClientProtocolException e) { // TODO Auto-generated catch block System.out.println("Error while sending the Post Request : "); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("Error while sending the Post Request : "); e.printStackTrace(); } }
/** {@inheritDoc} */ public Object addingService(ServiceReference reference) { HttpService service = (HttpService) context.getService(reference); try { service.registerServlet( getServletAlias(), new JolokiaServlet(context, restrictor), getConfiguration(), getHttpContext()); } catch (ServletException e) { logError("Servlet Exception: " + e, e); } catch (NamespaceException e) { logError("Namespace Exception: " + e, e); } return service; }
/** * Test method for {@link * masquerade.sim.client.MasqueradeHttpClient#dynamicResponseScript(java.lang.String, * java.util.List)}. */ @Test public void testProvideResponseScript() { String content = "<steps>\n" + " <masquerade.sim.model.CopyRequestToResponseStep>\n" + " <name>copy</name>\n" + " </masquerade.sim.model.CopyRequestToResponseStep>\n" + " <masquerade.sim.model.impl.step.RenameXmlNodeStep>\n" + " <name>rename</name>\n" + " <substituteVariables>true</substituteVariables>\n" + " <namespaceURI>http://example.com/ns</namespaceURI>\n" + " <newQualifiedName>ns:newName</newQualifiedName>\n" + " <selectNodeXpath>/</selectNodeXpath>\n" + " </masquerade.sim.model.impl.step.RenameXmlNodeStep>\n" + "</steps>"; httpService.post("api/dynamicResponseScript/123", content); replay(httpService); List<SimulationStep> steps = new LinkedList<SimulationStep>(); steps.add(new CopyRequestToResponseStep("copy")); steps.add(new RenameXmlNodeStep("rename")); client.dynamicResponseScript("123", steps); verify(httpService); }
@Override protected HttpResponse doInBackground(JSONObject... jsonObjects) { // Enviar a requisição HTTP via GET. HttpResponse response = HttpService.sendJsonPostRequest("/reserva/cadastrar", jsonObjects[0]); return response; }
public Long create(Long contactId, String body) throws HubSpotException { HSEngagement engagement = new HSEngagement(HSEngagement.Type.NOTE, contactId, body); String url = "/engagements/v1/engagements"; JSONObject jsonNode = (JSONObject) httpService.postRequest(url, engagement.toString()); return jsonNode.getJSONObject("engagement").getLong("id"); }
/** * Test method for {@link * masquerade.sim.client.MasqueradeHttpClient#removeResponseScripts(java.lang.String)}. */ @Test public void testRemoveResponseScripts() { expect(httpService.get("api/removeResponseScripts/123")).andReturn(""); replay(httpService); client.removeResponseScripts("123"); verify(httpService); }
private @Nullable FullHttpResponse handleHttpService( ChannelHandlerContext ctx, FullHttpRequest request, HttpService httpService) throws Exception { if (!httpSessionManager.hasReadAccess(request) && !(httpService instanceof UnauthenticatedHttpService)) { return handleNotAuthenticated(request); } boolean isGetRequest = request.method().name().equals(HttpMethod.GET.name()); if (!isGetRequest && !httpSessionManager.hasAdminAccess(request)) { return handleNotAuthorized(); } return httpService.handleRequest(ctx, request); }
/** * Test method for {@link * masquerade.sim.client.MasqueradeHttpClient#listRequests(java.lang.String)}. */ @Test public void testListRequests() { String firstPart = "abc\n" + "<bla/>"; String secondPart = "def"; String str = "------=_Part_0_227383376.1318946202703\n" + "X-Masquerade-RequestId: requestId-123\n" + "X-Masquerade-RequestTimestamp: 1970-01-01T01:00:00.000\n" + "X-Masquerade-RequestTime: 0\n" + "X-Masquerade-ReceiveTime: 0\n" + "X-Masquerade-ProcessingPeriod: 123\n" + "X-Masquerade-ChannelName: channelName-foo\n" + "X-Masquerade-ClientInfo: clientInfo-abc\n" + "\n" + firstPart + "\n" + "------=_Part_0_227383376.1318946202703\n" + "X-Masquerade-RequestId: requestId-456\n" + "X-Masquerade-RequestTimestamp: 1970-01-01T01:00:00.000\n" + "X-Masquerade-RequestTime: 0\n" + "X-Masquerade-ReceiveTime: 0\n" + "X-Masquerade-ProcessingPeriod: 123\n" + "X-Masquerade-ChannelName: channelName-foo\n" + "X-Masquerade-ClientInfo: clientInfo-abc\n" + "\n" + secondPart + "\n" + "------=_Part_0_227383376.1318946202703--\n" + "\n"; InputStream content = new ByteArrayInputStream(str.getBytes()); expect(httpService.getStream("api/listRequests/123")).andReturn(content); replay(httpService); List<Request> requests = client.listRequests("123"); assertEquals(2, requests.size()); assertEquals(firstPart, requests.get(0).getContent()); assertEquals("requestId-123", requests.get(0).getRequestId()); assertEquals("def", requests.get(1).getContent()); assertEquals("requestId-456", requests.get(1).getRequestId()); verify(httpService); }
public void delete(Long engagementId) throws UnirestException, HubSpotException { String url = "/engagements/v1/engagements/" + engagementId; httpService.deleteRequest(url); }
/** {@inheritDoc} */ public void removedService(ServiceReference reference, Object service) { HttpService httpService = (HttpService) service; httpService.unregister(getServletAlias()); }