Java Code Examples for org.apache.axis.AxisFault

The following examples show how to use org.apache.axis.AxisFault. These examples are extracted from open source projects. 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 Project: openbd-core   Source File: cfcInvoker.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Object invokeCFCFunction(MessageContext msgContext, cfSession session, String cfcName, cfStructData method, Object[] argValues) throws Exception {
	// Create the cfc
	cfComponentData cfc = new cfComponentData(session, cfcName);
	if (cfc == null || cfc.getMetaData() == null || cfc.getMetaData().isEmpty())
		throw new AxisFault(Messages.getMessage("noClassForService00", cfcName));

	// Convert the params
	cfArgStructData args = prepareArgs(session, method, argValues);

	// Execute the cfc
	cfData rtn = invokeComponentMethod(session, method, args, cfc);
	if (rtn == null || rtn instanceof cfNullData)
		return null;
	else {
		return tagUtils.getNatural(rtn, true, true, true);
	}
}
 
Example 2
Source Project: openbd-core   Source File: cfcInvoker.java    License: GNU General Public License v3.0 6 votes vote down vote up
private cfArgStructData prepareArgs(cfSession session, cfStructData method, Object[] argValues) throws AxisFault {
	cfArgStructData rtn = new cfArgStructData();
	if (argValues != null && argValues.length > 0) {
		cfArrayData params = (cfArrayData) method.getData("PARAMETERS");
		if (params == null || params.size() != argValues.length)
			throw new AxisFault("Incorrect number of parameters for method: " + method.getData("NAME").toString());

		for (int i = 1; i <= params.size(); i++) {
			cfData d = null;
			if (argValues[i - 1] instanceof String && tagUtils.isXmlString((String) argValues[i - 1])) {
				try {
					d = cfXmlData.parseXml(argValues[i - 1], true, null);
				} catch (cfmRunTimeException ex) {
					// Do nothing, just move on
				}
			}
			if (d == null) {
				d = tagUtils.convertToCfData(argValues[i - 1]);
			}
			rtn.setData(((cfStructData) params.getElement(i)).getData("NAME").toString(), d);
		}
	}
	return rtn;
}
 
Example 3
Source Project: birt   Source File: BirtUtility.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an axis fault grouping the given exceptions list
 * 
 * @param qName
 *            QName of the fault
 * @param exceptions
 *            list of exceptions
 * @return axis fault
 */
public static Exception makeAxisFault( String qName,
		Collection<Exception> exceptions )
{
	if ( exceptions.size( ) == 1 )
	{
		return makeAxisFault( qName, exceptions.iterator( ).next( ) );
	}
	else
	{
		QName exceptionQName = new QName( "string" );
		AxisFault fault = new AxisFault( BirtResources.getMessage( ResourceConstants.GENERAL_EXCEPTION_MULTIPLE_EXCEPTIONS ) );
		fault.setFaultCode( new QName( qName ) );

		for ( Iterator i = exceptions.iterator( ); i.hasNext( ); )
		{
			Exception e = (Exception) i.next( );
			fault.addFaultDetail( exceptionQName, getStackTrace( e ) );
		}
		return fault;
	}
}
 
Example 4
Source Project: googleads-java-lib   Source File: HttpHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(MessageContext msgContext) throws AxisFault {
  if (msgContext == null) {
    throw AxisFault.makeFault(new NullPointerException("Null message context"));
  }

  // Catch any exception thrown and wrap it in an AxisFault, per the contract of Handler.invoke.
  try {
    HttpResponse response = null;
    // Create the request.
    HttpRequest postRequest = createHttpRequest(msgContext);
    // Execute the request.
    response = postRequest.execute();
    // Translate the HTTP response to an Axis message on the message context.
    msgContext.setResponseMessage(createResponseMessage(response));
  } catch (RuntimeException | SOAPException | IOException e) {
    throw AxisFault.makeFault(e);
  }
}
 
