org.apache.axis.transport.http.HTTPConstants Java Examples
The following examples show how to use
org.apache.axis.transport.http.HTTPConstants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpHandlerTest.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** Tests that a poorly formed XML response will result in an AxisFault. */ @Test public void testInvokeReturnsInvalidXml() throws AxisFault { MessageContext messageContext = new MessageContext(axisEngine); messageContext.setRequestMessage(requestMessage); messageContext.setProperty(MessageContext.TRANS_URL, mockHttpServer.getServerUrl()); messageContext.setProperty(HTTPConstants.MC_GZIP_REQUEST, true); mockHttpServer.setMockResponse( new MockResponse( "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" + "foo...")); httpHandler.invoke(messageContext); // Expect parsing to fail. Tear down will verify the stream was closed. thrown.expect(AxisFault.class); messageContext.getResponseMessage().getSOAPEnvelope(); }
Example #2
Source File: HttpHandler.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Creates an HTTP request based on the message context. * * @param msgContext the Axis message context * @return a new {@link HttpRequest} with content and headers populated */ private HttpRequest createHttpRequest(MessageContext msgContext) throws SOAPException, IOException { Message requestMessage = Preconditions.checkNotNull( msgContext.getRequestMessage(), "Null request message on message context"); // Construct the output stream. String contentType = requestMessage.getContentType(msgContext.getSOAPConstants()); ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE); if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) { logger.debug("Compressing request"); try (GZIPOutputStream gzipOs = new GZIPOutputStream(bos, BUFFER_SIZE)) { requestMessage.writeTo(gzipOs); } } else { logger.debug("Not compressing request"); requestMessage.writeTo(bos); } HttpRequest httpRequest = requestFactory.buildPostRequest( new GenericUrl(msgContext.getStrProp(MessageContext.TRANS_URL)), new ByteArrayContent(contentType, bos.toByteArray())); int timeoutMillis = msgContext.getTimeout(); if (timeoutMillis >= 0) { logger.debug("Setting read and connect timeout to {} millis", timeoutMillis); // These are not the same, but MessageContext has only one definition of timeout. httpRequest.setReadTimeout(timeoutMillis); httpRequest.setConnectTimeout(timeoutMillis); } // Copy the request headers from the message context to the post request. setHttpRequestHeaders(msgContext, httpRequest); return httpRequest; }
Example #3
Source File: HttpHandler.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** Sets HTTP request headers based on the Axis message context. */ private void setHttpRequestHeaders(MessageContext msgContext, HttpRequest httpRequest) { @SuppressWarnings("unchecked") Map<Object, Object> requestHeaders = (Map<Object, Object>) msgContext.getProperty(HTTPConstants.REQUEST_HEADERS); if (requestHeaders != null) { for (Entry<Object, Object> headerEntry : requestHeaders.entrySet()) { Object headerKey = headerEntry.getKey(); if (headerKey == null) { continue; } String headerName = headerKey.toString().trim(); Object headerValue = headerEntry.getValue(); if (HTTPConstants.HEADER_AUTHORIZATION.equals(headerName) && (headerValue instanceof String)) { // HttpRequest expects the Authorization header to be a list of values, // so handle the case where it is simply a string. httpRequest.getHeaders().setAuthorization((String) headerValue); } else { httpRequest.getHeaders().set(headerName, headerValue); } } } if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) { httpRequest.getHeaders().setContentEncoding(HTTPConstants.COMPRESSION_GZIP); } }
Example #4
Source File: AxisHandler.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * @see SoapClientHandler#putAllHttpHeaders(Object, Map) */ @Override public void putAllHttpHeaders(Stub soapClient, Map<String, String> headersMap) { @SuppressWarnings("unchecked") Hashtable<String, String> headers = (Hashtable<String, String>) soapClient._getProperty(HTTPConstants.REQUEST_HEADERS); if (headers == null) { headers = new Hashtable<String, String>(); } headers.putAll(headersMap); soapClient._setProperty(HTTPConstants.REQUEST_HEADERS, headers); }
Example #5
Source File: HttpHandlerTest.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Tests that a failed, non-XML response results in an AxisFault containing the HTTP status and * message. */ @Test public void testInvokeReturnsNonXmlResponse() throws AxisFault { MessageContext messageContext = new MessageContext(axisEngine); messageContext.setRequestMessage(requestMessage); messageContext.setProperty(MessageContext.TRANS_URL, mockHttpServer.getServerUrl()); messageContext.setProperty(HTTPConstants.MC_GZIP_REQUEST, true); MockResponse mockResponse = new MockResponse("Something went wrong", 500); mockResponse.setContentType("text/html"); mockHttpServer.setMockResponse(mockResponse); // Expect an AxisFault based on the status code and content type. thrown.expect(AxisFault.class); httpHandler.invoke(messageContext); }
Example #6
Source File: HttpHandlerTest.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** Tests that a request with null content type will fail as expected. */ @Test public void testInvokeWithoutContentType() throws AxisFault { MessageContext messageContext = new MessageContext(axisEngine); messageContext.setRequestMessage(requestMessage); messageContext.setProperty(MessageContext.TRANS_URL, mockHttpServer.getServerUrl()); messageContext.setProperty(HTTPConstants.MC_GZIP_REQUEST, true); MockResponse mockResponse = new MockResponse("Something went wrong", 500); mockResponse.setContentType(null); mockHttpServer.setMockResponse(mockResponse); // Expect an AxisFault based on the status code and content type. thrown.expect(AxisFault.class); httpHandler.invoke(messageContext); }
Example #7
Source File: AxisHandler.java From googleads-java-lib with Apache License 2.0 | 4 votes |
/** * Clears all of the SOAP headers from the given SOAP client. * * @param soapClient the client to remove the headers from */ @Override public void clearHeaders(Stub soapClient) { soapClient._setProperty(HTTPConstants.REQUEST_HEADERS, new Hashtable<String, String>()); soapClient.clearHeaders(); }
Example #8
Source File: AxisHandlerTest.java From googleads-java-lib with Apache License 2.0 | 4 votes |
@Test public void testSetCompression_true() { axisHandler.setCompression(stub, true); assertTrue((Boolean) stub._getProperty(HTTPConstants.MC_ACCEPT_GZIP)); assertTrue((Boolean) stub._getProperty(HTTPConstants.MC_GZIP_REQUEST)); }
Example #9
Source File: AxisHandlerTest.java From googleads-java-lib with Apache License 2.0 | 4 votes |
@Test public void testSetCompression_false() { axisHandler.setCompression(stub, false); assertFalse((Boolean) stub._getProperty(HTTPConstants.MC_ACCEPT_GZIP)); assertFalse((Boolean) stub._getProperty(HTTPConstants.MC_GZIP_REQUEST)); }
Example #10
Source File: cfcHandler.java From openbd-core with GNU General Public License v3.0 | 3 votes |
/** * Returns a new cfSession from the specified MessageContext. * * @param msgContext * MessageContext for the current request. * @return a new cfSession from the specified MessageContext */ private cfSession getSession(MessageContext msgContext) { HttpServletRequest req = (HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); HttpServletResponse res = (HttpServletResponse) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE); ServletContext ctxt = req.getSession(true).getServletContext(); return new cfSession(req, res, ctxt); }
Example #11
Source File: cfcHandler.java From openbd-core with GNU General Public License v3.0 | 2 votes |
/** * Registers all the classes associated with the specified CFC generated class * in the specified MessageContext's TypeMapping, for use by Axis. Assumes the * specified DynamicCacheClassLoader is the one responsible for the type/class * being generated and that it has already been linked/associated to dependent * DynamicCacheClassLoader instances. * * @param msgContext * @param dcl */ private void registerClasses(MessageContext msgContext, DynamicCacheClassLoader dcl) { String scm = ((HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST)).getScheme(); dcl.registerClasses(new ContextRegistrar(msgContext, scm)); }
Example #12
Source File: cfcHandler.java From openbd-core with GNU General Public License v3.0 | 2 votes |
/** * Registers all the classes associated with the specified CFC generated class * in the specified MessageContext's TypeMapping, for use by Axis. Assumes the * specified DynamicCacheClassLoader is the one responsible for the type/class * being generated and that it has already been linked/associated to dependent * DynamicCacheClassLoader instances. * * @param msgContext * @param dcl */ private void unregisterClasses(MessageContext msgContext, DynamicCacheClassLoader dcl) { String scm = ((HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST)).getScheme(); dcl.unregisterClasses(new ContextRegistrar(msgContext, scm)); }
Example #13
Source File: AxisHandler.java From googleads-java-lib with Apache License 2.0 | 2 votes |
/** * Set whether SOAP requests should use compression. * * @param soapClient the client to set compression settings for * @param compress whether or not to use compression */ @Override public void setCompression(Stub soapClient, boolean compress) { soapClient._setProperty(HTTPConstants.MC_ACCEPT_GZIP, compress); soapClient._setProperty(HTTPConstants.MC_GZIP_REQUEST, compress); }