Example 5
Source Project: googleads-java-lib   Source File: HttpHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
/** 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 6
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
	String ns = null;
	String n = null;
	cfData val = null;
	boolean mustUnderstand = false;

	int offset = 0;
	if (parameters.size() == 4) {
		mustUnderstand = parameters.get(0).getBoolean();
		offset = 1;
	}
	val = parameters.get(0 + offset);
	n = parameters.get(1 + offset).getString();
	ns = parameters.get(2 + offset).getString();

	// Create the header
	SOAPHeaderElement header = addSOAPRequestHeader.createSOAPHeader(val, ns, n, mustUnderstand);

	// Add the header
	try {
		MessageContext mc = MessageContext.getCurrentContext();
		if (mc != null && mc.getResponseMessage() != null && mc.getResponseMessage().getSOAPEnvelope() != null) {
			// Check to see if the same header has already been added
			// (same meaning, having the same namespace/name pair)
			if (mc.getResponseMessage().getSOAPEnvelope().getHeaderByName(header.getNamespaceURI(), header.getName()) != null)
				throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError", "SOAP header value: " + header.getNamespaceURI() + ":" + header.getName() + " already set."));
			else
				mc.getResponseMessage().getSOAPEnvelope().addHeader(header);
		} else {
			throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError", "Could not set SOAP header value. MessageContext response message is not available. " + "Be sure this is being called from a CFC web service function."));
		}
	} catch (AxisFault ex) {
		throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
	}
	return cfBooleanData.TRUE;
}
 
Example 7
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
	SOAPHeaderElement header = null;

	String ns = null;
	String n = null;
	boolean asXml = false;

	int offset = 0;
	if (parameters.size() == 3) {
		asXml = parameters.get(0).getBoolean();
		offset = 1;
	}
	n = parameters.get(0 + offset).getString();
	ns = parameters.get(1 + offset).getString();

	// Get the header
	try {
		MessageContext mc = MessageContext.getCurrentContext();
		if (mc != null && mc.getRequestMessage() != null && mc.getRequestMessage().getSOAPEnvelope() != null)
			header = mc.getRequestMessage().getSOAPEnvelope().getHeaderByName(ns, n);
		else
			throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError", "Could not get SOAP header. MessageContext request message is not available. " + "Be sure this is being called from a CFC web service function."));
	} catch (AxisFault ex) {
		throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
	}

	// Convert the header value into the desired cfData type
	return getSOAPHeaderValue(header, asXml);
}
 
Example 8
Source Project: birt   Source File: BirtUtility.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates an axis fault based on a given exception.
 * 
 * @param qName
 *            QName of the fault
 * @param e
 *            exception
 * @return axis fault
 */
public static AxisFault makeAxisFault( Exception e )
{
	if ( e instanceof AxisFault )
	{
		return (AxisFault) e;
	}
	else
	{
		AxisFault fault = AxisFault.makeFault( e );
		fault.addFaultDetailString( BirtUtility.getStackTrace( e ) );
		return fault;
	}
}
 
Example 9
/**
 * Action handler entry point.
 * 
 * @throws Exception
 */
protected void __execute( ) throws Exception
{
	BaseAttributeBean attrBean = (BaseAttributeBean) context.getBean( );
	__docName = attrBean.getReportDocumentName( );
	__checkDocumentExists( );

	List exportedResultSets;
	String instanceID = operation.getTarget( ).getId( );

	InputOptions options = new InputOptions( );
	options.setOption( InputOptions.OPT_REQUEST, context.getRequest( ) );

	if ( instanceID.equals( "Document" ) ) //$NON-NLS-1$
		exportedResultSets = getReportService( ).getResultSetsMetadata(
				__docName, options );
	else
		exportedResultSets = getReportService( ).getResultSetsMetadata(
				__docName, instanceID, options );

	if ( exportedResultSets == null )
	{
		// No result sets available
		AxisFault fault = new AxisFault( );
		fault
				.setFaultReason( BirtResources
						.getMessage( ResourceConstants.REPORT_SERVICE_EXCEPTION_EXTRACT_DATA_NO_RESULT_SET ) );
		throw fault;
	}

	ResultSet[] resultSetArray = getResultSetArray( exportedResultSets );
	ResultSets resultSets = new ResultSets( );
	resultSets.setResultSet( resultSetArray );
	handleUpdate( resultSets );
}
 
Example 10
Source Project: birt   Source File: BirtQueryExportActionHandler.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Implement to check if document file exists
 * 
 * @throws RemoteException
 */
protected void __checkDocumentExists( ) throws RemoteException
{
	File file = new File( __docName );
	if ( !file.exists( ) )
	{
		// if document file doesn't exist, throw exception
		AxisFault fault = new AxisFault( );
		fault
				.setFaultReason( BirtResources
						.getMessage( ResourceConstants.ACTION_EXCEPTION_DOCUMENT_FILE_NO_EXIST ) );
		throw fault;
	}
}
 
Example 11
Source Project: birt   Source File: BirtGetTOCActionHandler.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Implement to check if document file exists
 * 
 * @throws RemoteException
 */
protected void __checkDocumentExists( ) throws RemoteException
{
	File file = new File( __docName );
	if ( !file.exists( ) )
	{
		// if document file doesn't exist, throw exception
		AxisFault fault = new AxisFault( );
		fault
				.setFaultReason( BirtResources
						.getMessage( ResourceConstants.ACTION_EXCEPTION_DOCUMENT_FILE_NO_EXIST ) );
		throw fault;
	}
}
 
Example 12
Source Project: birt   Source File: BaseProcessorFactory.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get processor factory instance.
 * 
 * @return
 * @throws MarshalException
 * @throws ValidationException
 * @throws UnsupportedEncodingException
 * @throws FileNotFoundException
 */
public static synchronized IProcessorFactory getInstance( )
		throws AxisFault
{
	if ( instance != null )
	{
		return instance;
	}

	try
	{
		instance = (IProcessorFactory) Class
				.forName( "com.actuate.common.processor.ProcessorFactory" ).newInstance( ); //$NON-NLS-1$
	}
	catch ( Exception e )
	{
		instance = null;
	}

	if ( instance == null )
	{
		instance = new BaseProcessorFactory( );
	}

	instance.init( );

	return instance;
}
 
Example 13
Source Project: tomee   Source File: EjbRpcProvider.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param msgContext msgContext
 * @param reqEnv reqEnv
 * @param resEnv resEnv
 * @param obj obj
 * @throws Exception
 */
@Override
public void processMessage(MessageContext msgContext, SOAPEnvelope reqEnv, SOAPEnvelope resEnv, Object obj) throws Exception {

    RPCElement body = getBody(reqEnv, msgContext);
    OperationDesc operation = getOperationDesc(msgContext, body);

    AxisRpcInterceptor interceptor = new AxisRpcInterceptor(operation, msgContext);
    SOAPMessage message = msgContext.getMessage();

    try {
        message.getSOAPPart().getEnvelope();
        msgContext.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION, Boolean.FALSE);

        RpcContainer container = (RpcContainer) ejbDeployment.getContainer();

        Object[] arguments = {msgContext, interceptor};

        Class callInterface = ejbDeployment.getServiceEndpointInterface();
        Object result = container.invoke(ejbDeployment.getDeploymentID(), InterfaceType.SERVICE_ENDPOINT, callInterface, operation.getMethod(), arguments, null);

        interceptor.createResult(result);
    } catch (ApplicationException e) {
        interceptor.createExceptionResult(e.getCause());
    } catch (Throwable throwable) {
        throw new AxisFault("Web Service EJB Invocation failed: method " + operation.getMethod(), throwable);
    }
}
 
Example 14
Source Project: tomee   Source File: OperationInfo.java    License: Apache License 2.0 5 votes vote down vote up
public Throwable unwrapFault(RemoteException re) {
    if (re instanceof AxisFault && re.getCause() != null) {
        Throwable t = re.getCause();
        if (operationDesc.getFaultByClass(t.getClass()) != null) {
            return t;
        }
    }
    return re;
}
 
Example 15
Source Project: googleads-java-lib   Source File: HttpHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new Axis Message based on the contents of the HTTP response.
 *
 * @param httpResponse the HTTP response
 * @return an Axis Message for the HTTP response
 * @throws IOException if unable to retrieve the HTTP response's contents
 * @throws AxisFault if the HTTP response's status or contents indicate an unexpected error, such
 *     as a 405.
 */
private Message createResponseMessage(HttpResponse httpResponse) throws IOException, AxisFault {
  int statusCode = httpResponse.getStatusCode();
  String contentType = httpResponse.getContentType();
  // The conditions below duplicate the logic in CommonsHTTPSender and HTTPSender.
  boolean shouldParseResponse =
      (statusCode > 199 && statusCode < 300)
          || (contentType != null
              && !contentType.equals("text/html")
              && statusCode > 499
              && statusCode < 600);
  // Wrap the content input stream in a notifying stream so the stream event listener will be
  // notified when it is closed.
  InputStream responseInputStream =
      new NotifyingInputStream(httpResponse.getContent(), inputStreamEventListener);
  if (!shouldParseResponse) {
    // The contents are not an XML response, so throw an AxisFault with
    // the HTTP status code and message details.
    String statusMessage = httpResponse.getStatusMessage();
    AxisFault axisFault =
        new AxisFault("HTTP", "(" + statusCode + ")" + statusMessage, null, null);
    axisFault.addFaultDetail(
        Constants.QNAME_FAULTDETAIL_HTTPERRORCODE, String.valueOf(statusCode));
    try (InputStream stream = responseInputStream) {
      byte[] contentBytes = ByteStreams.toByteArray(stream);
      axisFault.setFaultDetailString(
          Messages.getMessage(
              "return01", String.valueOf(statusCode), new String(contentBytes, UTF_8)));
    }
    throw axisFault;
  }
  // Response is an XML response. Do not consume and close the stream in this case, since that
  // will happen later when the response is deserialized by Axis (as confirmed by unit tests for
  // this class).
  Message responseMessage =
      new Message(
          responseInputStream, false, contentType, httpResponse.getHeaders().getLocation());
  responseMessage.setMessageType(Message.RESPONSE);
  return responseMessage;
}
 
Example 16
Source Project: googleads-java-lib   Source File: HttpHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 17
Source Project: googleads-java-lib   Source File: HttpHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
/** 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 18
Source Project: googleads-java-lib   Source File: HttpHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
/** Tests that a request with null message context will fail as expected. */
@Test
public void testInvokeWithoutMessageContext() throws AxisFault {
  thrown.expect(AxisFault.class);
  thrown.expectCause(Matchers.<Exception>instanceOf(NullPointerException.class));
  thrown.expectMessage("context");

  httpHandler.invoke(null);
}
 
Example 19
Source Project: googleads-java-lib   Source File: HttpHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
/** Tests that a request with null request on the message context will fail as expected. */
@Test
public void testInvokeWithoutRequestMessage() throws AxisFault {
  MessageContext messageContext = new MessageContext(axisEngine);

  thrown.expect(AxisFault.class);
  thrown.expectCause(Matchers.<Exception>instanceOf(NullPointerException.class));
  thrown.expectMessage("request");

  httpHandler.invoke(messageContext);
}
 
Example 20
Source Project: googleads-java-lib   Source File: HttpHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
/** Tests that a request with null request URL will fail as expected. */
@Test
public void testInvokeWithoutRequestUrl() throws AxisFault {
  MessageContext messageContext = new MessageContext(axisEngine);
  messageContext.setRequestMessage(requestMessage);

  thrown.expect(AxisFault.class);
  thrown.expectCause(Matchers.<Exception>instanceOf(IllegalArgumentException.class));
  thrown.expectMessage("URL");

  httpHandler.invoke(messageContext);
}
 
Example 21
/**
 * Asserts that the axis client's transport configuration matches that of the prototype axis
 * client.
 */
private void assertTransportConfiguration(AxisClient axisClient, AxisClient prototypeAxisClient)
    throws AxisFault {
  for (String transportName : new String[] {"http", "local", "java"}) {
    assertEquals("Pivot handler is not of the expected type",
        getTransport(prototypeAxisClient, transportName).getPivotHandler().getClass(),
        getTransport(axisClient, transportName).getPivotHandler().getClass());
  }
}
 
Example 22
/**
 * Asserts that the axis server's transport configuration matches that of the prototype axis
 * server.
 */
private void assertTransportConfiguration(AxisServer axisServer, AxisServer prototypeAxisServer)
    throws AxisFault {
  assertEquals("Request handler is not of the expected type",
      getTransport(prototypeAxisServer, "http").getRequestHandler().getClass(),
      getTransport(axisServer, "http").getRequestHandler().getClass());

  assertEquals("Response handler is not of the expected type",
      getTransport(prototypeAxisServer, "local").getResponseHandler().getClass(),
      getTransport(axisServer, "local").getResponseHandler().getClass());
}
 
Example 23
/**
 * Utility method for getting the underlying named transport from an AxisEngine and casting it to
 * a TargetedChain.
 */
private TargetedChain getTransport(AxisEngine axisEngine, String transportName) throws AxisFault {
  Handler transport = axisEngine.getTransport(transportName);
  assertNotNull("No " + transportName + " transport returned from the configured engine",
      transport);

  assertTrue("The " + transportName + " transport is not of the expected type",
      transport instanceof TargetedChain);
  return (TargetedChain) transport;
}
 
Example 24
Source Project: birt   Source File: BirtUtility.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Append Error Message with stack trace
 * 
 * @param out
 * @param e
 * @throws IOException
 */
public static void appendErrorMessage( OutputStream out, Exception e )
		throws IOException
{
	StringBuffer message = new StringBuffer( );
	message.append( "<html>\n<head>\n<title>" //$NON-NLS-1$
			+ BirtResources.getMessage( "birt.viewer.title.error" ) //$NON-NLS-1$
			+ "</title>\n" ); //$NON-NLS-1$
	message.append( "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\"/>\n</head>\n" ) //$NON-NLS-1$
			.append( "<body>\n" ); //$NON-NLS-1$

	String errorId = "document.getElementById('error_detail')"; //$NON-NLS-1$
	String errorIcon = "document.getElementById('error_icon')"; //$NON-NLS-1$
	String onClick = "if (" + errorId + ".style.display == 'none') { " //$NON-NLS-1$//$NON-NLS-2$
			+ errorIcon
			+ ".innerHTML = '- '; " + errorId //$NON-NLS-1$
			+ ".style.display = 'block'; }" + "else { " + errorIcon //$NON-NLS-1$//$NON-NLS-2$
			+ ".innerHTML = '+ '; " + errorId //$NON-NLS-1$
			+ ".style.display = 'none'; }"; //$NON-NLS-1$
	message.append( "<div id=\"birt_errorPage\" style=\"color:red\">\n" ) //$NON-NLS-1$
			.append( "<span id=\"error_icon\"  style=\"cursor:pointer\" onclick=\"" //$NON-NLS-1$
					+ onClick
					+ "\" > + </span>\n" ); //$NON-NLS-1$

	String errorMessage = null;
	if ( e instanceof AxisFault )
	{
		errorMessage = ( (AxisFault) e ).getFaultString( );
	}
	else
	{
		errorMessage = e.getLocalizedMessage( );

	}
	if ( errorMessage != null )
	{
		message.append( ParameterAccessor.htmlEncode( errorMessage ) );
	}
	else
	{
		message.append( "Unknown error!" ); //$NON-NLS-1$
	}

	message.append( "<br>\n" ) //$NON-NLS-1$
			.append( "<pre id=\"error_detail\" style=\"display:none;\" >\n" )//$NON-NLS-1$
			.append( ParameterAccessor.htmlEncode( getDetailMessage( e ) ) )
			.append( "</pre>\n" ) //$NON-NLS-1$
			.append( "</div>\n" ) //$NON-NLS-1$
			.append( "</body>\n</html>" ); //$NON-NLS-1$

	out.write( message.toString( ).getBytes( "UTF-8" ) ); //$NON-NLS-1$
	out.flush( );
	out.close( );
}
 
Example 25
Source Project: birt   Source File: PrintUtility.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Execuate Print Job
 * 
 * @param inputStream
 * @param printer
 * @throws ViewerException
 */
public static void execPrint( InputStream inputStream, Printer printer )
		throws RemoteException
{
	if ( inputStream == null || printer == null )
		return;

	// Create print request attribute set
	PrintRequestAttributeSet pas = new HashPrintRequestAttributeSet( );

	// Copies
	if ( printer.isCopiesSupported( ) )
		pas.add( new Copies( printer.getCopies( ) ) );

	// Collate
	if ( printer.isCollateSupported( ) )
		pas.add( printer.isCollate( )
				? SheetCollate.COLLATED
				: SheetCollate.UNCOLLATED );

	// Duplex
	if ( printer.isDuplexSupported( ) )
	{
		switch ( printer.getDuplex( ) )
		{
			case Printer.DUPLEX_SIMPLEX :
				pas.add( Sides.ONE_SIDED );
				break;
			case Printer.DUPLEX_HORIZONTAL :
				pas.add( Sides.DUPLEX );
				break;
			case Printer.DUPLEX_VERTICAL :
				pas.add( Sides.TUMBLE );
				break;
			default :
				pas.add( Sides.ONE_SIDED );
		}
	}

	// Mode
	if ( printer.isModeSupported( ) )
	{
		switch ( printer.getMode( ) )
		{
			case Printer.MODE_MONOCHROME :
				pas.add( Chromaticity.MONOCHROME );
				break;
			case Printer.MODE_COLOR :
				pas.add( Chromaticity.COLOR );
				break;
			default :
				pas.add( Chromaticity.MONOCHROME );
		}
	}

	// Media
	if ( printer.isMediaSupported( ) && printer.getMediaSize( ) != null )
	{
		MediaSizeName mediaSizeName = (MediaSizeName) printer
				.getMediaSizeNames( ).get( printer.getMediaSize( ) );
		if ( mediaSizeName != null )
			pas.add( mediaSizeName );
	}

	try
	{
		PrintService service = printer.getService( );
		synchronized ( service )
		{
			DocPrintJob job = service.createPrintJob( );
			Doc doc = new SimpleDoc( inputStream,
					DocFlavor.INPUT_STREAM.POSTSCRIPT, null );
			job.print( doc, pas );
		}
	}
	catch ( PrintException e )
	{
		AxisFault fault = new AxisFault( e.getLocalizedMessage( ), e );
		fault.setFaultCode( new QName( "PrintUtility.execPrint( )" ) ); //$NON-NLS-1$
		fault.setFaultString( e.getLocalizedMessage( ) );
		throw fault;
	}
}
 
Example 26
Source Project: birt   Source File: AbstractBaseActionHandler.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Paser returned report ids.
 * 
 * @param activeIds
 * @return
 * @throws RemoteException
 */
protected ReportId[] parseReportId( ArrayList activeIds )
		throws RemoteException
{
	if ( activeIds == null || activeIds.size( ) <= 0 )
	{
		return null;
	}

	java.util.Vector ids = new java.util.Vector( );
	for ( int i = 0; i < activeIds.size( ); i++ )
	{
		String id = (String) activeIds.get( i );
		int firstComma = id.indexOf( ',' );
		if ( firstComma == -1 )
		{
			AxisFault fault = new AxisFault( );
			fault.setFaultCode( new QName(
					"DocumentProcessor.parseReportId( )" ) ); //$NON-NLS-1$
			fault.setFaultString( BirtResources.getMessage(
					ResourceConstants.ACTION_EXCEPTION_INVALID_ID_FORMAT,
					new String[]{id} ) );
			throw fault;
		}

		int secondComma = id.indexOf( ',', firstComma + 1 );
		if ( secondComma == -1 )
		{
			secondComma = id.length( );
		}
		String type = id.substring( firstComma + 1, secondComma );
		if ( ReportIdType._Document.equalsIgnoreCase( type )
				|| ReportIdType._Table.equalsIgnoreCase( type )
				|| ReportIdType._Chart.equalsIgnoreCase( type )
				|| ReportIdType._Extended.equalsIgnoreCase( type )
				|| ReportIdType._Label.equalsIgnoreCase( type )
				|| ReportIdType._Group.equalsIgnoreCase( type )
				|| "ColoumnInfo".equalsIgnoreCase( type ) ) //$NON-NLS-1$
		// TODO: emitter need to fix its name.
		{
			ReportId reportId = new ReportId( );
			reportId.setId( id.substring( 0, id.indexOf( ',' ) ) );

			if ( ReportIdType._Document.equalsIgnoreCase( type ) )
			{
				reportId.setType( ReportIdType.Document );
			}
			else if ( ReportIdType._Table.equalsIgnoreCase( type ) )
			{
				reportId.setType( ReportIdType.Table );
			}
			else if ( ReportIdType._Chart.equalsIgnoreCase( type )
					|| ReportIdType._Extended.equalsIgnoreCase( type ) )
			{
				reportId.setType( ReportIdType.Chart );
			}
			else if ( ReportIdType._Label.equalsIgnoreCase( type ) )
			{
				reportId.setType( ReportIdType.Label );
			}
			else if ( ReportIdType._Group.equalsIgnoreCase( type ) )
			{
				reportId.setType( ReportIdType.Group );
			}
			else if ( "ColoumnInfo".equalsIgnoreCase( type ) ) //$NON-NLS-1$
			{
				reportId.setType( ReportIdType.ColumnInfo );
			}

			try
			{
				reportId.setRptElementId( Long.valueOf( Long.parseLong( id
						.substring( secondComma + 1 ) ) ) );
			}
			catch ( Exception e )
			{
				reportId.setRptElementId( null );
			}

			ids.add( reportId );
		}
	}

	ReportId[] reportIds = new ReportId[ids.size( )];
	for ( int i = 0; i < ids.size( ); i++ )
	{
		reportIds[i] = (ReportId) ids.get( i );
	}

	return reportIds;
}
 
Example 27
Source Project: tomee   Source File: GenericServiceEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
Call createCall() throws java.rmi.RemoteException {
        try {
            org.apache.axis.client.Call _call =
                (org.apache.axis.client.Call) service.createCall();
            if (super.maintainSessionSet) {
                _call.setMaintainSession(super.maintainSession);
            }
            if (super.cachedUsername != null) {
                _call.setUsername(super.cachedUsername);
            }
            if (super.cachedPassword != null) {
                _call.setPassword(super.cachedPassword);
            }
            if (super.cachedEndpoint != null) {
                _call.setTargetEndpointAddress(super.cachedEndpoint);
            }
            if (super.cachedTimeout != null) {
                _call.setTimeout(super.cachedTimeout);
            }
            if (super.cachedPortName != null) {
                _call.setPortName(super.cachedPortName);
            }
            java.util.Enumeration keys = super.cachedProperties.keys();
            while (keys.hasMoreElements()) {
                java.lang.String key = (java.lang.String) keys.nextElement();
                _call.setProperty(key, super.cachedProperties.get(key));
            }
            // All the type mapping information is registered
            // when the first call is made.
            // The type mapping information is actually registered in
            // the TypeMappingRegistry of the service, which
            // is the reason why registration is only needed for the first call.
            //TODO figure out if this can be done during deployment!
//            synchronized (this) {
//                if (firstCall()) {
//                    // must set encoding style before registering serializers
//                    //TODO these constants probably need to be parameters of GSE.
//                    _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
////                    _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);
//                    //override unsigned long mapping
//                    _call.registerTypeMapping(BigInteger.class,
//                            Constants.XSD_UNSIGNEDLONG,
//                            new SimpleSerializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG),
//                            new SimpleDeserializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG));
//                    _call.registerTypeMapping(URI.class,
//                            Constants.XSD_ANYURI,
//                            new SimpleSerializerFactory(URI.class, Constants.XSD_ANYURI),
//                            new SimpleDeserializerFactory(URI.class, Constants.XSD_ANYURI));
//                    for (Iterator iterator = typeInfo.iterator(); iterator.hasNext();) {
//                        TypeInfo info = (TypeInfo) iterator.next();
//                        _call.registerTypeMapping(info.getClazz(), info.getqName(), info.getSerFactoryClass(), info.getDeserFactoryClass(), false);
//                    }
//                }
//            }
            return _call;
        } catch (java.lang.Throwable t) {
            throw new org.apache.axis.AxisFault("Failure trying to get the Call object", t);
        }
    }
 
Example 28
Source Project: tomee   Source File: GenericServiceEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
void setUpCall(Call call) throws AxisFault {
    setRequestHeaders(call);
    setAttachments(call);
}
 
Example 29
Source Project: googleads-java-lib   Source File: HttpHandlerTest.java    License: Apache License 2.0 4 votes vote down vote up
/** Tests that the timeout set on the message context is passed to the underlying request. */
@Test
public void testInvokeSetsTimeout() {
  MessageContext messageContext = new MessageContext(axisEngine);
  messageContext.setRequestMessage(requestMessage);
  messageContext.setProperty(MessageContext.TRANS_URL, "https://www.example.com");

  // Do not care about XML parsing for this test, so set the response's status code to 302
  // to trigger an AxisFault.
  MockLowLevelHttpResponse lowLevelHttpResponse = new MockLowLevelHttpResponse();
  lowLevelHttpResponse.setContent("Intentional failure");
  lowLevelHttpResponse.setStatusCode(302);

  /*
   * Set timeout on the message context, then create a custom mock transport that will capture
   * invocations of LowLevelHttpRequest.setTimeout(int, int) and record the arguments passed.
   */
  int timeout = 1234567;
  messageContext.setTimeout(timeout);
  final int[] actualTimeouts = new int[] {Integer.MIN_VALUE, Integer.MIN_VALUE};
  MockLowLevelHttpRequest lowLevelHttpRequest =
      new MockLowLevelHttpRequest() {
        @Override
        public void setTimeout(int connectTimeout, int readTimeout) throws IOException {
          actualTimeouts[0] = connectTimeout;
          actualTimeouts[1] = readTimeout;
          super.setTimeout(connectTimeout, readTimeout);
        }
      };
  lowLevelHttpRequest.setResponse(lowLevelHttpResponse);
  MockHttpTransport mockTransport =
      new MockHttpTransport.Builder().setLowLevelHttpRequest(lowLevelHttpRequest).build();
  httpHandler = new HttpHandler(mockTransport, streamListener);

  try {
    httpHandler.invoke(messageContext);
    fail("Expected an AxisFault");
  } catch (AxisFault e) {
    assertThat(e.getFaultString(), Matchers.containsString("302"));
  }
  assertArrayEquals(
      "Timeouts not set to expected values", new int[] {timeout, timeout}, actualTimeouts);
}
 
Example 30
Source Project: openbd-core   Source File: cfcProvider.java    License: GNU General Public License v3.0 3 votes vote down vote up
/**
 * Fill in a service description with the correct impl class and typemapping
 * set. This uses methods that can be overridden by other providers (like the
 * EJBProvider) to get the class from the right place.
 * 
 * @param service
 *          SOAPService wrapper
 * @param msgContext
 *          MessageContext for this SOAPService
 * @throws AxisFault
 */
public void initServiceDesc(SOAPService service, MessageContext msgContext) throws AxisFault {
	// Normal initialization
	super.initServiceDesc(service, msgContext);

	// Remove the IComplexObject operations
	removeIComplexObjectOps(service.getServiceDescription());
}